[geos-commits] [SCM] GEOS branch master updated. 2d95d1a35053cfd602eaa22248d69a196ef71ccf

git at osgeo.org git at osgeo.org
Sat Dec 19 18:58:47 PST 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  2d95d1a35053cfd602eaa22248d69a196ef71ccf (commit)
       via  a69e00fafb87bac57341d92d3dbaf893517e08f2 (commit)
      from  e8e20974f41963e4653fc6f20ac2e8ed0392f623 (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 2d95d1a35053cfd602eaa22248d69a196ef71ccf
Merge: a69e00f e8e2097
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date:   Sat Dec 19 18:58:43 2020 -0800

    Merge branch 'master' of https://git.osgeo.org/gitea/geos/geos


commit a69e00fafb87bac57341d92d3dbaf893517e08f2
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date:   Sat Dec 19 17:54:11 2020 -0800

    Clean up Win32 memory issue, references #1050

diff --git a/capi/geos_ts_c.cpp b/capi/geos_ts_c.cpp
index c823bfe..6962521 100644
--- a/capi/geos_ts_c.cpp
+++ b/capi/geos_ts_c.cpp
@@ -2403,22 +2403,31 @@ extern "C" {
         //assert(0 != holes);
 
         return execute(extHandle, [&]() {
-            auto vholes = geos::detail::make_unique<std::vector<LinearRing*>>(nholes);
 
-            for (std::size_t i = 0; i < nholes; i++) {
-                (*vholes)[i] = dynamic_cast<LinearRing*>(holes[i]);
-                if ((*vholes)[i] == nullptr) {
+            std::vector<LinearRing*> tmpholes(nholes);
+            for (size_t i = 0; i < nholes; i++) {
+                LinearRing* lr = dynamic_cast<LinearRing*>(holes[i]);
+                if (! lr) {
                     throw IllegalArgumentException("Hole is not a LinearRing");
                 }
+                tmpholes[i] = lr;
             }
-
             LinearRing* nshell = dynamic_cast<LinearRing*>(shell);
             if(! nshell) {
                 throw IllegalArgumentException("Shell is not a LinearRing");
             }
-            const GeometryFactory* gf = shell->getFactory();
+            GEOSContextHandleInternal_t* handle = reinterpret_cast<GEOSContextHandleInternal_t*>(extHandle);
+            const GeometryFactory* gf = handle->geomFactory;
+
+            /* Create unique_ptr version for constructor */
+            std::vector<std::unique_ptr<LinearRing>> vholes;
+            vholes.reserve(nholes);
+            for (LinearRing* lr: tmpholes) {
+                vholes.emplace_back(lr);
+            }
+            std::unique_ptr<LinearRing> shell(nshell);
 
-            return gf->createPolygon(nshell, vholes.release());
+            return gf->createPolygon(std::move(shell), std::move(vholes)).release();
         });
     }
 
diff --git a/tests/unit/Makefile.am b/tests/unit/Makefile.am
index 2bbd681..4aaffe2 100644
--- a/tests/unit/Makefile.am
+++ b/tests/unit/Makefile.am
@@ -78,6 +78,8 @@ geos_unit_SOURCES = \
 	capi/GEOSEqualsTest.cpp \
 	capi/GEOSFrechetDistanceTest.cpp \
 	capi/GEOSGeom_createCollectionTest.cpp \
+	capi/GEOSGeom_createPolygonTest.cpp \
+	capi/GEOSGeom_createLineStringTest.cpp \
 	capi/GEOSGeom_createTest.cpp \
 	capi/GEOSGeom_extentTest.cpp \
 	capi/GEOSGeom_extractUniquePointsTest.cpp \
diff --git a/tests/unit/capi/GEOSGeom_createPolygonTest.cpp b/tests/unit/capi/GEOSGeom_createPolygonTest.cpp
new file mode 100644
index 0000000..b560975
--- /dev/null
+++ b/tests/unit/capi/GEOSGeom_createPolygonTest.cpp
@@ -0,0 +1,54 @@
+#include <tut/tut.hpp>
+#include "capi_test_utils.h"
+
+namespace tut {
+//
+// Test Group
+//
+
+struct test_geosgeom_createpolygon_data : public capitest::utility {};
+
+typedef test_group<test_geosgeom_createpolygon_data> group;
+typedef group::object object;
+
+group test_geosgeom_createpolygon("capi::GEOSGeom_createPolygon");
+
+template<>
+template<>
+void object::test<1>
+()
+{
+    GEOSCoordSequence* shell_seq = GEOSCoordSeq_create(5, 2);
+    GEOSCoordSequence* hole_seq = GEOSCoordSeq_create(5, 2);
+
+    double shell_coords[] = {0,0, 0,10, 10,10, 10,0, 0,0};
+    double hole_coords[] = {5,5, 5,6, 6,6, 6,5, 5,5};
+    for (int i = 0; i < 5; i++) {
+        GEOSCoordSeq_setXY(shell_seq, i, shell_coords[2*i], shell_coords[2*i+1]);
+        GEOSCoordSeq_setXY(hole_seq, i, hole_coords[2*i], hole_coords[2*i+1]);
+    }
+
+    GEOSGeometry* shell = GEOSGeom_createLinearRing(shell_seq);
+    GEOSGeometry* hole = GEOSGeom_createLinearRing(hole_seq);
+    GEOSGeometry** holes = (GEOSGeometry**)malloc(sizeof(GEOSGeometry *));
+    holes[0] = hole;
+
+    GEOSGeometry* polygon = GEOSGeom_createPolygon(shell, holes, 1);
+    GEOSGeometry* expected = GEOSGeomFromWKT("POLYGON((0 0, 0 10, 10 10, 10 0, 0 0),(5 5, 5 6, 6 6, 6 5, 5 5))");
+
+    // GEOSWKTWriter* w = GEOSWKTWriter_create();
+    // printf("%s\n", GEOSWKTWriter_write(w, polygon));
+    // printf("%s\n", GEOSWKTWriter_write(w, expected));
+
+    ensure_equals(GEOSEqualsExact(polygon, expected, 0), 1);
+
+    GEOSGeom_destroy(polygon);
+    GEOSGeom_destroy(expected);
+    // WARNING! The GEOSGeom_createPolygon takes ownership of the
+    // GEOSGeometry, but not the containing array!
+    // maybe this should be changed...
+    free(holes);
+}
+
+} // namespace tut
+

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

Summary of changes:
 capi/geos_ts_c.cpp                             | 23 +++++++----
 tests/unit/Makefile.am                         |  2 +
 tests/unit/capi/GEOSGeom_createPolygonTest.cpp | 54 ++++++++++++++++++++++++++
 3 files changed, 72 insertions(+), 7 deletions(-)
 create mode 100644 tests/unit/capi/GEOSGeom_createPolygonTest.cpp


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list