[geos-commits] [SCM] GEOS branch master updated. c06450ef893f63319c360568b18726475b1e39c7
git at osgeo.org
git at osgeo.org
Mon Oct 19 03:20:19 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, master has been updated
via c06450ef893f63319c360568b18726475b1e39c7 (commit)
from 4f099194d449b987cf9349f65731fce89891152f (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 c06450ef893f63319c360568b18726475b1e39c7
Author: Joris Van den Bossche <jorisvandenbossche at gmail.com>
Date: Fri Oct 16 15:55:41 2020 +0200
BUG: Fix GEOSProjectNormalized return -1 on exception
diff --git a/capi/geos_ts_c.cpp b/capi/geos_ts_c.cpp
index 39f3dfc..c8abec2 100644
--- a/capi/geos_ts_c.cpp
+++ b/capi/geos_ts_c.cpp
@@ -3098,10 +3098,16 @@ extern "C" {
{
double length;
+ double distance;
if(GEOSLength_r(extHandle, g, &length) != 1) {
return -1.0;
};
- return GEOSProject_r(extHandle, g, p) / length;
+ 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 f8d4c8c..87a56b2 100644
--- a/tests/unit/Makefile.am
+++ b/tests/unit/Makefile.am
@@ -106,6 +106,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
-----------------------------------------------------------------------
Summary of changes:
capi/geos_ts_c.cpp | 8 ++-
tests/unit/Makefile.am | 1 +
tests/unit/capi/GEOSProjectTest.cpp | 111 ++++++++++++++++++++++++++++++++++++
3 files changed, 119 insertions(+), 1 deletion(-)
create mode 100644 tests/unit/capi/GEOSProjectTest.cpp
hooks/post-receive
--
GEOS
More information about the geos-commits
mailing list