]> git.tdb.fi Git - libs/math.git/blobdiff - tests/sphere.cpp
Some basic test cases
[libs/math.git] / tests / sphere.cpp
diff --git a/tests/sphere.cpp b/tests/sphere.cpp
new file mode 100644 (file)
index 0000000..7d9a4bb
--- /dev/null
@@ -0,0 +1,34 @@
+#include <msp/geometry/circle.h>
+#include <msp/linal/vector2.h>
+#include <msp/test/test.h>
+
+using namespace Msp;
+
+class HyperSphereTests: public Test::RegisteredTest<HyperSphereTests>
+{
+public:
+       HyperSphereTests();
+
+       static const char *get_name() { return "HyperSphere"; }
+
+private:
+       void ray_intersection();
+};
+
+HyperSphereTests::HyperSphereTests()
+{
+       add(&HyperSphereTests::ray_intersection, "Ray intersection");
+}
+
+void HyperSphereTests::ray_intersection()
+{
+       Geometry::Circle<double> circle(1.5);
+       Geometry::Ray<double, 2> ray(LinAl::Vector2<double>(2.5, 0), LinAl::Vector2<double>(-1, 0));
+       EXPECT(circle.check_intersection(ray));
+       ray = Geometry::Ray<double, 2>(LinAl::Vector2<double>(2.5, 0), LinAl::Vector2<double>(1, 0));
+       EXPECT(!circle.check_intersection(ray));
+       ray = Geometry::Ray<double, 2>(LinAl::Vector2<double>(2.5, 0), LinAl::Vector2<double>(-4, 2.95));
+       EXPECT(circle.check_intersection(ray));
+       ray = Geometry::Ray<double, 2>(LinAl::Vector2<double>(2.5, 0), LinAl::Vector2<double>(-4, 3.05));
+       EXPECT(!circle.check_intersection(ray));
+}