]> git.tdb.fi Git - libs/math.git/blob - tests/sphere.cpp
Some basic test cases
[libs/math.git] / tests / sphere.cpp
1 #include <msp/geometry/circle.h>
2 #include <msp/linal/vector2.h>
3 #include <msp/test/test.h>
4
5 using namespace Msp;
6
7 class HyperSphereTests: public Test::RegisteredTest<HyperSphereTests>
8 {
9 public:
10         HyperSphereTests();
11
12         static const char *get_name() { return "HyperSphere"; }
13
14 private:
15         void ray_intersection();
16 };
17
18 HyperSphereTests::HyperSphereTests()
19 {
20         add(&HyperSphereTests::ray_intersection, "Ray intersection");
21 }
22
23 void HyperSphereTests::ray_intersection()
24 {
25         Geometry::Circle<double> circle(1.5);
26         Geometry::Ray<double, 2> ray(LinAl::Vector2<double>(2.5, 0), LinAl::Vector2<double>(-1, 0));
27         EXPECT(circle.check_intersection(ray));
28         ray = Geometry::Ray<double, 2>(LinAl::Vector2<double>(2.5, 0), LinAl::Vector2<double>(1, 0));
29         EXPECT(!circle.check_intersection(ray));
30         ray = Geometry::Ray<double, 2>(LinAl::Vector2<double>(2.5, 0), LinAl::Vector2<double>(-4, 2.95));
31         EXPECT(circle.check_intersection(ray));
32         ray = Geometry::Ray<double, 2>(LinAl::Vector2<double>(2.5, 0), LinAl::Vector2<double>(-4, 3.05));
33         EXPECT(!circle.check_intersection(ray));
34 }