[geos-commits] [SCM] GEOS branch main updated. 5f4af4116e39ec9f859d8a64adc74cd4f4ffb349

git at osgeo.org git at osgeo.org
Mon Aug 23 13:23:51 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  5f4af4116e39ec9f859d8a64adc74cd4f4ffb349 (commit)
      from  1d8950fec9ccb6bc80d74d9f3c1f760563c9a1ea (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 5f4af4116e39ec9f859d8a64adc74cd4f4ffb349
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date:   Mon Aug 23 13:23:47 2021 -0700

    When dealing with a zero-length linestring in GEOSProjectNormalized, do not return NaN as the projected length, but rather return 0.0 for the case where GEOSProject returns 0.0 and an error code otherwise to stop the divide-by-zero case. References https://github.com/libgeos/geos/issues/475

diff --git a/NEWS b/NEWS
index 05101c1..480b79a 100644
--- a/NEWS
+++ b/NEWS
@@ -24,6 +24,7 @@ Changes in 3.10.0
 - Changes:
   - #1094, #1090: Drop inlines.cpp to address duplicate symbols on many platforms
     (Regina Obe)
+  - GH475: Do not return NaN from GEOSProjectNormalized_r (Paul Ramsey)
 
 Changes in 3.9.0
 2020-12-09
diff --git a/capi/geos_ts_c.cpp b/capi/geos_ts_c.cpp
index 4416ae7..481d30f 100644
--- a/capi/geos_ts_c.cpp
+++ b/capi/geos_ts_c.cpp
@@ -3332,8 +3332,14 @@ extern "C" {
         if(GEOSLength_r(extHandle, g, &length) != 1) {
             return -1.0;
         };
+
         distance = GEOSProject_r(extHandle, g, p);
-        if (distance == -1.0) {
+
+        if (distance == 0.0 && length == 0.0)
+            return 0.0;
+
+        /* Meaningless projection? error */
+        if (distance < 0.0 || ! std::isfinite(distance) || length == 0.0) {
             return -1.0;
         } else {
             return distance / length;
diff --git a/tests/unit/capi/GEOSProjectTest.cpp b/tests/unit/capi/GEOSProjectTest.cpp
index 7f2077c..aae5186 100644
--- a/tests/unit/capi/GEOSProjectTest.cpp
+++ b/tests/unit/capi/GEOSProjectTest.cpp
@@ -78,4 +78,21 @@ void object::test<3>
     ensure_equals(dist_norm, -1.0);
 }
 
+// Test
+// https://github.com/libgeos/geos/issues/475
+template<>
+template<>
+void object::test<4>
+()
+{
+    geom1_ = GEOSGeomFromWKT("LINESTRING (0 0, 0 0)");
+    geom2_ = GEOSGeomFromWKT("POINT (0 0)");
+
+    double dist = GEOSProject(geom1_, geom2_);
+    ensure_equals(dist, 0.0);
+
+    double dist_norm = GEOSProjectNormalized(geom1_, geom2_);
+    ensure_equals(dist_norm, 0.0);
+}
+
 } // namespace tut

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

Summary of changes:
 NEWS                                |  1 +
 capi/geos_ts_c.cpp                  |  8 +++++++-
 tests/unit/capi/GEOSProjectTest.cpp | 17 +++++++++++++++++
 3 files changed, 25 insertions(+), 1 deletion(-)


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list