1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
31 using ::basegfx2d::getRandomOrdinal
;
33 class b2dpolypolygon
: public CppUnit::TestFixture
36 // insert your test code here.
37 void testTrapezoidHelper()
40 // provoke the PointBlockAllocator to exercise the freeIfLast path
41 for (int i
= 0; i
< 16 * 10; i
++)
43 B2DPoint
aPoint(getRandomOrdinal(1000), getRandomOrdinal(1000));
44 aPolygon
.append(aPoint
);
46 // scatter some duplicate points in to stress things more.
47 for (int i
= 0; i
< 16 * 10; i
++)
49 aPolygon
.insert(getRandomOrdinal(aPolygon
.count() - 1),
50 aPolygon
.getB2DPoint(getRandomOrdinal(aPolygon
.count() - 1)));
52 B2DPolygon aPolygonOffset
;
53 // duplicate the polygon and offset it slightly.
54 for (size_t i
= 0; i
< aPolygon
.count(); i
++)
56 B2DPoint
aPoint(aPolygon
.getB2DPoint(i
));
57 aPoint
+= B2DPoint(0.5 - getRandomOrdinal(1), 0.5 - getRandomOrdinal(1));
58 aPolygonOffset
.append(aPoint
);
60 B2DPolyPolygon aPolyPolygon
;
61 aPolyPolygon
.append(aPolygon
);
62 aPolyPolygon
.append(aPolygonOffset
);
63 B2DTrapezoidVector aVector
;
64 basegfx::utils::trapezoidSubdivide(aVector
, aPolyPolygon
);
65 CPPUNIT_ASSERT_MESSAGE("more than zero sub-divided trapezoids", !aVector
.empty());
68 // Change the following lines only, if you add, remove or rename
69 // member functions of the current class,
70 // because these macros are need by auto register mechanism.
72 CPPUNIT_TEST_SUITE(b2dpolypolygon
);
73 CPPUNIT_TEST(testTrapezoidHelper
);
74 CPPUNIT_TEST_SUITE_END();
75 }; // class b2dpolypolygon
77 } // namespace basegfx
79 CPPUNIT_TEST_SUITE_REGISTRATION(basegfx::b2dpolypolygon
);
81 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */