]> git.tdb.fi Git - libs/math.git/blobdiff - tests/box.cpp
Some basic test cases
[libs/math.git] / tests / box.cpp
diff --git a/tests/box.cpp b/tests/box.cpp
new file mode 100644 (file)
index 0000000..860bb4e
--- /dev/null
@@ -0,0 +1,34 @@
+#include <msp/geometry/box.h>
+#include <msp/linal/vector3.h>
+#include <msp/test/test.h>
+
+using namespace Msp;
+
+class HyperBoxTests: public Test::RegisteredTest<HyperBoxTests>
+{
+public:
+       HyperBoxTests();
+
+       static const char *get_name() { return "HyperBox"; }
+
+private:
+       void ray_intersection();
+};
+
+HyperBoxTests::HyperBoxTests()
+{
+       add(&HyperBoxTests::ray_intersection, "Ray intersection");
+}
+
+void HyperBoxTests::ray_intersection()
+{
+       Geometry::Box<double> box(2, 4, 3);
+       Geometry::Ray<double, 3> ray(LinAl::Vector3<double>(10, 0, 0), LinAl::Vector3<double>(-1, 0, 0));
+       EXPECT(box.check_intersection(ray));
+       ray = Geometry::Ray<double, 3>(LinAl::Vector3<double>(10, 0, 0), LinAl::Vector3<double>(1, 0, 0));
+       EXPECT(!box.check_intersection(ray));
+       ray = Geometry::Ray<double, 3>(LinAl::Vector3<double>(9, 0, 11.45), LinAl::Vector3<double>(-1, 0, -1));
+       EXPECT(box.check_intersection(ray));
+       ray = Geometry::Ray<double, 3>(LinAl::Vector3<double>(9, 0, 11.55), LinAl::Vector3<double>(-1, 0, -1));
+       EXPECT(!box.check_intersection(ray));
+}