summaryrefslogtreecommitdiff
path: root/basegfx
diff options
context:
space:
mode:
Diffstat (limited to 'basegfx')
-rw-r--r--basegfx/source/polygon/b2dpolypolygontools.cxx18
-rw-r--r--basegfx/test/B2DPolygonTest.cxx20
2 files changed, 38 insertions, 0 deletions
diff --git a/basegfx/source/polygon/b2dpolypolygontools.cxx b/basegfx/source/polygon/b2dpolypolygontools.cxx
index 062e37da9dae..d537531a4600 100644
--- a/basegfx/source/polygon/b2dpolypolygontools.cxx
+++ b/basegfx/source/polygon/b2dpolypolygontools.cxx
@@ -416,6 +416,24 @@ namespace basegfx
return aRetval;
}
+ bool containsOnlyHorizontalOrVerticalLines(const basegfx::B2DPolygon& rPolygon)
+ {
+ if (rPolygon.count() <= 1)
+ return false;
+
+ for (size_t i = 1; i < rPolygon.count(); ++i)
+ {
+ const basegfx::B2DPoint& rPrevPoint = rPolygon.getB2DPoint(i - 1);
+ const basegfx::B2DPoint& rPoint = rPolygon.getB2DPoint(i);
+ if (rPrevPoint.getX() == rPoint.getX() || rPrevPoint.getY() == rPoint.getY())
+ continue;
+
+ return false;
+ }
+
+ return true;
+ }
+
B2DPolyPolygon createSevenSegmentPolyPolygon(sal_Char nNumber, bool bLitSegments)
{
// config here
diff --git a/basegfx/test/B2DPolygonTest.cxx b/basegfx/test/B2DPolygonTest.cxx
index 9f0d1ef98dcc..316a916f931f 100644
--- a/basegfx/test/B2DPolygonTest.cxx
+++ b/basegfx/test/B2DPolygonTest.cxx
@@ -22,6 +22,7 @@
#include <cppunit/extensions/HelperMacros.h>
#include <basegfx/polygon/b2dpolygon.hxx>
+#include <basegfx/polygon/b2dpolygontools.hxx>
#include <basegfx/point/b2dpoint.hxx>
namespace basegfx
@@ -77,12 +78,31 @@ public:
CPPUNIT_ASSERT_EQUAL_MESSAGE("#2 second polygon point wrong", B2DPoint(3, 3),
aPoly.getB2DPoint(1));
}
+
+ void testContainsOnlyHorizontalOrVerticalLines()
+ {
+ // First line is horziontal, second is vertical.
+ B2DPolygon aPoly;
+ aPoly.append(B2DPoint(0, 1));
+ aPoly.append(B2DPoint(1, 1));
+ aPoly.append(B2DPoint(1, 0));
+ CPPUNIT_ASSERT(utils::containsOnlyHorizontalOrVerticalLines(aPoly));
+
+ // First line is diagonal, second is vertical.
+ aPoly.clear();
+ aPoly.append(B2DPoint(0, 0));
+ aPoly.append(B2DPoint(1, 1));
+ aPoly.append(B2DPoint(1, 0));
+ CPPUNIT_ASSERT(!utils::containsOnlyHorizontalOrVerticalLines(aPoly));
+ }
+
// Change the following lines only, if you add, remove or rename
// member functions of the current class,
// because these macros are need by auto register mechanism.
CPPUNIT_TEST_SUITE(b2dpolygon);
CPPUNIT_TEST(testBasics);
+ CPPUNIT_TEST(testContainsOnlyHorizontalOrVerticalLines);
CPPUNIT_TEST_SUITE_END();
}; // class b2dpolygon