]> git.tdb.fi Git - libs/math.git/blobdiff - tests/transformedshape.cpp
Some basic test cases
[libs/math.git] / tests / transformedshape.cpp
diff --git a/tests/transformedshape.cpp b/tests/transformedshape.cpp
new file mode 100644 (file)
index 0000000..5468a73
--- /dev/null
@@ -0,0 +1,32 @@
+#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));
+}