aboutsummaryrefslogtreecommitdiffstats
path: root/test/utils
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2012-03-21 21:36:59 +0100
committerAlexander Sulfrian <alexander@sulfrian.net>2013-01-05 17:17:51 +0100
commitb489968dcc1416a530b9f5289b47962e39ec4158 (patch)
treeeb299b599bd0f7ae98661d61eb33d971250d7b67 /test/utils
parente762b9d1a0080bfbba36d1b53ada858d05e13db1 (diff)
downloadusdx-b489968dcc1416a530b9f5289b47962e39ec4158.tar.gz
usdx-b489968dcc1416a530b9f5289b47962e39ec4158.tar.xz
usdx-b489968dcc1416a530b9f5289b47962e39ec4158.zip
utils/rectangle: added function to intersect two rectangles
Diffstat (limited to 'test/utils')
-rw-r--r--test/utils/rectangle.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/test/utils/rectangle.cpp b/test/utils/rectangle.cpp
index f2fe93ea..0cfbece2 100644
--- a/test/utils/rectangle.cpp
+++ b/test/utils/rectangle.cpp
@@ -35,6 +35,8 @@ namespace usdx
class RectangleTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(RectangleTest);
CPPUNIT_TEST(testInit);
+ CPPUNIT_TEST(testIntersectInner);
+ CPPUNIT_TEST(testIntersectOuter);
CPPUNIT_TEST_SUITE_END();
private:
static log4cpp::Category& log;
@@ -57,6 +59,30 @@ namespace usdx
CPPUNIT_ASSERT(rect.get_width() == 200);
CPPUNIT_ASSERT(rect.get_height() == 250);
}
+
+ void testIntersectInner()
+ {
+ Rectangle<int> outer(100, 150, 200, 250);
+ Rectangle<int> inner(120, 170, 180, 200);
+ Rectangle<int> intersect = outer.intersect(inner);
+
+ CPPUNIT_ASSERT(intersect.get_point1().get_x() == 120);
+ CPPUNIT_ASSERT(intersect.get_point1().get_y() == 170);
+ CPPUNIT_ASSERT(intersect.get_point2().get_x() == 180);
+ CPPUNIT_ASSERT(intersect.get_point2().get_y() == 200);
+ }
+
+ void testIntersectOuter()
+ {
+ Rectangle<int> outer(120, 170, 180, 200);
+ Rectangle<int> inner(100, 150, 200, 250);
+ Rectangle<int> intersect = outer.intersect(inner);
+
+ CPPUNIT_ASSERT(intersect.get_point1().get_x() == 120);
+ CPPUNIT_ASSERT(intersect.get_point1().get_y() == 170);
+ CPPUNIT_ASSERT(intersect.get_point2().get_x() == 180);
+ CPPUNIT_ASSERT(intersect.get_point2().get_y() == 200);
+ }
};
log4cpp::Category& RectangleTest::log =