X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=tests%2Fsphere.cpp;fp=tests%2Fsphere.cpp;h=7d9a4bbcf7c7648cfdc144623913a6505a5155f4;hb=eb02e224876676a2d78f7305456a7d6f67d3dee2;hp=0000000000000000000000000000000000000000;hpb=6ff13022b53830d35283905d562c2ef3af198cc1;p=libs%2Fmath.git diff --git a/tests/sphere.cpp b/tests/sphere.cpp new file mode 100644 index 0000000..7d9a4bb --- /dev/null +++ b/tests/sphere.cpp @@ -0,0 +1,34 @@ +#include +#include +#include + +using namespace Msp; + +class HyperSphereTests: public Test::RegisteredTest +{ +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 circle(1.5); + Geometry::Ray ray(LinAl::Vector2(2.5, 0), LinAl::Vector2(-1, 0)); + EXPECT(circle.check_intersection(ray)); + ray = Geometry::Ray(LinAl::Vector2(2.5, 0), LinAl::Vector2(1, 0)); + EXPECT(!circle.check_intersection(ray)); + ray = Geometry::Ray(LinAl::Vector2(2.5, 0), LinAl::Vector2(-4, 2.95)); + EXPECT(circle.check_intersection(ray)); + ray = Geometry::Ray(LinAl::Vector2(2.5, 0), LinAl::Vector2(-4, 3.05)); + EXPECT(!circle.check_intersection(ray)); +}