summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThorsten Behrens <tbehrens@suse.com>2011-11-02 16:32:00 +0100
committerThorsten Behrens <tbehrens@suse.com>2011-11-02 23:58:28 +0100
commit3c8f2388769a439a871c90550832a6aeb03227dc (patch)
treee2f8bb6b2d062ef19c7462e86a92bd1c0e5bc4c9
parent3c1b4b6ef70b049bc5242149e727dd5d94111d86 (diff)
Fix BXYBox behaviour and unit test
Made the distinction more clear, added appropriate tests to nail behaviour.
-rw-r--r--basegfx/inc/basegfx/range/b1irange.hxx5
-rw-r--r--basegfx/inc/basegfx/range/basicbox.hxx11
-rw-r--r--basegfx/inc/basegfx/range/basicrange.hxx13
-rw-r--r--basegfx/test/basegfx2d.cxx110
4 files changed, 113 insertions, 26 deletions
diff --git a/basegfx/inc/basegfx/range/b1irange.hxx b/basegfx/inc/basegfx/range/b1irange.hxx
index 90e5ba23d01c..81e19ef29904 100644
--- a/basegfx/inc/basegfx/range/b1irange.hxx
+++ b/basegfx/inc/basegfx/range/b1irange.hxx
@@ -121,6 +121,11 @@ namespace basegfx
return maRange.overlaps(rRange.maRange);
}
+ bool overlapsMore(const B1IRange& rRange) const
+ {
+ return maRange.overlapsMore(rRange.maRange);
+ }
+
void expand(sal_Int32 nValue)
{
maRange.expand(nValue);
diff --git a/basegfx/inc/basegfx/range/basicbox.hxx b/basegfx/inc/basegfx/range/basicbox.hxx
index 6c7606748420..a6eae3a628f2 100644
--- a/basegfx/inc/basegfx/range/basicbox.hxx
+++ b/basegfx/inc/basegfx/range/basicbox.hxx
@@ -35,12 +35,11 @@
namespace basegfx
{
- /** Specialization of BasicRange, handling the inside predicates
+ /** Explicitely different from BasicRange, handling the inside predicates
differently.
- This template considers the rightmost and bottommost border as
- <em>outside</em> of the range, in contrast to BasicRange,
- which considers them inside.
+ This is modelled after how polygon fill algorithms set pixel -
+ typically excluding rightmost and bottommost ones.
*/
class BASEGFX_DLLPUBLIC BasicBox : public BasicRange< sal_Int32, Int32Traits >
{
@@ -56,9 +55,9 @@ namespace basegfx
{
}
- BasicBox(const BasicBox& rBox) :
- Base( rBox )
+ bool isEmpty() const
{
+ return mnMinimum >= mnMaximum;
}
double getCenter() const
diff --git a/basegfx/inc/basegfx/range/basicrange.hxx b/basegfx/inc/basegfx/range/basicrange.hxx
index 8711f95b754c..daf552f56daf 100644
--- a/basegfx/inc/basegfx/range/basicrange.hxx
+++ b/basegfx/inc/basegfx/range/basicrange.hxx
@@ -58,12 +58,6 @@ namespace basegfx
{
}
- BasicRange(const BasicRange& rRange) :
- mnMinimum(rRange.mnMinimum),
- mnMaximum(rRange.mnMaximum)
- {
- }
-
void reset()
{
mnMinimum = Traits::maxVal();
@@ -158,13 +152,6 @@ namespace basegfx
return (mnMinimum != rRange.mnMinimum || mnMaximum != rRange.mnMaximum);
}
- BasicRange& operator=(const BasicRange& rRange)
- {
- mnMinimum = rRange.mnMinimum;
- mnMaximum = rRange.mnMaximum;
- return *this;
- }
-
bool equal(const BasicRange& rRange) const
{
return (
diff --git a/basegfx/test/basegfx2d.cxx b/basegfx/test/basegfx2d.cxx
index e888fe52aed5..424133aec10b 100644
--- a/basegfx/test/basegfx2d.cxx
+++ b/basegfx/test/basegfx2d.cxx
@@ -45,6 +45,11 @@
#include <basegfx/polygon/b2dpolypolygontools.hxx>
#include <basegfx/polygon/b2dpolygonclipper.hxx>
#include <basegfx/polygon/b2dpolypolygon.hxx>
+#include <basegfx/range/b2irange.hxx>
+#include <basegfx/range/b2ibox.hxx>
+#include <basegfx/range/b1drange.hxx>
+#include <basegfx/range/b1irange.hxx>
+#include <basegfx/range/b1ibox.hxx>
#include <basegfx/range/b2dpolyrange.hxx>
#include <basegfx/numeric/ftools.hxx>
#include <basegfx/color/bcolor.hxx>
@@ -1219,7 +1224,7 @@ public:
}; // class b2dquadraticbezier
-class b2drange : public CppUnit::TestFixture
+class b1Xrange : public CppUnit::TestFixture
{
public:
// initialise your test code values here.
@@ -1231,19 +1236,109 @@ public:
{
}
- // insert your test code here.
- void EmptyMethod()
+ template<class Type> void implCheck()
+ {
+ // test interval axioms
+ // (http://en.wikipedia.org/wiki/Interval_%28mathematics%29)
+ Type aRange;
+ CPPUNIT_ASSERT_MESSAGE("default ctor - empty range", aRange.isEmpty());
+ CPPUNIT_ASSERT_MESSAGE("center - get cop-out value since range is empty", aRange.getCenter()==0);
+
+ // degenerate interval
+ aRange.expand(1);
+ CPPUNIT_ASSERT_MESSAGE("degenerate range - still, not empty!", !aRange.isEmpty());
+ CPPUNIT_ASSERT_MESSAGE("degenerate range - size of 0", aRange.getRange() == 0);
+ CPPUNIT_ASSERT_MESSAGE("same value as degenerate range - is inside range", aRange.isInside(1));
+ CPPUNIT_ASSERT_MESSAGE("center - must be the single range value", aRange.getCenter()==1);
+
+ // proper interval
+ aRange.expand(2);
+ CPPUNIT_ASSERT_MESSAGE("proper range - size of 1", aRange.getRange() == 1);
+ CPPUNIT_ASSERT_MESSAGE("smaller value of range - is inside *closed* range", aRange.isInside(1));
+ CPPUNIT_ASSERT_MESSAGE("larger value of range - is inside *closed* range", aRange.isInside(2));
+
+ // center for proper interval that works for ints, too
+ aRange.expand(3);
+ CPPUNIT_ASSERT_MESSAGE("center - must be half of the range", aRange.getCenter()==2);
+
+ // 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));
+
+ Type aRange3(0,2);
+ CPPUNIT_ASSERT_MESSAGE("box overlapping is fully overlapping now", aRange.overlapsMore(aRange3));
+ }
+
+ void check()
{
+ implCheck<B1DRange>();
+ implCheck<B1IRange>();
}
// 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(b2drange);
- CPPUNIT_TEST(EmptyMethod);
+ SAL_CPPUNIT_TEST_SUITE(b1Xrange);
+ CPPUNIT_TEST(check);
+ SAL_CPPUNIT_TEST_SUITE_END();
+}; // class b1Xrange
+
+
+class b1ibox : public CppUnit::TestFixture
+{
+public:
+ // initialise your test code values here.
+ void setUp()
+ {
+ }
+
+ void tearDown()
+ {
+ }
+
+ void TestBox()
+ {
+ // test axioms - markedly different from proper mathematical
+ // intervals (behaviour modelled after how polygon fill
+ // algorithms fill pixels)
+ B1IBox aBox;
+ CPPUNIT_ASSERT_MESSAGE("default ctor - empty range", aBox.isEmpty());
+
+ // degenerate box
+ aBox.expand(1);
+ CPPUNIT_ASSERT_MESSAGE("degenerate box - still empty!", aBox.isEmpty());
+ CPPUNIT_ASSERT_MESSAGE("degenerate box - size of 0", aBox.getRange() == 0);
+ CPPUNIT_ASSERT_MESSAGE("same value as degenerate box - is outside (since empty)", !aBox.isInside(1));
+ CPPUNIT_ASSERT_MESSAGE("center - get cop-out value since box is empty", aBox.getCenter()==0);
+
+ // proper box
+ aBox.expand(2);
+ CPPUNIT_ASSERT_MESSAGE("proper box - size of 1", aBox.getRange() == 1);
+ CPPUNIT_ASSERT_MESSAGE("smaller value of box", aBox.isInside(1));
+ CPPUNIT_ASSERT_MESSAGE("larger value of box - must be outside", !aBox.isInside(2));
+
+ // center for proper box that works for ints, too
+ aBox.expand(4);
+ CPPUNIT_ASSERT_MESSAGE("center - must be center pixel of the box", aBox.getCenter()==2);
+
+ // check overlap, which is markedly different from Range
+ B1IBox aBox2(0,1);
+ CPPUNIT_ASSERT_MESSAGE("box overlapping *excludes* upper bound", !aBox.overlaps(aBox2));
+
+ B1IBox aBox3(0,2);
+ CPPUNIT_ASSERT_MESSAGE("box overlapping then includes upper bound-1", aBox.overlaps(aBox3));
+ }
+
+ // 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(b1ibox);
+ CPPUNIT_TEST(TestBox);
SAL_CPPUNIT_TEST_SUITE_END();
-}; // class b2drange
+}; // class b1ibox
class b2dtuple : public CppUnit::TestFixture
@@ -1487,7 +1582,8 @@ CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b2dpolygon);
CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b2dpolygontools);
CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b2dpolypolygon);
CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b2dquadraticbezier);
-CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b2drange);
+CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b1Xrange);
+CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b1ibox);
CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b2dtuple);
CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::b2dvector);
CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::bcolor);