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

git at osgeo.org git at osgeo.org
Mon Oct 26 13:08:04 PDT 2026


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  a9752091be7ca35f0ffd94c37ef77530ff3dc194 (commit)
      from  283e82726fbd5ecc45397f182e12e056a65b2dd7 (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 a9752091be7ca35f0ffd94c37ef77530ff3dc194
Author: Jeroen Bloemscheer <jbloemscheer at gmail.com>
Date:   Mon Oct 26 21:07:40 2026 +0100

    Envelope: Return zero distance between touching envelopes (#1576)
    
    distanceSquared computed each gap as a combined span minus two widths,
    which cancels: envelopes touching along y = -48 came out 7e-15 apart, so
    GEOSDistanceWithin(a, b, 0) was false for lines sharing an endpoint.
    Compute each gap as a single difference between facing sides.

diff --git a/include/geos/geom/Envelope.h b/include/geos/geom/Envelope.h
index 15d360030..654edbc2f 100644
--- a/include/geos/geom/Envelope.h
+++ b/include/geos/geom/Envelope.h
@@ -742,12 +742,8 @@ public:
      */
     double distanceSquared(const Envelope& env) const
     {
-        double dx = std::max(0.0,
-            std::max(maxx, env.maxx) - std::min(minx, env.minx) - (maxx - minx) -
-            (env.maxx - env.minx));
-        double dy = std::max(0.0,
-            std::max(maxy, env.maxy) - std::min(miny, env.miny) - (maxy - miny) -
-            (env.maxy - env.miny));
+        double dx = std::max(0.0, std::max(minx - env.maxx, env.minx - maxx));
+        double dy = std::max(0.0, std::max(miny - env.maxy, env.miny - maxy));
 
         return dx * dx + dy * dy;
     };
diff --git a/tests/unit/capi/GEOSDistanceWithinTest.cpp b/tests/unit/capi/GEOSDistanceWithinTest.cpp
index 0b164d199..044598918 100644
--- a/tests/unit/capi/GEOSDistanceWithinTest.cpp
+++ b/tests/unit/capi/GEOSDistanceWithinTest.cpp
@@ -437,4 +437,18 @@ void object::test<33>()
 }
 
 
+
+template<>
+template<>
+void object::test<34>() {
+    set_test_name("lines touching at endpoint");
+
+    testGEOSDistanceWithin(
+        "LINESTRING (0 -80, 64 -48)",
+        "LINESTRING (64 -48, 0 -0.1)",
+        0.0,
+        1
+    );
+}
+
 } // namespace tut
diff --git a/tests/unit/geom/EnvelopeTest.cpp b/tests/unit/geom/EnvelopeTest.cpp
index a289438bd..f4f95ff84 100644
--- a/tests/unit/geom/EnvelopeTest.cpp
+++ b/tests/unit/geom/EnvelopeTest.cpp
@@ -692,4 +692,18 @@ void object::test<21>()
     ensure(env.containsProperly({3.0000001, 8}));
 }
 
+
+template<>
+template<>
+void object::test<22>()
+{
+    set_test_name("distance between touching envelopes is zero");
+
+    Envelope a(0, 64, -80, -48);
+    Envelope b(0, 64, -48, -0.1);
+
+    ensure_equals(a.distance(b), 0.0);
+    ensure_equals(b.distance(a), 0.0);
+}
+
 }

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

Summary of changes:
 include/geos/geom/Envelope.h               |  8 ++------
 tests/unit/capi/GEOSDistanceWithinTest.cpp | 14 ++++++++++++++
 tests/unit/geom/EnvelopeTest.cpp           | 14 ++++++++++++++
 3 files changed, 30 insertions(+), 6 deletions(-)


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list