Kaydet (Commit) 82b56544 authored tarafından Michael Meeks's avatar Michael Meeks

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
üst b178afc8
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include <basegfx/polygon/b2dpolypolygontools.hxx> #include <basegfx/polygon/b2dpolypolygontools.hxx>
#include <basegfx/polygon/b2dpolygonclipper.hxx> #include <basegfx/polygon/b2dpolygonclipper.hxx>
#include <basegfx/polygon/b2dpolypolygon.hxx> #include <basegfx/polygon/b2dpolypolygon.hxx>
#include <basegfx/polygon/b2dtrapezoid.hxx>
#include <basegfx/range/b2irange.hxx> #include <basegfx/range/b2irange.hxx>
#include <basegfx/range/b2ibox.hxx> #include <basegfx/range/b2ibox.hxx>
#include <basegfx/range/b1drange.hxx> #include <basegfx/range/b1drange.hxx>
...@@ -51,6 +52,7 @@ using namespace ::basegfx; ...@@ -51,6 +52,7 @@ using namespace ::basegfx;
namespace basegfx2d namespace basegfx2d
{ {
extern double getRandomOrdinal( const ::std::size_t n );
class b2dsvgdimpex : public CppUnit::TestFixture class b2dsvgdimpex : public CppUnit::TestFixture
{ {
...@@ -858,13 +860,39 @@ public: ...@@ -858,13 +860,39 @@ public:
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
}; // class b2dpolygontools }; // class b2dpolygontools
class b2dpolypolygon : public CppUnit::TestFixture class b2dpolypolygon : public CppUnit::TestFixture
{ {
public: public:
// insert your test code here. // 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 // Change the following lines only, if you add, remove or rename
...@@ -872,7 +900,7 @@ public: ...@@ -872,7 +900,7 @@ public:
// because these macros are need by auto register mechanism. // because these macros are need by auto register mechanism.
CPPUNIT_TEST_SUITE(b2dpolypolygon); CPPUNIT_TEST_SUITE(b2dpolypolygon);
CPPUNIT_TEST(EmptyMethod); CPPUNIT_TEST(testTrapezoidHelper);
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
}; // class b2dpolypolygon }; // class b2dpolypolygon
......
...@@ -38,11 +38,12 @@ ...@@ -38,11 +38,12 @@
using namespace ::basegfx; using namespace ::basegfx;
extern double getRandomOrdinal( const ::std::size_t n );
namespace basegfx2d namespace basegfx2d
{ {
/// Gets a random ordinal [0,n) /// 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 // use this one when displaying polygons in OOo, which still sucks
// great rocks when trying to import non-integer svg:d attributes // great rocks when trying to import non-integer svg:d attributes
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment