From 2d1ad723f02c0ff21f6ac3855b68ac347b23bc12 Mon Sep 17 00:00:00 2001
From: Thomas Fischer <thomas.fischer@ufz.de>
Date: Tue, 7 Jun 2016 10:31:00 +0200
Subject: [PATCH] [MaL/GL] Mv isPointInTetrahedron() from GL to MaL.

---
 GeoLib/AnalyticalGeometry.cpp     | 30 ------------------------------
 GeoLib/AnalyticalGeometry.h       | 17 -----------------
 MathLib/GeometricBasics.cpp       | 30 ++++++++++++++++++++++++++++++
 MathLib/GeometricBasics.h         | 22 ++++++++++++++++++++++
 MeshLib/Elements/HexRule8.cpp     | 13 ++++++-------
 MeshLib/Elements/PrismRule6.cpp   |  7 +++----
 MeshLib/Elements/PyramidRule5.cpp | 11 +++++++----
 MeshLib/Elements/TetRule4.cpp     |  3 +--
 8 files changed, 69 insertions(+), 64 deletions(-)

diff --git a/GeoLib/AnalyticalGeometry.cpp b/GeoLib/AnalyticalGeometry.cpp
index 9b02181d393..b8006bd6c43 100644
--- a/GeoLib/AnalyticalGeometry.cpp
+++ b/GeoLib/AnalyticalGeometry.cpp
@@ -321,36 +321,6 @@ bool barycentricPointInTriangle(MathLib::Point3d const& p,
     return true;
 }
 
