From b9a20b919901b20097d6a510cb732d80bde58a4c Mon Sep 17 00:00:00 2001
From: "Dmitry Yu. Naumov" <github@naumov.de>
Date: Sun, 19 Jul 2015 17:34:28 +0000
Subject: [PATCH] [MaL] Move lessEq() for Point3d to TemplatePoint.

Extend the input to arbitrary TemplatePoint,
but it is working only for TemplatePoint<double, 3>
== Point3d for now.
---
 MathLib/Point3d.cpp     | 29 -----------------------------
 MathLib/Point3d.h       | 12 ------------
 MathLib/TemplatePoint.h | 39 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 39 insertions(+), 41 deletions(-)

diff --git a/MathLib/Point3d.cpp b/MathLib/Point3d.cpp
index ad1b56ea7e0..5c4b5de4250 100644
--- a/MathLib/Point3d.cpp
+++ b/MathLib/Point3d.cpp
@@ -18,33 +18,4 @@
 namespace MathLib
 {
 
-bool lessEq(const MathLib::Point3d& p0, const MathLib::Point3d& p1, double tol)
-{
-	// test a relative and an absolute criterion
-	if (fabs(p0[0]-p1[0]) > tol * std::min(fabs(p1[0]), fabs(p0[0])) && fabs(p0[0]-p1[0]) > tol) {
-		if (p0[0] <= p1[0])
-			return true;
-		else
-			return false;
-	} else {
-		// assume p0[0] == p1[0]
-		if (fabs (p0[1]-p1[1]) > tol * fabs(p0[1]) && fabs(p0[1]-p1[1]) > tol) {
-			if (p0[1] <= p1[1])
-				return true;
-			else
-				return false;
-		} else {
-			// assume p0[1] == p1[1] and p0[0] == p1[0]
-			if (fabs (p0[2]-p1[2]) > tol * fabs(p0[2]) && fabs(p0[2]-p1[2]) > tol) {
-				if (p0[2] <= p1[2])
-					return true;
-				else
-					return false;
-			} else {
-				return true;
-			}
-		}
-	}
-}
-
 }	// namespace MathLib
diff --git a/MathLib/Point3d.h b/MathLib/Point3d.h
index 85ed4b4ca4c..938bf88807e 100644
--- a/MathLib/Point3d.h
+++ b/MathLib/Point3d.h
@@ -23,18 +23,6 @@ namespace MathLib
 {
 typedef MathLib::TemplatePoint<double,3> Point3d;
 
-/**
- * lexicographical comparison of points taking an epsilon into account
- * @param p0 first input Point3d
- * @param p1 second input Point3d
- * @param tol tolerance (if in the comparison operation the property fabs(p0[k] - p1[k]) < tol
- *     holds for the k-th coordinate the points are assumed the be equal in this coordinate)
- * @return true, if p0 is lexicographically smaller than p1
- */
-bool lessEq(const MathLib::Point3d& p0,
-            const MathLib::Point3d& p1,
-            double tol = std::numeric_limits<double>::epsilon());
-
 /**
  * rotation of points
  * @param mat a rotation matrix
diff --git a/MathLib/TemplatePoint.h b/MathLib/TemplatePoint.h
index d6429bf2fe9..5fda916ef8f 100644
--- a/MathLib/TemplatePoint.h
+++ b/MathLib/TemplatePoint.h
@@ -130,6 +130,45 @@ bool operator< (TemplatePoint<T,DIM> const& a, TemplatePoint<T,DIM> const& b)
 	return false;
 }
 
+/**
+ * lexicographical comparison of points taking an epsilon into account
+ * @param p0 first input Point3d
+ * @param p1 second input Point3d
+ * @param tol tolerance (if in the comparison operation the property fabs(p0[k] - p1[k]) < tol
+ *     holds for the k-th coordinate the points are assumed the be equal in this coordinate)
+ * @return true, if p0 is lexicographically smaller than p1
+ */
+template <typename T, std::size_t DIM>
+bool lessEq(TemplatePoint<T, DIM> const& a, TemplatePoint<T, DIM> const& b,
+		double tol = std::numeric_limits<double>::epsilon())
+{
+	// test a relative and an absolute criterion
+	if (fabs(a[0]-b[0]) > tol * std::min(fabs(b[0]), fabs(a[0])) && fabs(a[0]-b[0]) > tol) {
+		if (a[0] <= b[0])
+			return true;
+		else
+			return false;
+	} else {
+		// assume a[0] == b[0]
+		if (fabs (a[1]-b[1]) > tol * fabs(a[1]) && fabs(a[1]-b[1]) > tol) {
+			if (a[1] <= b[1])
+				return true;
+			else
+				return false;
+		} else {
+			// assume a[1] == b[1] and a[0] == b[0]
+			if (fabs (a[2]-b[2]) > tol * fabs(a[2]) && fabs(a[2]-b[2]) > tol) {
+				if (a[2] <= b[2])
+					return true;
+				else
+					return false;
+			} else {
+				return true;
+			}
+		}
+	}
+}
+
 /** Distance between points p0 and p1 in the maximum norm. */
 template <typename T>
 T maxNormDist(const MathLib::TemplatePoint<T>* p0, const MathLib::TemplatePoint<T>* p1)
-- 
GitLab