]> git.localhorst.tv Git - gong.git/blobdiff - tst/geometry/IntersectionTest.cpp
simple AABB intersection test
[gong.git] / tst / geometry / IntersectionTest.cpp
index d2332fe7f74b7ddb55ee2a449b0fdb9459788411..36cacdfa8bd309293c8224a0da636f9dd544e34d 100644 (file)
@@ -21,6 +21,64 @@ void IntersectionTest::tearDown() {
 }
 
 
+void IntersectionTest::testAABB() {
+       AABB a{ { -1, -1, -1 }, { 1, 1, 1 } };
+       AABB b(a);
+
+       CPPUNIT_ASSERT_MESSAGE(
+               "coincidental AABBs should intersect",
+               Intersection(a, b)
+       );
+
+       b.Move({ 1, 0, 0 });
+       CPPUNIT_ASSERT_MESSAGE(
+               "AABBs should intersect",
+               Intersection(a, b)
+       );
+
+       b.Move({ 2, 0, 0 });
+       CPPUNIT_ASSERT_MESSAGE(
+               "AABBs should not intersect",
+               !Intersection(a, b)
+       );
+
+       b.Move({ -4, 0, 0 });
+       CPPUNIT_ASSERT_MESSAGE(
+               "AABBs should intersect",
+               Intersection(a, b)
+       );
+
+       b.Move({ -2, 0, 0 });
+       CPPUNIT_ASSERT_MESSAGE(
+               "AABBs should not intersect",
+               !Intersection(a, b)
+       );
+
+       b.Move({ 3, 1, 0 });
+       CPPUNIT_ASSERT_MESSAGE(
+               "AABBs should intersect",
+               Intersection(a, b)
+       );
+
+       b.Move({ 0, 2, 0 });
+       CPPUNIT_ASSERT_MESSAGE(
+               "AABBs should not intersect",
+               !Intersection(a, b)
+       );
+
+       b.Move({ 2, 0, 0 });
+       CPPUNIT_ASSERT_MESSAGE(
+               "AABBs should not intersect",
+               !Intersection(a, b)
+       );
+
+       b.Move({ 0, 0, 2 });
+       CPPUNIT_ASSERT_MESSAGE(
+               "AABBs should not intersect",
+               !Intersection(a, b)
+       );
+}
+
 void IntersectionTest::testSimpleRayBox() {
        Ray ray{ { 0, 0, 0 }, { 1, 0, 0 }, { } }; // at origin, pointing right
        ray.Update();