[geos-commits] [SCM] GEOS branch 3.8 updated. dca69c5135f5b1876cd6e2acafa4bac3b0a593ae

git at osgeo.org git at osgeo.org
Mon Oct 19 03:31:28 PDT 2020


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.8 has been updated
       via  dca69c5135f5b1876cd6e2acafa4bac3b0a593ae (commit)
       via  07611d4ac8cdba9ad662263bc62f34df4ef82a5b (commit)
       via  f60cd0c1c623012feca00ee8b287dd66d45dd2d6 (commit)
      from  bc5429f45fc16a6c39dba2d4b9bcb841d70d01ee (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 dca69c5135f5b1876cd6e2acafa4bac3b0a593ae
Author: Sandro Santilli <strk at kbt.io>
Date:   Mon Oct 19 12:31:20 2020 +0200

    Fix catch-by-value

diff --git a/tests/unit/operation/geounion/CoverageUnionTest.cpp b/tests/unit/operation/geounion/CoverageUnionTest.cpp
index 2fed702..fefe1e3 100644
--- a/tests/unit/operation/geounion/CoverageUnionTest.cpp
+++ b/tests/unit/operation/geounion/CoverageUnionTest.cpp
@@ -78,7 +78,7 @@ namespace tut {
         try {
             auto u1 = CoverageUnion::Union(coll.get());
             fail();
-        } catch(const geos::util::TopologyException e) {}
+        } catch(const geos::util::TopologyException&) {}
     }
 
     template<>

commit 07611d4ac8cdba9ad662263bc62f34df4ef82a5b
Author: Joris Van den Bossche <jorisvandenbossche at gmail.com>
Date:   Fri Oct 16 15:55:41 2020 +0200

    Fix GEOSProjectNormalized return -1 on exception
    
    Includes testcase and NEWS entry

