summaryrefslogtreecommitdiff
path: root/basegfx
diff options
context:
space:
mode:
authorThorsten Behrens <tbehrens@suse.com>2011-11-03 14:58:40 +0100
committerThorsten Behrens <tbehrens@suse.com>2011-11-03 15:02:00 +0100
commitf7975d2335334899e5d14e35e7640d3afdf220f6 (patch)
tree2c97dc4a14afce606d8f68ee28777c917371ab17 /basegfx
parent3e8dee1a48bd80c52b5adda6bd9358c2136ea764 (diff)
Fix one more subtlety around B2IBox / B2IRange changes.
The Cohen/Sutherland clip flag routine was not aware of B2IBox, thusly yielding incorrect line clipping for BitmapDevice software rendering. Cleaned that up, added some more unit tests around the problem, and removed the now-extraneous maLineClip member from the bitmap device.
Diffstat (limited to 'basegfx')
-rw-r--r--basegfx/inc/basegfx/tools/rectcliptools.hxx14
-rw-r--r--basegfx/test/basegfx2d.cxx126
2 files changed, 135 insertions, 5 deletions
diff --git a/basegfx/inc/basegfx/tools/rectcliptools.hxx b/basegfx/inc/basegfx/tools/rectcliptools.hxx
index 7e2ff80876ca..c9b36eb3e46d 100644
--- a/basegfx/inc/basegfx/tools/rectcliptools.hxx
+++ b/basegfx/inc/basegfx/tools/rectcliptools.hxx
@@ -30,6 +30,7 @@
#define _BGFX_TOOLS_RECTCLIPTOOLS_HXX
#include <sal/types.h>
+#include <basegfx/range/b2ibox.hxx>
//////////////////////////////////////////////////////////////////////////////
@@ -65,6 +66,19 @@ namespace basegfx
return clip;
}
+ /// Cohen-Sutherland mask calculation - overload for boxes.
+ template< class Point > inline
+ sal_uInt32 getCohenSutherlandClipFlags( const Point& rP,
+ const B2IBox& rB )
+ {
+ // maxY | minY | maxX | minX
+ sal_uInt32 clip = (rP.getX() < rB.getMinX()) << 0;
+ clip |= (rP.getX() >= rB.getMaxX()) << 1;
+ clip |= (rP.getY() < rB.getMinY()) << 2;
+ clip |= (rP.getY() >= rB.getMaxY()) << 3;
+ return clip;
+ }
+
/** Determine number of clip planes hit by given clip mask
This method returns the number of one bits in the four
diff --git a/basegfx/test/basegfx2d.cxx b/basegfx/test/basegfx2d.cxx
index 18a046ac93c0..9aceb8323f94 100644
--- a/basegfx/test/basegfx2d.cxx
+++ b/basegfx/test/basegfx2d.cxx
@@ -56,6 +56,7 @@
#include <basegfx/color/bcolortools.hxx>
#include <basegfx/tools/debugplotter.hxx>
+#include <basegfx/tools/rectcliptools.hxx>
#include <iostream>
#include <fstream>
@@ -1263,15 +1264,24 @@ public:
// check overlap
Type aRange2(0,1);
- CPPUNIT_ASSERT_MESSAGE("box overlapping *includes* upper bound", aRange.overlaps(aRange2));
- CPPUNIT_ASSERT_MESSAGE("box overlapping *includes* upper bound, but only barely", !aRange.overlapsMore(aRange2));
+ CPPUNIT_ASSERT_MESSAGE("range overlapping *includes* upper bound", aRange.overlaps(aRange2));
+ CPPUNIT_ASSERT_MESSAGE("range overlapping *includes* upper bound, but only barely", !aRange.overlapsMore(aRange2));
Type aRange3(0,2);
- CPPUNIT_ASSERT_MESSAGE("box overlapping is fully overlapping now", aRange.overlapsMore(aRange3));
+ CPPUNIT_ASSERT_MESSAGE("range overlapping is fully overlapping now", aRange.overlapsMore(aRange3));
+
+ // check intersect
+ Type aRange4(3,4);
+ aRange.intersect(aRange4);
+ CPPUNIT_ASSERT_MESSAGE("range intersection is yielding empty range!", !aRange.isEmpty());
+
+ Type aRange5(5,6);
+ aRange.intersect(aRange5);
+ CPPUNIT_ASSERT_MESSAGE("range intersection is yielding nonempty range!", aRange.isEmpty());
// just so that this compiles -
- Type aRange4( aRange );
- (void)aRange4;
+ Type aRange6( aRange );
+ (void)aRange6;
}
void check()
@@ -1333,6 +1343,19 @@ public:
B1IBox aBox3(0,2);
CPPUNIT_ASSERT_MESSAGE("box overlapping then includes upper bound-1", aBox.overlaps(aBox3));
+
+ // check intersect
+ B1IBox aBox4(4,5);
+ aBox.intersect(aBox4);
+ CPPUNIT_ASSERT_MESSAGE("box intersection is yielding nonempty box!", aBox.isEmpty());
+
+ B1IBox aBox5(2,5);
+ aBox5.intersect(aBox4);
+ CPPUNIT_ASSERT_MESSAGE("box intersection is yielding empty box!", !aBox5.isEmpty());
+
+ // just so that this compiles -
+ B1IBox aBox6( aBox );
+ (void)aBox6;
}
// Change the following lines only, if you add, remove or rename
@@ -1345,6 +1368,97 @@ public:
}; // class b1ibox
+class b2Xrange : public CppUnit::TestFixture
+{
+public:
+ // initialise your test code values here.
+ void setUp()
+ {
+ }
+
+ void tearDown()
+ {
+ }
+
+ template<class Type> void implCheck()
+ {
+ // cohen sutherland clipping
+ Type aRange(0,0,10,10);
+
+ CPPUNIT_ASSERT_MESSAGE("(0,0) is outside range!",
+ tools::getCohenSutherlandClipFlags(B2IPoint(0,0),aRange) == 0);
+ CPPUNIT_ASSERT_MESSAGE("(-1,-1) is inside range!",
+ tools::getCohenSutherlandClipFlags(B2IPoint(-1,-1),aRange) ==
+ (tools::RectClipFlags::LEFT|tools::RectClipFlags::TOP));
+ CPPUNIT_ASSERT_MESSAGE("(10,10) is outside range!",
+ tools::getCohenSutherlandClipFlags(B2IPoint(10,10),aRange) == 0);
+ CPPUNIT_ASSERT_MESSAGE("(11,11) is inside range!",
+ tools::getCohenSutherlandClipFlags(B2IPoint(11,11),aRange) ==
+ (tools::RectClipFlags::RIGHT|tools::RectClipFlags::BOTTOM));
+
+ // just so that this compiles -
+ Type aRange1( aRange );
+ (void)aRange1;
+ }
+
+ void check()
+ {
+ implCheck<B2DRange>();
+ implCheck<B2IRange>();
+ }
+
+ // 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.
+
+ SAL_CPPUNIT_TEST_SUITE(b2Xrange);
+ CPPUNIT_TEST(check);
+ SAL_CPPUNIT_TEST_SUITE_END();
+}; // class b2Xrange
+
+
+class b2ibox : public CppUnit::TestFixture
+{
+public:
+ // initialise your test code values here.
+ void setUp()
+ {
+ }
+
+ void tearDown()
+ {
+ }
+
+ void TestBox()
+ {
+ // cohen sutherland clipping
+ B2IBox aBox(0,0,10,10);
+
+ CPPUNIT_ASSERT_MESSAGE("(0,0) is outside range!",
+ tools::getCohenSutherlandClipFlags(B2IPoint(0,0),aBox) == 0);
+ CPPUNIT_ASSERT_MESSAGE("(-1,-1) is inside range!",
+ tools::getCohenSutherlandClipFlags(B2IPoint(-1,-1),aBox) ==
+ (tools::RectClipFlags::LEFT|tools::RectClipFlags::TOP));
+ CPPUNIT_ASSERT_MESSAGE("(9,9) is outside range!",
+ tools::getCohenSutherlandClipFlags(B2IPoint(9,9),aBox) == 0);
+ CPPUNIT_ASSERT_MESSAGE("(10,10) is inside range!",
+ tools::getCohenSutherlandClipFlags(B2IPoint(10,10),aBox) ==
+ (tools::RectClipFlags::RIGHT|tools::RectClipFlags::BOTTOM));
+
+ // just so that this compiles -
+ B2IBox aBox1( aBox );
+ (void)aBox1;
+ }
+
+ // 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.
+ SAL_CPPUNIT_TEST_SUITE(b2ibox);
+ CPPUNIT_TEST(TestBox);
+ SAL_CPPUNIT_TEST_SUITE_END();
+}; // class b2ibox
+
+
class b2dtuple : public CppUnit::TestFixture
{
public:
@@ -1588,6 +1702,8 @@ CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b2dpolypolygon);
CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b2dquadraticbezier);
CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b1Xrange);
CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b1ibox);
+CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b2Xrange);
+CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b2ibox);
CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b2dtuple);
CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b2dvector);
CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::bcolor);