summaryrefslogtreecommitdiff
path: root/basebmp/test/polytest.cxx
diff options
context:
space:
mode:
authorThorsten Behrens <tbehrens@suse.com>2011-11-15 12:24:52 +0100
committerThorsten Behrens <tbehrens@suse.com>2011-11-15 12:38:50 +0100
commitb53d2bc9dd92079c030346af57e9b1a0078a05e7 (patch)
tree492f6e07cf7dc7251a83e1afa9a1b54c4137e3d6 /basebmp/test/polytest.cxx
parent2264f482e57e989e649934d3980368f2b135d496 (diff)
Fix clipped line renderer.
Fix for a nasty corner case where supposedly clipped pixel were still rasterized (see polytest.cxx:implTestPolyDrawClip for what failed previously). Added much more unit tests while at it, clippedlinerenderer.hxx should now have 100% coverage.
Diffstat (limited to 'basebmp/test/polytest.cxx')
-rw-r--r--basebmp/test/polytest.cxx105
1 files changed, 100 insertions, 5 deletions
diff --git a/basebmp/test/polytest.cxx b/basebmp/test/polytest.cxx
index 8cc51d4921ee..63485000b7f9 100644
--- a/basebmp/test/polytest.cxx
+++ b/basebmp/test/polytest.cxx
@@ -65,7 +65,6 @@ private:
const Color aBgCol(0);
rDevice->clear(aBgCol);
basegfx::B2DPolyPolygon aPoly;
- ::rtl::OUString aSvg;
basegfx::tools::importFromSvgD(
aPoly,
@@ -100,7 +99,6 @@ private:
const Color aBgCol(0);
rDevice->clear(aBgCol);
basegfx::B2DPolyPolygon aPoly;
- ::rtl::OUString aSvg;
basegfx::tools::importFromSvgD(
aPoly,
@@ -150,7 +148,6 @@ private:
const Color aBgCol(0);
rDevice->clear(aBgCol);
basegfx::B2DPolyPolygon aPoly;
- ::rtl::OUString aSvg;
basegfx::tools::importFromSvgD( aPoly,
::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
@@ -170,7 +167,6 @@ private:
const Color aBgCol(0);
rDevice->clear(aBgCol);
basegfx::B2DPolyPolygon aPoly;
- ::rtl::OUString aSvg;
basegfx::tools::importFromSvgD( aPoly,
::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
@@ -204,13 +200,98 @@ private:
countPixel( rDevice, aCol ) == 7);
}
+ void implTestLineDrawClip(const BitmapDeviceSharedPtr& rDevice)
+ {
+ const Color aCol(0xFFFFFFFF);
+ const Color aBgCol(0);
+ rDevice->clear(aBgCol);
+
+ // create rectangular subset, such that we can 'see' extra
+ // pixel outside
+ BitmapDeviceSharedPtr pClippedDevice=(
+ subsetBitmapDevice( rDevice,
+ basegfx::B2IBox(3,3,5,9) ));
+
+ // trigger "alternate bresenham" case in
+ // clippedlinerenderer.hxx, first point not clipped
+ const basegfx::B2IPoint aPt1(3,3);
+ const basegfx::B2IPoint aPt2(4,2);
+ pClippedDevice->drawLine( aPt1, aPt2, aCol, DrawMode_PAINT );
+
+ CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 1",
+ countPixel( rDevice, aCol ) == 1);
+
+ // trigger "alternate bresenham" case in
+ // clippedlinerenderer.hxx, both start and endpoint clipped
+ const basegfx::B2IPoint aPt3(0,4);
+ pClippedDevice->drawLine( aPt3, aPt2, aCol, DrawMode_XOR );
+
+ CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 0",
+ countPixel( rDevice, aCol ) == 0);
+
+ // trigger "standard bresenham" case in
+ // clippedlinerenderer.hxx, first point not clipped
+ const basegfx::B2IPoint aPt4(6,2);
+ pClippedDevice->drawLine( aPt1, aPt4, aCol, DrawMode_PAINT );
+
+ CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 2",
+ countPixel( rDevice, aCol ) == 2);
+
+ // trigger "clipCode1 & aMinFlag/bMinFlag" cases in
+ // clippedlinerenderer.hxx (note1: needs forcing end point to
+ // be clipped as well, otherwise optimisation kicks in. note2:
+ // needs forcing end point to clip on two edges, not only on
+ // one, otherwise swap kicks in)
+ const basegfx::B2IPoint aPt5(1,1);
+ const basegfx::B2IPoint aPt6(6,10);
+ pClippedDevice->drawLine( aPt5, aPt6, aCol, DrawMode_XOR );
+
+ CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 6",
+ countPixel( rDevice, aCol ) == 6);
+
+ // trigger "clipCode1 & (aMinFlag|aMaxFlag)" case in
+ // clippedlinerenderer.hxx that was not taken for the test
+ // above
+ pClippedDevice->drawLine( aPt3, aPt6, aCol, DrawMode_XOR );
+
+ CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 8",
+ countPixel( rDevice, aCol ) == 8);
+
+ }
+
+ void implTestPolyDrawClip(const BitmapDeviceSharedPtr& rDevice)
+ {
+ const Color aCol(0xFFFFFFFF);
+ const Color aBgCol(0);
+ rDevice->clear(aBgCol);
+ basegfx::B2DPolyPolygon aPoly;
+
+ // test all corner-touching lines of our clip rect. note that
+ // *all* of the four two-pixel lines in that polygon do *not*
+ // generate a single pixel, due to the rasterization effect.
+ basegfx::tools::importFromSvgD( aPoly,
+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
+ "M2 3 l1 -1 M4 2 l1 1 M2 8 l1 1 M5 8 l-1 1 M2 5 h4 M3 0 v10" )) );
+ BitmapDeviceSharedPtr pClippedDevice=(
+ subsetBitmapDevice( rDevice,
+ basegfx::B2IBox(3,3,5,9) ));
+
+ for( unsigned int i=0; i<aPoly.count(); ++i )
+ pClippedDevice->drawPolygon(
+ aPoly.getB2DPolygon(i),
+ aCol,
+ DrawMode_PAINT );
+
+ CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 7",
+ countPixel( rDevice, aCol ) == 7);
+ }
+
void implTestPolyPolyCrissCross(const BitmapDeviceSharedPtr& rDevice)
{
const Color aCol(0xFFFFFFFF);
const Color aBgCol(0);
rDevice->clear(aBgCol);
basegfx::B2DPolyPolygon aPoly;
- ::rtl::OUString aSvg;
basegfx::tools::importFromSvgD( aPoly,
::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
@@ -264,6 +345,18 @@ public:
implTestPolyPolyClip(mpDevice32bpp);
}
+ void testLineDrawClip()
+ {
+ implTestLineDrawClip(mpDevice1bpp);
+ implTestLineDrawClip(mpDevice32bpp);
+ }
+
+ void testPolyDrawClip()
+ {
+ implTestPolyDrawClip(mpDevice1bpp);
+ implTestPolyDrawClip(mpDevice32bpp);
+ }
+
void testPolyPolyCrissCross()
{
implTestPolyPolyCrissCross(mpDevice1bpp);
@@ -279,6 +372,8 @@ public:
CPPUNIT_TEST(testHairline);
CPPUNIT_TEST(testPolyPoly);
CPPUNIT_TEST(testPolyPolyClip);
+ CPPUNIT_TEST(testLineDrawClip);
+ CPPUNIT_TEST(testPolyDrawClip);
CPPUNIT_TEST(testPolyPolyCrissCross);
CPPUNIT_TEST_SUITE_END();
};