From dac1db4da9ec2424be4e5aabbf164dcfd8983e44 Mon Sep 17 00:00:00 2001
From: Dmitri Naumov <dmitri.naumov@ufz.de>
Date: Tue, 19 Feb 2019 18:05:04 +0100
Subject: [PATCH] [GL] Add a fast and non-robust version of orient2d

---
 GeoLib/AnalyticalGeometry.cpp | 23 +++++++++++++++++++++++
 GeoLib/AnalyticalGeometry.h   | 10 +++++++++-
 2 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/GeoLib/AnalyticalGeometry.cpp b/GeoLib/AnalyticalGeometry.cpp
index dd029dc5bb1..283a4a955b0 100644
--- a/GeoLib/AnalyticalGeometry.cpp
+++ b/GeoLib/AnalyticalGeometry.cpp
@@ -30,6 +30,7 @@
 #include "MathLib/GeometricBasics.h"
 
 extern double orient2d(double *, double *, double *);
+extern double orient2dfast(double*, double*, double*);
 
 namespace ExactPredicates
 {
@@ -40,6 +41,15 @@ double getOrientation2d(MathLib::Point3d const& a,
         const_cast<double*>(b.getCoords()),
         const_cast<double*>(c.getCoords()));
 }
+
+double getOrientation2dFast(MathLib::Point3d const& a,
+                            MathLib::Point3d const& b,
+                            MathLib::Point3d const& c)
+{
+    return orient2dfast(const_cast<double*>(a.getCoords()),
+                        const_cast<double*>(b.getCoords()),
+                        const_cast<double*>(c.getCoords()));
+}
 }
 
 namespace GeoLib
@@ -56,6 +66,19 @@ Orientation getOrientation(MathLib::Point3d const& p0,
     return COLLINEAR;
 }
 
+Orientation getOrientationFast(MathLib::Point3d const& p0,
+                               MathLib::Point3d const& p1,
+                               MathLib::Point3d const& p2)
+{
+    double const orientation =
+        ExactPredicates::getOrientation2dFast(p0, p1, p2);
+    if (orientation > 0)
+        return CCW;
+    if (orientation < 0)
+        return CW;
+    return COLLINEAR;
+}
+
 bool parallel(MathLib::Vector3 v, MathLib::Vector3 w)
 {
     const double eps(std::numeric_limits<double>::epsilon());
diff --git a/GeoLib/AnalyticalGeometry.h b/GeoLib/AnalyticalGeometry.h
index 300dd5d42c4..b66cd04835a 100644
--- a/GeoLib/AnalyticalGeometry.h
+++ b/GeoLib/AnalyticalGeometry.h
@@ -39,13 +39,21 @@ enum Orientation
 };
 
 /**
- * Computes the orientation of the three 2D-Points.
+ * Computes the orientation of the three 2D-Points. This is a robust method.
  * \returns CW (clockwise), CCW (counterclockwise) or COLLINEAR (points are on a
  * line)
  */
 Orientation getOrientation(MathLib::Point3d const& p0,
                            MathLib::Point3d const& p1,
                            MathLib::Point3d const& p2);
+/**
+ * Computes the orientation of the three 2D-Points. This is a non-robust method.
+ * \returns CW (clockwise), CCW (counterclockwise) or COLLINEAR (points are on a
+ * line)
+ */
+Orientation getOrientationFast(MathLib::Point3d const& p0,
+                               MathLib::Point3d const& p1,
+                               MathLib::Point3d const& p2);
 /**
  * compute a supporting plane (represented by plane_normal and the value d) for the polygon
  * Let \f$n\f$ be the plane normal and \f$d\f$ a parameter. Then for all points \f$p \in R^3\f$ of the plane
-- 
GitLab