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