-bool isPointInTetrahedron(MathLib::Point3d const& p,
-    MathLib::Point3d const& a, MathLib::Point3d const& b,
-    MathLib::Point3d const& c, MathLib::Point3d const& d, double eps)
-{
-    double const d0 (MathLib::orientation3d(d,a,b,c));
-    // if tetrahedron is not coplanar
-    if (std::abs(d0) > std::numeric_limits<double>::epsilon())
-    {
-        bool const d0_sign (d0>0);
-        // if p is on the same side of bcd as a
-        double const d1 (MathLib::orientation3d(d, p, b, c));
-        if (!(d0_sign == (d1>=0) || std::abs(d1) < eps))
-            return false;
-        // if p is on the same side of acd as b
-        double const d2 (MathLib::orientation3d(d, a, p, c));
-        if (!(d0_sign == (d2>=0) || std::abs(d2) < eps))
-            return false;
-        // if p is on the same side of abd as c
-        double const d3 (MathLib::orientation3d(d, a, b, p));
-        if (!(d0_sign == (d3>=0) || std::abs(d3) < eps))
-            return false;
-        // if p is on the same side of abc as d
-        double const d4 (MathLib::orientation3d(p, a, b, c));
-        if (!(d0_sign == (d4>=0) || std::abs(d4) < eps))
-            return false;
-        return true;
-    }
-    return false;
-}
-
 double calcTriangleArea(MathLib::Point3d const& a,
     MathLib::Point3d const& b, MathLib::Point3d const& c)
 {
diff --git a/GeoLib/AnalyticalGeometry.h b/GeoLib/AnalyticalGeometry.h
index 709cdadfd6c..cf5f1d83c5a 100644
--- a/GeoLib/AnalyticalGeometry.h
+++ b/GeoLib/AnalyticalGeometry.h
@@ -243,23 +243,6 @@ bool barycentricPointInTriangle(MathLib::Point3d const& p,
     double eps_pnt_out_of_plane = std::numeric_limits<float>::epsilon(),
     double eps_pnt_out_of_tri = std::numeric_limits<float>::epsilon());
 
-/**
- * Tests if the given point p is located within a tetrahedron spanned by points a, b, c, d.
- * If the tet specified by a, b, c, d is degenerated (i.e. all points are coplanar) the function
- * will return false because there is no meaningful concept of "inside" for such elements.
- * @param p test point
- * @param a edge node of tetrahedron
- * @param b edge node of tetrahedron
- * @param c edge node of tetrahedron
- * @param d edge node of tetrahedron
- * @param eps Accounts for numerical inaccuracies by allowing a point to be slightly outside of the element and still be regarded as inside.
- * @return true if the test point p is not located outside of abcd (i.e. inside or on a plane/edge).
- */
-bool isPointInTetrahedron(MathLib::Point3d const& p,
-    MathLib::Point3d const& a, MathLib::Point3d const& b,
-    MathLib::Point3d const& c, MathLib::Point3d const& d,
-    double eps = std::numeric_limits<double>::epsilon());
-
 /**
  * test for intersections of the line segments of the Polyline
  * @param ply the polyline
diff --git a/MathLib/GeometricBasics.cpp b/MathLib/GeometricBasics.cpp
index 5e43c3cc61f..caab906d2d3 100644
--- a/MathLib/GeometricBasics.cpp
+++ b/MathLib/GeometricBasics.cpp
@@ -36,4 +36,34 @@ double calcTetrahedronVolume(MathLib::Point3d const& a,
     return std::abs(MathLib::scalarTriple(ac, ad, ab)) / 6.0;
 }
 
+bool isPointInTetrahedron(MathLib::Point3d const& p, MathLib::Point3d const& a,
+                          MathLib::Point3d const& b, MathLib::Point3d const& c,
+                          MathLib::Point3d const& d, double eps)
+{
+    double const d0 (MathLib::orientation3d(d,a,b,c));
+    // if tetrahedron is not coplanar
+    if (std::abs(d0) > std::numeric_limits<double>::epsilon())
+    {
+        bool const d0_sign (d0>0);
+        // if p is on the same side of bcd as a
+        double const d1 (MathLib::orientation3d(d, p, b, c));
+        if (!(d0_sign == (d1>=0) || std::abs(d1) < eps))
+            return false;
+        // if p is on the same side of acd as b
+        double const d2 (MathLib::orientation3d(d, a, p, c));
+        if (!(d0_sign == (d2>=0) || std::abs(d2) < eps))
+            return false;
+        // if p is on the same side of abd as c
+        double const d3 (MathLib::orientation3d(d, a, b, p));
+        if (!(d0_sign == (d3>=0) || std::abs(d3) < eps))
+            return false;
+        // if p is on the same side of abc as d
+        double const d4 (MathLib::orientation3d(p, a, b, c));
+        if (!(d0_sign == (d4>=0) || std::abs(d4) < eps))
+            return false;
+        return true;
+    }
+    return false;
+}
+
 }  // end namespace MathLib
diff --git a/MathLib/GeometricBasics.h b/MathLib/GeometricBasics.h
index d5164d5365c..e97a9b5e407 100644
--- a/MathLib/GeometricBasics.h
+++ b/MathLib/GeometricBasics.h
@@ -12,6 +12,7 @@
 #define GEOMETRIC_BASICS_H_
 
 #include <cstddef>
+#include <limits>
 
 namespace MathLib
 {
@@ -44,6 +45,27 @@ double calcTetrahedronVolume(MathLib::Point3d const& x1,
                              MathLib::Point3d const& x2,
                              MathLib::Point3d const& x3,
                              MathLib::Point3d const& x4);
+/**
+ * Tests if the given point p is located within a tetrahedron spanned by points
+ * a, b, c, d.
+ * If the tet specified by a, b, c, d is degenerated (i.e. all points are
+ * coplanar) the function
+ * will return false because there is no meaningful concept of "inside" for such
+ * elements.
+ * @param p test point
+ * @param a edge node of tetrahedron
+ * @param b edge node of tetrahedron
+ * @param c edge node of tetrahedron
+ * @param d edge node of tetrahedron
+ * @param eps Accounts for numerical inaccuracies by allowing a point to be
+ * slightly outside of the element and still be regarded as inside.
+ * @return true if the test point p is not located outside of abcd (i.e. inside
+ * or on a plane/edge).
+ */
+bool isPointInTetrahedron(MathLib::Point3d const& p, MathLib::Point3d const& a,
+                          MathLib::Point3d const& b, MathLib::Point3d const& c,
+                          MathLib::Point3d const& d,
+                          double eps = std::numeric_limits<double>::epsilon());
 
 }  // end namespace MathLib
 
