From 7b6ccd57d3d621af5491b728c83169b70c253f45 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dennis=20Gl=C3=A4ser?= <dennis.glaeser@iws.uni-stuttgart.de>
Date: Wed, 20 Oct 2021 17:29:20 +0200
Subject: [PATCH] [test] test polygon intersections in 3d space

---
 test/geometry/test_2d2d_intersection.cc | 56 ++++++++++++++++++++++++-
 1 file changed, 55 insertions(+), 1 deletion(-)

diff --git a/test/geometry/test_2d2d_intersection.cc b/test/geometry/test_2d2d_intersection.cc
index a9951bc455..426b591fe7 100644
--- a/test/geometry/test_2d2d_intersection.cc
+++ b/test/geometry/test_2d2d_intersection.cc
@@ -128,14 +128,68 @@ void testPolygonIntersections(std::vector<bool>& returns)
     }
 }
 
+void testParallelPolygons(std::vector<bool>& returns)
+{
+    using Point = Dune::FieldVector<double, 3>;
+
+    for (auto scaling : {1.0, 1e3, 1e12, 1e-12})
+    {
+        const double unit = 1.0*scaling;
+        const double offUnit = (1.0 + 1e-6)*scaling;
+
+        std::cout << "Test with scaling " << scaling << std::endl;
+        const auto tria1 = makeTriangle( Point{{0.0, 0.0, unit}},
+                                         Point{{unit, 0.0, unit}},
+                                         Point{{unit, unit, unit}} );
+        const auto tria2 = makeTriangle( Point{{0.0, 0.0, offUnit}},
+                                         Point{{0.0, unit, offUnit}},
+                                         Point{{unit, 0.0, offUnit}} );
+        returns.push_back(testPolygonIntersection<3>(tria1, tria2, false));
+    }
+
+    std::cout << std::endl;
+}
+
+void testNonParallelPolygons(std::vector<bool>& returns)
+{
+    using Point = Dune::FieldVector<double, 3>;
+
+    for (auto scaling : {1.0, 1e3, 1e12, 1e-12})
+    {
+        const double unit = 1.0*scaling;
+        const double offUnit = (1.0 + 1e-6)*scaling;
+
+        std::cout << "Test with scaling " << scaling << std::endl;
+        const auto tria1 = makeTriangle( Point{{0.0, 0.0, unit}},
+                                         Point{{unit, 0.0, unit}},
+                                         Point{{unit, unit, unit}} );
+        const auto tria2 = makeTriangle( Point{{0.0, 0.0, unit}},
+                                         Point{{0.0, unit, unit}},
+                                         Point{{unit, 0.0, offUnit}} );
+        returns.push_back(testPolygonIntersection<3>(tria1, tria2, false));
+    }
+
+    std::cout << std::endl;
+}
+
 #endif
 
 int main(int argc, char* argv[])
 {
     std::vector<bool> returns;
+
+    std::cout << "Testing intersections in 2d space" << std::endl;
     testPolygonIntersections<2>(returns);
 
-    // TODO: implement and test intersections in 3d
+    std::cout << "Testing intersecions in 3d space" << std::endl;
+    testPolygonIntersections<3>(returns);
+
+    std::cout << "Testing parallel polygons in 3d space" << std::endl;
+    testParallelPolygons(returns);
+
+    std::cout << "Testing non-parallel polygons in 3d space" << std::endl;
+    testNonParallelPolygons(returns);
+
     // TODO: implement and test point and segment intersections
 
     // determine the exit code
-- 
GitLab