diff --git a/NEWS b/NEWS
index f74067b..b029530 100644
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,7 @@ Changes in 3.8.2
   - Fix buffering problem (#1022, JTS-525, Paul Ramsey)
   - Fix segfault in GEOSInterpolate against empty eollections (#1055,
     Sandro Santilli)
+  - Fix GEOSProjectNormalized return -1 on exception (Joris Van den Bossche)
 
 
 Changes in 3.8.1
diff --git a/capi/geos_ts_c.cpp b/capi/geos_ts_c.cpp
index 31f2f1e..763be98 100644
--- a/capi/geos_ts_c.cpp
+++ b/capi/geos_ts_c.cpp
@@ -6265,10 +6265,17 @@ extern "C" {
     GEOSProjectNormalized_r(GEOSContextHandle_t extHandle, const Geometry* g,
                             const Geometry* p)
     {
-
         double length;
-        GEOSLength_r(extHandle, g, &length);
-        return GEOSProject_r(extHandle, g, p) / length;
+        double distance;
+        if(GEOSLength_r(extHandle, g, &length) != 1) {
+            return -1.0;
+        };
+        distance = GEOSProject_r(extHandle, g, p);
+        if (distance == -1.0) {
+            return -1.0;
+        } else {
+            return distance / length;
+        }
     }
 
 
diff --git a/tests/unit/Makefile.am b/tests/unit/Makefile.am
index 88c4816..45293f3 100644
--- a/tests/unit/Makefile.am
+++ b/tests/unit/Makefile.am
@@ -98,6 +98,7 @@ geos_unit_SOURCES = \
 	capi/GEOSPointOnSurfaceTest.cpp \
 	capi/GEOSPolygonizeTest.cpp \
 	capi/GEOSPreparedGeometryTest.cpp \
+	capi/GEOSProjectTest.cpp \
 	capi/GEOSRelateBoundaryNodeRuleTest.cpp \
 	capi/GEOSRelatePatternMatchTest.cpp \
 	capi/GEOSReverseTest.cpp \
diff --git a/tests/unit/capi/GEOSProjectTest.cpp b/tests/unit/capi/GEOSProjectTest.cpp
new file mode 100644
index 0000000..8a71566
--- /dev/null
+++ b/tests/unit/capi/GEOSProjectTest.cpp
@@ -0,0 +1,111 @@
+// Test Suite for C-API LineString project functions
+
+#include <tut/tut.hpp>
+// geos
+#include <geos_c.h>
+// std
+#include <cstdarg>
+#include <cstdio>
+#include <cstdlib>
+#include <cmath>
+
+namespace tut {
+//
+// Test Group
+//
+
+// Common data used in test cases.
+struct test_capiproject_data {
+    GEOSGeometry* geom1_;
+    GEOSGeometry* geom2_;
+
+    static void
+    notice(const char* fmt, ...)
+    {
+        std::fprintf(stdout, "NOTICE: ");
+
+        va_list ap;
+        va_start(ap, fmt);
+        std::vfprintf(stdout, fmt, ap);
+        va_end(ap);
+
+        std::fprintf(stdout, "\n");
+    }
+
+    test_capiproject_data()
+        : geom1_(nullptr), geom2_(nullptr)
+    {
+        initGEOS(notice, notice);
+    }
+
+    ~test_capiproject_data()
+    {
+        GEOSGeom_destroy(geom1_);
+        GEOSGeom_destroy(geom2_);
+        geom1_ = nullptr;
+        geom2_ = nullptr;
+        finishGEOS();
+    }
+
+};
+
+typedef test_group<test_capiproject_data> group;
+typedef group::object object;
+
+group test_capiproject_group("capi::GEOSProject");
+
+//
+// Test Cases
+//
+
+// Test basic usage
+template<>
+template<>
+void object::test<1>
+()
+{
+    geom1_ = GEOSGeomFromWKT("LINESTRING (0 0, 0 2)");
+    geom2_ = GEOSGeomFromWKT("POINT (1 1)");
+
+
+    double dist = GEOSProject(geom1_, geom2_);
+    ensure_equals(dist, 1.0);
+
+    double dist_norm = GEOSProjectNormalized(geom1_, geom2_);
+    ensure_equals(dist_norm, 0.5);
+}
+
+// Test non-linestring geometry (first argument) correctly returns -1.0
+template<>
+template<>
+void object::test<2>
+()
+{
+    geom1_ = GEOSGeomFromWKT("POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))");
+    geom2_ = GEOSGeomFromWKT("POINT (1 1)");
+
+    double dist = GEOSProject(geom1_, geom2_);
+    ensure_equals(dist, -1.0);
+
+    double dist_norm = GEOSProjectNormalized(geom1_, geom2_);
+    ensure_equals(dist_norm, -1.0);
+}
+
+// Test non-point geometry (second argument) correctly returns -1.0
+// https://trac.osgeo.org/geos/ticket/1058
+template<>
+template<>
+void object::test<3>
+()
+{
+    geom1_ = GEOSGeomFromWKT("LINESTRING (0 0, 0 2)");
+    geom2_ = GEOSGeomFromWKT("LINESTRING (0 0, 0 2)");
+
+    double dist = GEOSProject(geom1_, geom2_);
+    ensure_equals(dist, -1.0);
+
+    double dist_norm = GEOSProjectNormalized(geom1_, geom2_);
+    ensure_equals(dist_norm, -1.0);
+}
+
+} // namespace tut

commit f60cd0c1c623012feca00ee8b287dd66d45dd2d6
Author: Joris Van den Bossche <jorisvandenbossche at gmail.com>
Date:   Thu Oct 15 11:15:57 2020 +0200

    DOC: clarify that GEOSProject returns -1 on exception (C API)

diff --git a/capi/geos_c.h.in b/capi/geos_c.h.in
index 31da35e..cf66d6f 100644
--- a/capi/geos_c.h.in
+++ b/capi/geos_c.h.in
@@ -369,7 +369,8 @@ extern int GEOS_DLL GEOSCoordSeq_isCCW_r(GEOSContextHandle_t handle,
 
 
 /* Return distance of point 'p' projected on 'g' from origin
- * of 'g'. Geometry 'g' must be a lineal geometry */
+ * of 'g'. Geometry 'g' must be a lineal geometry.
+ * Return -1 on exception*/
 extern double GEOS_DLL GEOSProject_r(GEOSContextHandle_t handle,
                                      const GEOSGeometry *g,
                                      const GEOSGeometry *p);
@@ -1461,7 +1462,8 @@ extern int GEOS_DLL GEOSCoordSeq_isCCW(const GEOSCoordSequence* s, char* is_ccw)
 
 
 /* Return distance of point 'p' projected on 'g' from origin
- * of 'g'. Geometry 'g' must be a lineal geometry */
+ * of 'g'. Geometry 'g' must be a lineal geometry.
+ * Return -1 on exception */
 extern double GEOS_DLL GEOSProject(const GEOSGeometry *g,
                                    const GEOSGeometry* p);
 

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

Summary of changes:
 NEWS                                               |   1 +
 capi/geos_c.h.in                                   |   6 +-
 capi/geos_ts_c.cpp                                 |  13 ++-
 tests/unit/Makefile.am                             |   1 +
 tests/unit/capi/GEOSProjectTest.cpp                | 111 +++++++++++++++++++++
 .../unit/operation/geounion/CoverageUnionTest.cpp  |   2 +-
 6 files changed, 128 insertions(+), 6 deletions(-)
 create mode 100644 tests/unit/capi/GEOSProjectTest.cpp


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list