[geos-commits] [SCM] GEOS branch main updated. eb3299023a884547efd423df8b9dbc9ef59802ca

git at osgeo.org git at osgeo.org
Mon Oct 4 14:10:27 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, main has been updated
       via  eb3299023a884547efd423df8b9dbc9ef59802ca (commit)
      from  80398b0377f9597f6c9b05b1684e00d97f04ebef (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 eb3299023a884547efd423df8b9dbc9ef59802ca
Author: Sandro Santilli <strk at kbt.io>
Date:   Mon Oct 4 23:09:46 2021 +0200

    Always return false from DistanceWithin if any operand is empty
    
    See https://trac.osgeo.org/postgis/ticket/5008#comment:1

diff --git a/src/operation/distance/DistanceOp.cpp b/src/operation/distance/DistanceOp.cpp
index b96f892..fa73b1b 100644
--- a/src/operation/distance/DistanceOp.cpp
+++ b/src/operation/distance/DistanceOp.cpp
@@ -528,6 +528,7 @@ DistanceOp::isWithinDistance(const geom::Geometry& g0,
                              double distance)
 {
     // check envelope distance for a short-circuit negative result
+    if ( g0.isEmpty() || g1.isEmpty() ) return false;
     const Envelope* env0 = g0.getEnvelopeInternal();
     const Envelope* env1 = g1.getEnvelopeInternal();
     double envDist = env0->distance(*env1);
diff --git a/tests/unit/capi/GEOSDistanceWithinTest.cpp b/tests/unit/capi/GEOSDistanceWithinTest.cpp
index 9469179..498cb53 100644
--- a/tests/unit/capi/GEOSDistanceWithinTest.cpp
+++ b/tests/unit/capi/GEOSDistanceWithinTest.cpp
@@ -6,6 +6,7 @@
 #include <geos/constants.h>
 #include <geos_c.h>
 // std
+#include <limits>
 #include <cstdarg>
 #include <cstdio>
 #include <cstdlib>
@@ -360,7 +361,7 @@ void object::test<26>() {
 }
 
 
-// empty geometries should always return true (distance 1)
+// empty geometries should return false (distance 1)
 template <>
 template <>
 void object::test<27>() {
@@ -368,11 +369,11 @@ void object::test<27>() {
       "POINT EMPTY",
       "LINESTRING EMPTY",
       1.0,
-      1
+      0
     );
 }
 
-// empty geometries should always return true (distance 0)
+// empty geometries should return false (distance 0)
 template <>
 template <>
 void object::test<28>() {
@@ -380,7 +381,43 @@ void object::test<28>() {
       "POINT EMPTY",
       "LINESTRING EMPTY",
       0.0,
-      1
+      0
+    );
+}
+
+// empty geometries should return false (distance Infinity)
+template <>
+template <>
+void object::test<29>() {
+  testGEOSDistanceWithin(
+      "POINT EMPTY",
+      "LINESTRING EMPTY",
+      std::numeric_limits<double>::infinity(),
+      0
+    );
+}
+
+// empty geometry is never within any distance
+template <>
+template <>
+void object::test<30>() {
+  testGEOSDistanceWithin(
+      "POINT EMPTY",
+      "LINESTRING(0 0, 20 0)",
+      std::numeric_limits<double>::infinity(),
+      0
+    );
+}
+
+// empty geometry is never within any distance
+template <>
+template <>
+void object::test<31>() {
+  testGEOSDistanceWithin(
+      "LINESTRING(0 0, 20 0)",
+      "POINT EMPTY",
+      std::numeric_limits<double>::infinity(),
+      0
     );
 }
 
diff --git a/tests/unit/capi/GEOSPreparedDistanceWithinTest.cpp b/tests/unit/capi/GEOSPreparedDistanceWithinTest.cpp
index 96a654c..32b0397 100644
--- a/tests/unit/capi/GEOSPreparedDistanceWithinTest.cpp
+++ b/tests/unit/capi/GEOSPreparedDistanceWithinTest.cpp
@@ -66,7 +66,7 @@ void object::test<1>
         "POLYGON EMPTY",
         "POLYGON EMPTY",
         std::numeric_limits<double>::infinity(),
-        1
+        0
     );
 }
 
@@ -145,7 +145,7 @@ void object::test<7>
         "LINESTRING EMPTY",
         "POINT EMPTY",
         std::numeric_limits<double>::infinity(),
-        1
+        0
     );
 }
 
@@ -158,7 +158,33 @@ void object::test<8>
         "POINT EMPTY",
         "LINESTRING EMPTY",
         std::numeric_limits<double>::infinity(),
-        1
+        0
+    );
+}
+
+template<>
+template<>
+void object::test<9>
+()
+{
+    checkDistanceWithin(
+        "POINT EMPTY",
+        "POINT(0 0)",
+        std::numeric_limits<double>::infinity(),
+        0
+    );
+}
+
+template<>
+template<>
+void object::test<10>
+()
+{
+    checkDistanceWithin(
+        "LINESTRING(0 0, 10 0)",
+        "POLYGON EMPTY",
+        std::numeric_limits<double>::infinity(),
+        0
     );
 }
 

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

Summary of changes:
 src/operation/distance/DistanceOp.cpp              |  1 +
 tests/unit/capi/GEOSDistanceWithinTest.cpp         | 45 ++++++++++++++++++++--
 tests/unit/capi/GEOSPreparedDistanceWithinTest.cpp | 32 +++++++++++++--
 3 files changed, 71 insertions(+), 7 deletions(-)


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list