android: Update app-specific/MIME type icons
[LibreOffice.git] / basegfx / test / B2DPolyPolygonTest.cxx
blobf51d396b8578e5d4e36709af3643aadb7724a758
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <cppunit/TestAssert.h>
21 #include <cppunit/TestFixture.h>
22 #include <cppunit/extensions/HelperMacros.h>
24 #include <basegfx/polygon/b2dpolypolygon.hxx>
25 #include <basegfx/polygon/b2dtrapezoid.hxx>
27 #include "boxclipper.hxx"
28 #include <random>
30 namespace basegfx
32 class b2dpolypolygon : public CppUnit::TestFixture
34 public:
35 // insert your test code here.
36 void testTrapezoidHelper()
38 B2DPolygon aPolygon;
39 // provoke the PointBlockAllocator to exercise the freeIfLast path
40 for (int i = 0; i < 16 * 10; i++)
42 B2DPoint aPoint(getRandomOrdinal(1000), getRandomOrdinal(1000));
43 aPolygon.append(aPoint);
45 // scatter some duplicate points in to stress things more.
46 for (int i = 0; i < 16 * 10; i++)
48 aPolygon.insert(getRandomOrdinal(aPolygon.count() - 1),
49 aPolygon.getB2DPoint(getRandomOrdinal(aPolygon.count() - 1)));
51 B2DPolygon aPolygonOffset;
52 // duplicate the polygon and offset it slightly.
53 for (size_t i = 0; i < aPolygon.count(); i++)
55 B2DPoint aPoint(aPolygon.getB2DPoint(i));
56 aPoint += B2DPoint(0.5 - getRandomOrdinal(1), 0.5 - getRandomOrdinal(1));
57 aPolygonOffset.append(aPoint);
59 B2DPolyPolygon aPolyPolygon;
60 aPolyPolygon.append(aPolygon);
61 aPolyPolygon.append(aPolygonOffset);
62 B2DTrapezoidVector aVector;
63 basegfx::utils::trapezoidSubdivide(aVector, aPolyPolygon);
64 CPPUNIT_ASSERT_MESSAGE("more than zero sub-divided trapezoids", !aVector.empty());
67 std::mt19937 rng; // Standard mersenne_twister_engine
69 /// Gets a random ordinal [0,n)
70 ::std::size_t getRandomOrdinal(const ::std::size_t n)
72 std::uniform_int_distribution<size_t> dist(0, n - 1);
73 return dist(rng);
76 // Change the following lines only, if you add, remove or rename
77 // member functions of the current class,
78 // because these macros are need by auto register mechanism.
80 CPPUNIT_TEST_SUITE(b2dpolypolygon);
81 CPPUNIT_TEST(testTrapezoidHelper);
82 CPPUNIT_TEST_SUITE_END();
83 }; // class b2dpolypolygon
85 } // namespace basegfx
87 CPPUNIT_TEST_SUITE_REGISTRATION(basegfx::b2dpolypolygon);
89 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */