/libmspmath.a
/libmspmath.so
/mspmath.pc
+/tests/test
--- /dev/null
+package "mspmath-tests"
+{
+ require "mspcore";
+ require "msptest";
+ require "mspmath";
+
+ program "test"
+ {
+ source ".";
+ };
+};
--- /dev/null
+#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));
+}
--- /dev/null
+#include <msp/linal/matrix.h>
+#include <msp/linal/squarematrix.h>
+#include <msp/test/test.h>
+
+using namespace Msp;
+
+class MatrixTests: public Test::RegisteredTest<MatrixTests>
+{
+public:
+ MatrixTests();
+
+ static const char *get_name() { return "Matrix"; }
+
+private:
+ void multiply();
+ void invert();
+};
+
+
+MatrixTests::MatrixTests()
+{
+ add(&MatrixTests::multiply, "Multiplication");
+ add(&MatrixTests::invert, "Inversion");
+}
+
+void MatrixTests::multiply()
+{
+ static double data[] =
+ {
+ 1, 2, 1, 2, 1, 2,
+ 3, 0, 3, 0, 0, 3,
+ 3, 6, 3, 3, 6, 3, 6, 3, 6,
+ 9, 3, 9, 6
+ };
+
+ LinAl::Matrix<double, 3, 2> a(data);
+ LinAl::Matrix<double, 2, 3> b(data+6);
+ EXPECT(a*b == (LinAl::Matrix<double, 3, 3>(data+12)));
+ EXPECT(b*a == (LinAl::Matrix<double, 2, 2>(data+21)));
+}
+
+template<typename T, unsigned N>
+bool is_identity(const LinAl::Matrix<T, N, N> &m)
+{
+ for(unsigned i=0; i<N; ++i)
+ for(unsigned j=0; j<N; ++j)
+ if(abs(T(i==j)-m(i, j))>1e-10)
+ return false;
+ return true;
+}
+
+void MatrixTests::invert()
+{
+ static double data[] =
+ {
+ 1, 4, 2, 4, 8, 6, 2, 2, 4
+ };
+
+ LinAl::SquareMatrix<double, 3> m(data);
+ LinAl::SquareMatrix<double, 3> i = LinAl::invert(m);
+ EXPECT(is_identity(i*m));
+}
--- /dev/null
+#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));
+}
--- /dev/null
+#include <msp/geometry/rectangle.h>
+#include <msp/geometry/transformedshape.h>
+#include <msp/test/test.h>
+
+using namespace Msp;
+
+class TransformedShapeTests: public Test::RegisteredTest<TransformedShapeTests>
+{
+public:
+ TransformedShapeTests();
+
+ static const char *get_name() { return "TransformedShape"; }
+
+private:
+ void ray_intersection();
+};
+
+TransformedShapeTests::TransformedShapeTests()
+{
+ add(&TransformedShapeTests::ray_intersection, "Ray intersection");
+}
+
+void TransformedShapeTests::ray_intersection()
+{
+ Geometry::TransformedShape<double, 2> shape(Geometry::Rectangle<double>(2, 1), Geometry::AffineTransformation<double, 2>::rotation(Geometry::Angle<double>::from_degrees(45)));
+ Geometry::Ray<double, 2> ray(LinAl::Vector2<double>(3, 1.05), LinAl::Vector2<double>(-1, 0));
+ EXPECT(shape.check_intersection(ray));
+ ray = Geometry::Ray<double, 2>(LinAl::Vector2<double>(2.65, 3.35), LinAl::Vector2<double>(-1, -1));
+ EXPECT(shape.check_intersection(ray));
+ ray = Geometry::Ray<double, 2>(LinAl::Vector2<double>(2.6, 3.4), LinAl::Vector2<double>(-1, -1));
+ EXPECT(!shape.check_intersection(ray));
+}