From a4536e61ee1a5d09a2c4c8d6e99ff9a1ae35d03e Mon Sep 17 00:00:00 2001
From: Thomas Fischer <thomas.fischer@ufz.de>
Date: Mon, 26 Feb 2024 11:58:00 +0100
Subject: [PATCH] [GL] OctTree::addPoint() Ensure max of range query is larger
 than query point

Add eps could lead the same floating point number,
instead resize to the next larger floating point number that is available
---
 GeoLib/OctTree-impl.h | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/GeoLib/OctTree-impl.h b/GeoLib/OctTree-impl.h
index 96a51f6ef2e..8f26d27aaf8 100644
--- a/GeoLib/OctTree-impl.h
+++ b/GeoLib/OctTree-impl.h
@@ -76,10 +76,22 @@ OctTree<POINT, MAX_POINTS>::~OctTree()
 template <typename POINT, std::size_t MAX_POINTS>
 bool OctTree<POINT, MAX_POINTS>::addPoint(POINT* pnt, POINT*& ret_pnt)
 {
-    // first do a range query using a epsilon box around the point pnt
+    // first do a range query using a small box around the point pnt
     std::vector<POINT*> query_pnts;
     Eigen::Vector3d const min = pnt->asEigenVector3d().array() - _eps;
-    Eigen::Vector3d const max = pnt->asEigenVector3d().array() + _eps;
+    Eigen::Vector3d const max = {
+        std::abs(((*pnt)[0] + _eps) - (*pnt)[0]) > 0.0
+            ? (*pnt)[0] + _eps
+            : std::nextafter((*pnt)[0],
+                             std::numeric_limits<double>::infinity()),
+        std::abs(((*pnt)[1] + _eps) - (*pnt)[1]) > 0.0
+            ? (*pnt)[1] + _eps
+            : std::nextafter((*pnt)[1],
+                             std::numeric_limits<double>::infinity()),
+        std::abs(((*pnt)[2] + _eps) - (*pnt)[2]) > 0.0
+            ? (*pnt)[2] + _eps
+            : std::nextafter((*pnt)[2],
+                             std::numeric_limits<double>::infinity())};
     getPointsInRange(min, max, query_pnts);
     auto const it =
         std::find_if(query_pnts.begin(), query_pnts.end(),
-- 
GitLab