diff --git a/MeshLib/Elements/HexRule8.cpp b/MeshLib/Elements/HexRule8.cpp
index db669c01b53..8a4a9e4ce0d 100644
--- a/MeshLib/Elements/HexRule8.cpp
+++ b/MeshLib/Elements/HexRule8.cpp
@@ -13,7 +13,6 @@
 
 #include "logog/include/logog.hpp"
 
-#include "GeoLib/AnalyticalGeometry.h"
 #include "MathLib/GeometricBasics.h"
 
 #include "MeshLib/Node.h"
@@ -73,12 +72,12 @@ double HexRule8::computeVolume(Node const* const* _nodes)
 
 bool HexRule8::isPntInElement(Node const* const* _nodes, MathLib::Point3d const& pnt, double eps)
 {
-    return (GeoLib::isPointInTetrahedron(pnt, *_nodes[4], *_nodes[7], *_nodes[5], *_nodes[0], eps) ||
-            GeoLib::isPointInTetrahedron(pnt, *_nodes[5], *_nodes[3], *_nodes[1], *_nodes[0], eps) ||
-            GeoLib::isPointInTetrahedron(pnt, *_nodes[5], *_nodes[7], *_nodes[3], *_nodes[0], eps) ||
-            GeoLib::isPointInTetrahedron(pnt, *_nodes[5], *_nodes[7], *_nodes[6], *_nodes[2], eps) ||
-            GeoLib::isPointInTetrahedron(pnt, *_nodes[1], *_nodes[3], *_nodes[5], *_nodes[2], eps) ||
-            GeoLib::isPointInTetrahedron(pnt, *_nodes[3], *_nodes[7], *_nodes[5], *_nodes[2], eps));
+    return (MathLib::isPointInTetrahedron(pnt, *_nodes[4], *_nodes[7], *_nodes[5], *_nodes[0], eps) ||
+            MathLib::isPointInTetrahedron(pnt, *_nodes[5], *_nodes[3], *_nodes[1], *_nodes[0], eps) ||
+            MathLib::isPointInTetrahedron(pnt, *_nodes[5], *_nodes[7], *_nodes[3], *_nodes[0], eps) ||
+            MathLib::isPointInTetrahedron(pnt, *_nodes[5], *_nodes[7], *_nodes[6], *_nodes[2], eps) ||
+            MathLib::isPointInTetrahedron(pnt, *_nodes[1], *_nodes[3], *_nodes[5], *_nodes[2], eps) ||
+            MathLib::isPointInTetrahedron(pnt, *_nodes[3], *_nodes[7], *_nodes[5], *_nodes[2], eps));
 }
 
 unsigned HexRule8::identifyFace(Node const* const* _nodes, Node* nodes[3])
diff --git a/MeshLib/Elements/PrismRule6.cpp b/MeshLib/Elements/PrismRule6.cpp
index 8a1f72546f5..33dcd368860 100644
--- a/MeshLib/Elements/PrismRule6.cpp
+++ b/MeshLib/Elements/PrismRule6.cpp
@@ -11,7 +11,6 @@
 
 #include "logog/include/logog.hpp"
 
-#include "GeoLib/AnalyticalGeometry.h"
 #include "MathLib/GeometricBasics.h"
 
 #include "MeshLib/Node.h"
