[geos-commits] [SCM] GEOS branch 3.9 updated. c5437e903598aaca10fcdacda36bc1b115c50262

git at osgeo.org git at osgeo.org
Tue Oct 5 13:16:36 PDT 2021


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GEOS".

The branch, 3.9 has been updated
       via  c5437e903598aaca10fcdacda36bc1b115c50262 (commit)
      from  1f727025ec8c19f2d540c902580862ef4c670b11 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit c5437e903598aaca10fcdacda36bc1b115c50262
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date:   Tue Oct 5 12:49:36 2021 -0700

    Avoid raising double overflow signals in distance calcs

diff --git a/NEWS b/NEWS
index db42c61..b606e21 100644
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,7 @@ Changes in 3.9.2
   - Catch memory leaks on createPolygon failure (#1111, Paul Ramsey)
   - Fix DiscreteFrechetDistance to use initial points of input lines (#1128, Martin Davis)
   - Avoid stack overflow in KdTree::queryNode (Even Roualt)
+  - Avoid raising double overflow signals in distance calcs (Paul Ramsey)
 
 
 Changes in 3.9.1
diff --git a/include/geos/algorithm/CentralEndpointIntersector.h b/include/geos/algorithm/CentralEndpointIntersector.h
index 4c9145c..e5ca8cd 100644
--- a/include/geos/algorithm/CentralEndpointIntersector.h
+++ b/include/geos/algorithm/CentralEndpointIntersector.h
@@ -140,7 +140,7 @@ private:
     findNearestPoint(const geom::Coordinate& p,
                      const std::vector<geom::Coordinate>& pts) const
     {
-        double minDistSq = std::numeric_limits<double>::max();
+        double minDistSq = DoubleInfinity;
         geom::Coordinate result = geom::Coordinate::getNull();
         for(std::size_t i = 0, n = pts.size(); i < n; ++i) {
             double distSq = p.distanceSquared(pts[i]);
diff --git a/src/algorithm/InteriorPointLine.cpp b/src/algorithm/InteriorPointLine.cpp
index 4aa5ac1..3fb5155 100644
--- a/src/algorithm/InteriorPointLine.cpp
+++ b/src/algorithm/InteriorPointLine.cpp
@@ -40,7 +40,7 @@ namespace algorithm { // geos.algorithm
 
 InteriorPointLine::InteriorPointLine(const Geometry* g)
 {
-    minDistance = DoubleMax;
+    minDistance = DoubleInfinity;
     hasInterior = false;
     if (g->getCentroid(centroid)) {
 #if GEOS_DEBUG
diff --git a/src/algorithm/InteriorPointPoint.cpp b/src/algorithm/InteriorPointPoint.cpp
index 5d23333..6e52fb5 100644
--- a/src/algorithm/InteriorPointPoint.cpp
+++ b/src/algorithm/InteriorPointPoint.cpp
@@ -33,7 +33,7 @@ namespace algorithm { // geos.algorithm
 /*public*/
 InteriorPointPoint::InteriorPointPoint(const Geometry* g)
 {
-    minDistance = DoubleMax;
+    minDistance = DoubleInfinity;
     if (! g->getCentroid(centroid)) {
         hasInterior = false;
     }
diff --git a/src/algorithm/MinimumBoundingCircle.cpp b/src/algorithm/MinimumBoundingCircle.cpp
index 2cd1538..0898e56 100644
--- a/src/algorithm/MinimumBoundingCircle.cpp
+++ b/src/algorithm/MinimumBoundingCircle.cpp
@@ -299,7 +299,7 @@ MinimumBoundingCircle::lowestPoint(std::vector<Coordinate>& pts)
 Coordinate
 MinimumBoundingCircle::pointWitMinAngleWithX(std::vector<Coordinate>& pts, Coordinate& P)
 {
-    double minSin = std::numeric_limits<double>::max();
+    double minSin = DoubleInfinity;
     Coordinate minAngPt;
     minAngPt.setNull();
     for(const auto& p : pts) {
@@ -333,7 +333,7 @@ Coordinate
 MinimumBoundingCircle::pointWithMinAngleWithSegment(std::vector<Coordinate>& pts, Coordinate& P, Coordinate& Q)
 {
     assert(!pts.empty());
-    double minAng = std::numeric_limits<double>::max();
+    double minAng = DoubleInfinity;
     const Coordinate* minAngPt = &pts[0];
 
     for(const auto& p : pts) {
diff --git a/src/algorithm/MinimumDiameter.cpp b/src/algorithm/MinimumDiameter.cpp
index 9aa73bc..ee2728a 100644
--- a/src/algorithm/MinimumDiameter.cpp
+++ b/src/algorithm/MinimumDiameter.cpp
@@ -285,10 +285,10 @@ MinimumDiameter::getMinimumRectangle()
     double dx = minBaseSeg.p1.x - minBaseSeg.p0.x;
     double dy = minBaseSeg.p1.y - minBaseSeg.p0.y;
 
-    double minPara = DoubleMax;
-    double maxPara = -DoubleMax;
-    double minPerp = DoubleMax;
-    double maxPerp = -DoubleMax;
+    double minPara = DoubleInfinity;
+    double maxPara = DoubleNegInfinity;
+    double minPerp = DoubleInfinity;
+    double maxPerp = DoubleNegInfinity;
 
     // compute maxima and minima of lines parallel and perpendicular to base segment
     std::size_t const n = convexHullPts->getSize();
diff --git a/src/geom/LineSegment.cpp b/src/geom/LineSegment.cpp
index 0716766..1b6c19a 100644
--- a/src/geom/LineSegment.cpp
+++ b/src/geom/LineSegment.cpp
@@ -209,7 +209,7 @@ LineSegment::closestPoints(const LineSegment& line)
      */
     std::array<Coordinate, 2> closestPt;
 
-    double minDistance = DoubleMax;
+    double minDistance = DoubleInfinity;
     double dist;
 
     Coordinate close00;
diff --git a/src/operation/distance/DistanceOp.cpp b/src/operation/distance/DistanceOp.cpp
index 82b27d2..bbf7ff0 100644
--- a/src/operation/distance/DistanceOp.cpp
+++ b/src/operation/distance/DistanceOp.cpp
@@ -82,20 +82,20 @@ DistanceOp::nearestPoints(const Geometry* g0, const Geometry* g1)
 DistanceOp::DistanceOp(const Geometry* g0, const Geometry* g1):
     geom{g0, g1},
     terminateDistance(0.0),
-    minDistance(DoubleMax)
+    minDistance(DoubleInfinity)
 {}
 
 DistanceOp::DistanceOp(const Geometry& g0, const Geometry& g1):
     geom{&g0, &g1},
     terminateDistance(0.0),
-    minDistance(DoubleMax)
+    minDistance(DoubleInfinity)
 {}
 
 DistanceOp::DistanceOp(const Geometry& g0, const Geometry& g1, double tdist)
     :
     geom{&g0, &g1},
     terminateDistance(tdist),
-    minDistance(DoubleMax)
+    minDistance(DoubleInfinity)
 {}
 
 /**
diff --git a/tests/unit/capi/GEOSDistanceTest.cpp b/tests/unit/capi/GEOSDistanceTest.cpp
index a71b6f0..11e1b33 100644
--- a/tests/unit/capi/GEOSDistanceTest.cpp
+++ b/tests/unit/capi/GEOSDistanceTest.cpp
@@ -11,6 +11,7 @@
 #include <cstdlib>
 #include <memory>
 #include <math.h>
+#include <fenv.h>
 
 namespace tut {
 //
@@ -150,5 +151,31 @@ void object::test<3>
     GEOSGeom_destroy(g2);
 }
 
+// distance between boundables should not raise floating point exception
+template<>
+template<>
+void object::test<4>
+()
+{
+    GEOSGeometry* g1 = GEOSGeomFromWKT("LINESTRING (0 0, 1 1)");
+    GEOSGeometry* g2 = GEOSGeomFromWKT("LINESTRING (2 2, 3 3)");
+
+    // clear all floating point exceptions
+    feclearexcept (FE_ALL_EXCEPT);
+
+    double d;
+    int status = GEOSDistance(g1, g2, &d);
+
+    ensure_equals(status, 1);
+    ensure_equals(d, sqrt(2));
+
+    // check for floating point overflow exceptions
+    int raised = fetestexcept(FE_OVERFLOW);
+    ensure_equals(raised & FE_OVERFLOW, 0);
+
+    GEOSGeom_destroy(g1);
+    GEOSGeom_destroy(g2);
+}
+
 } // namespace tut
 
diff --git a/tests/unit/capi/GEOSSTRtreeTest.cpp b/tests/unit/capi/GEOSSTRtreeTest.cpp
index c46d39a..852cd35 100644
--- a/tests/unit/capi/GEOSSTRtreeTest.cpp
+++ b/tests/unit/capi/GEOSSTRtreeTest.cpp
@@ -4,6 +4,7 @@
 #include <tut/tut.hpp>
 // geos
 #include <geos_c.h>
+#include <geos/constants.h>
 // std
 #include <cstdarg>
 #include <cstdio>
@@ -129,7 +130,7 @@ void object::test<2>
     for(size_t i = 0; i < ngeoms; i++) {
         const GEOSGeometry* nearest = GEOSSTRtree_nearest(tree, queryPoints[i]);
         const GEOSGeometry* nearestBruteForce = nullptr;
-        double nearestBruteForceDistance = std::numeric_limits<double>::max();
+        double nearestBruteForceDistance = geos::DoubleInfinity;
         for(size_t j = 0; j < ngeoms; j++) {
             double distance;
             GEOSDistance(queryPoints[i], geoms[j], &distance);

-----------------------------------------------------------------------

Summary of changes:
 NEWS                                               |  1 +
 .../geos/algorithm/CentralEndpointIntersector.h    |  2 +-
 src/algorithm/InteriorPointLine.cpp                |  2 +-
 src/algorithm/InteriorPointPoint.cpp               |  2 +-
 src/algorithm/MinimumBoundingCircle.cpp            |  4 ++--
 src/algorithm/MinimumDiameter.cpp                  |  8 +++----
 src/geom/LineSegment.cpp                           |  2 +-
 src/operation/distance/DistanceOp.cpp              |  6 ++---
 tests/unit/capi/GEOSDistanceTest.cpp               | 27 ++++++++++++++++++++++
 tests/unit/capi/GEOSSTRtreeTest.cpp                |  3 ++-
 10 files changed, 43 insertions(+), 14 deletions(-)


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list