diff options
author | Michael Meeks <michael.meeks@collabora.com> | 2014-01-01 10:29:40 +0000 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2014-01-01 10:31:43 +0000 |
commit | 82b56544a7a53528970632d086c3cfd8ef879335 (patch) | |
tree | d2639b8833d411e211af6ffcb100b5fb0f4a1a9e /basegfx/test | |
parent | b178afc88ba97f04036e6eef9cf1ee0da987b258 (diff) |
basegfx: accelerate Trapezoid subdivision by avoiding allocations.
Allocate on the stack where possible, then more conservatively on
the heap. Unit test Trapezoid subdivision for good measure.
Change-Id: I83e63fd55fddcad149bb5279865670ebb18e0ab1
Diffstat (limited to 'basegfx/test')
-rw-r--r-- | basegfx/test/basegfx2d.cxx | 34 | ||||
-rw-r--r-- | basegfx/test/boxclipper.cxx | 3 |
2 files changed, 33 insertions, 4 deletions
diff --git a/basegfx/test/basegfx2d.cxx b/basegfx/test/basegfx2d.cxx index 89042cbcdf53..afa065c0ac57 100644 --- a/basegfx/test/basegfx2d.cxx +++ b/basegfx/test/basegfx2d.cxx @@ -30,6 +30,7 @@ #include <basegfx/polygon/b2dpolypolygontools.hxx> #include <basegfx/polygon/b2dpolygonclipper.hxx> #include <basegfx/polygon/b2dpolypolygon.hxx> +#include <basegfx/polygon/b2dtrapezoid.hxx> #include <basegfx/range/b2irange.hxx> #include <basegfx/range/b2ibox.hxx> #include <basegfx/range/b1drange.hxx> @@ -51,6 +52,7 @@ using namespace ::basegfx; namespace basegfx2d { + extern double getRandomOrdinal( const ::std::size_t n ); class b2dsvgdimpex : public CppUnit::TestFixture { @@ -858,13 +860,39 @@ public: CPPUNIT_TEST_SUITE_END(); }; // class b2dpolygontools - class b2dpolypolygon : public CppUnit::TestFixture { public: // insert your test code here. - void EmptyMethod() + void testTrapezoidHelper() { + B2DPolygon aPolygon; + // provoke the PointBlockAllocator to exercise the freeIfLast path + for(int i = 0; i < 16 * 10; i++) + { + B2DPoint aPoint(getRandomOrdinal(1000), getRandomOrdinal(1000)); + aPolygon.append(aPoint); + } + // scatter some duplicate points in to stress things more. + for(int i = 0; i < 16 * 10; i++) + { + aPolygon.insert(getRandomOrdinal(aPolygon.count() - 1), + aPolygon.getB2DPoint(getRandomOrdinal(aPolygon.count() - 1))); + } + B2DPolygon aPolygonOffset; + // duplicate the polygon and offset it slightly. + for(size_t i = 0; i < aPolygon.count(); i++) + { + B2DPoint aPoint(aPolygon.getB2DPoint(i)); + aPoint += B2DPoint(0.5-getRandomOrdinal(1),0.5-getRandomOrdinal(1)); + } + B2DPolyPolygon aPolyPolygon; + aPolyPolygon.append(aPolygon); + aPolyPolygon.append(aPolygonOffset); + B2DTrapezoidVector aVector; + basegfx::tools::trapezoidSubdivide(aVector, aPolyPolygon); + CPPUNIT_ASSERT_MESSAGE("more than zero sub-divided trapezoids", + aVector.size() > 0); } // Change the following lines only, if you add, remove or rename @@ -872,7 +900,7 @@ public: // because these macros are need by auto register mechanism. CPPUNIT_TEST_SUITE(b2dpolypolygon); - CPPUNIT_TEST(EmptyMethod); + CPPUNIT_TEST(testTrapezoidHelper); CPPUNIT_TEST_SUITE_END(); }; // class b2dpolypolygon diff --git a/basegfx/test/boxclipper.cxx b/basegfx/test/boxclipper.cxx index ddc0a803685e..9b8bf10254f4 100644 --- a/basegfx/test/boxclipper.cxx +++ b/basegfx/test/boxclipper.cxx @@ -38,11 +38,12 @@ using namespace ::basegfx; +extern double getRandomOrdinal( const ::std::size_t n ); namespace basegfx2d { /// Gets a random ordinal [0,n) -inline double getRandomOrdinal( const ::std::size_t n ) +double getRandomOrdinal( const ::std::size_t n ) { // use this one when displaying polygons in OOo, which still sucks // great rocks when trying to import non-integer svg:d attributes |