@@ -79,9 +78,9 @@ double PrismRule6::computeVolume(Node const* const* _nodes)
 
 bool PrismRule6::isPntInElement(Node const* const* _nodes, MathLib::Point3d const& pnt, double eps)
 {
-    return (GeoLib::isPointInTetrahedron(pnt, *_nodes[0], *_nodes[1], *_nodes[2], *_nodes[3], eps) ||
-            GeoLib::isPointInTetrahedron(pnt, *_nodes[1], *_nodes[4], *_nodes[2], *_nodes[3], eps) ||
-            GeoLib::isPointInTetrahedron(pnt, *_nodes[2], *_nodes[4], *_nodes[5], *_nodes[3], eps));
+    return (MathLib::isPointInTetrahedron(pnt, *_nodes[0], *_nodes[1], *_nodes[2], *_nodes[3], eps) ||
+            MathLib::isPointInTetrahedron(pnt, *_nodes[1], *_nodes[4], *_nodes[2], *_nodes[3], eps) ||
+            MathLib::isPointInTetrahedron(pnt, *_nodes[2], *_nodes[4], *_nodes[5], *_nodes[3], eps));
 }
 
 unsigned PrismRule6::identifyFace(Node const* const* _nodes, Node* nodes[3])
diff --git a/MeshLib/Elements/PyramidRule5.cpp b/MeshLib/Elements/PyramidRule5.cpp
index 98b3edcfdac..476aad78092 100644
--- a/MeshLib/Elements/PyramidRule5.cpp
+++ b/MeshLib/Elements/PyramidRule5.cpp
@@ -11,7 +11,6 @@
 
 #include "logog/include/logog.hpp"
 
-#include "GeoLib/AnalyticalGeometry.h"
 #include "MathLib/GeometricBasics.h"
 
 #include "MeshLib/Node.h"
@@ -75,10 +74,14 @@ double PyramidRule5::computeVolume(Node const* const* _nodes)
          + MathLib::calcTetrahedronVolume(*_nodes[2], *_nodes[3], *_nodes[0], *_nodes[4]);
 }
 
-bool PyramidRule5::isPntInElement(Node const* const* _nodes, MathLib::Point3d const& pnt, double eps)
+bool PyramidRule5::isPntInElement(Node const* const* _nodes,
+                                  MathLib::Point3d const& pnt,
+                                  double eps)
 {
-    return (GeoLib::isPointInTetrahedron(pnt, *_nodes[0], *_nodes[1], *_nodes[2], *_nodes[4], eps) ||
-            GeoLib::isPointInTetrahedron(pnt, *_nodes[0], *_nodes[2], *_nodes[3], *_nodes[4], eps));
+    return (MathLib::isPointInTetrahedron(
+                pnt, *_nodes[0], *_nodes[1], *_nodes[2], *_nodes[4], eps) ||
+            MathLib::isPointInTetrahedron(
+                pnt, *_nodes[0], *_nodes[2], *_nodes[3], *_nodes[4], eps));
 }
 
 unsigned PyramidRule5::identifyFace(Node const* const* _nodes, Node* nodes[3])
diff --git a/MeshLib/Elements/TetRule4.cpp b/MeshLib/Elements/TetRule4.cpp
index daeee368338..7f545b5454f 100644
--- a/MeshLib/Elements/TetRule4.cpp
+++ b/MeshLib/Elements/TetRule4.cpp
@@ -13,7 +13,6 @@
 
 #include "logog/include/logog.hpp"
 
-#include "GeoLib/AnalyticalGeometry.h"
 #include "MathLib/GeometricBasics.h"
 
 #include "MeshLib/Node.h"
@@ -60,7 +59,7 @@ double TetRule4::computeVolume(Node const* const* _nodes)
 
 bool TetRule4::isPntInElement(Node const* const* _nodes, MathLib::Point3d const& pnt, double eps)
 {
-    return GeoLib::isPointInTetrahedron(pnt, *_nodes[0], *_nodes[1], *_nodes[2], *_nodes[3], eps);
+    return MathLib::isPointInTetrahedron(pnt, *_nodes[0], *_nodes[1], *_nodes[2], *_nodes[3], eps);
 }
 
 unsigned TetRule4::identifyFace(Node const* const* _nodes, Node* nodes[3])
-- 
GitLab