[geos-commits] [SCM] GEOS branch 3.7 updated. 1d587ff39d7653d08f0c3327474de9085463d1b5

git at osgeo.org git at osgeo.org
Wed May 31 06:30:37 PDT 2023


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.7 has been updated
       via  1d587ff39d7653d08f0c3327474de9085463d1b5 (commit)
      from  0935e18ea216cc641213314c5dab93f7a340fbf2 (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 1d587ff39d7653d08f0c3327474de9085463d1b5
Author: Mike Taves <mwtoews at gmail.com>
Date:   Wed May 31 10:50:50 2023 +1200

    GEOSClipByRect: Fix case with POINT EMPTY, add more tests (#913)

diff --git a/NEWS b/NEWS
index a85a9db9d..ad4be5f13 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,9 @@
+Changes in 3.7.6
+20xx-xx-xx
+
+- Bug fixes / improvements
+  - GEOSClipByRect: Fix case with POINT EMPTY (GH-913, Mike Taves)
+
 Changes in 3.7.5
 2022-06-08
 
diff --git a/src/operation/intersection/RectangleIntersection.cpp b/src/operation/intersection/RectangleIntersection.cpp
index 04f5615bc..e91561881 100644
--- a/src/operation/intersection/RectangleIntersection.cpp
+++ b/src/operation/intersection/RectangleIntersection.cpp
@@ -109,7 +109,7 @@ RectangleIntersection::clip_point(const geom::Point * g,
 				RectangleIntersectionBuilder & parts,
 				const Rectangle & rect)
 {
-  if(g == nullptr)
+  if(g == nullptr || g->isEmpty())
 	return;
 
   double x = g->getX();
@@ -552,6 +552,9 @@ RectangleIntersection::clip_polygon(const geom::Polygon * g,
 				  const Rectangle & rect,
 				  bool keep_polygons)
 {
+  if(g == nullptr || g->isEmpty())
+	return;
+
   if(keep_polygons)
 	clip_polygon_to_polygons(g, parts, rect);
   else
diff --git a/tests/unit/capi/GEOSClipByRectTest.cpp b/tests/unit/capi/GEOSClipByRectTest.cpp
index b0eb02fac..cc6fc5b03 100644
--- a/tests/unit/capi/GEOSClipByRectTest.cpp
+++ b/tests/unit/capi/GEOSClipByRectTest.cpp
@@ -187,5 +187,31 @@ namespace tut
     isEqual(geom2_, "POLYGON ((5 5, 5 15, 10 15, 10 10, 15 10, 15 5, 5 5))");
   }
 
+  // Empty combinations - always return GEOMETRYCOLLECTION EMPTY
+  template<> template<> void object::test<14>
+  ()
+  {
+    std::vector<const char*> variants{
+      "POINT EMPTY",
+      "LINESTRING EMPTY",
+      "POLYGON EMPTY",
+      "MULTIPOINT EMPTY",
+      "MULTILINESTRING EMPTY",
+      "MULTIPOLYGON EMPTY",
+      "GEOMETRYCOLLECTION EMPTY",
+      "LINEARRING EMPTY",
+    };
+    for (const auto& wkt : variants) {
+      GEOSGeom geom1 = GEOSGeomFromWKT(wkt);
+      GEOSGeom geom2 = GEOSClipByRect(geom1, 0, 0, 1, 1);
+      char* obt_wkt = GEOSWKTWriter_write(w_, geom2);
+      std::string obt_wkt2(obt_wkt);
+      GEOSFree(obt_wkt);
+      GEOSGeom_destroy(geom1);
+      GEOSGeom_destroy(geom2);
+      ensure_equals(obt_wkt2, "GEOMETRYCOLLECTION EMPTY");
+  }
+}
+
 } // namespace tut
 
diff --git a/tests/unit/operation/intersection/RectangleIntersectionTest.cpp b/tests/unit/operation/intersection/RectangleIntersectionTest.cpp
index 89c60ed89..dbfc5d7f6 100644
--- a/tests/unit/operation/intersection/RectangleIntersectionTest.cpp
+++ b/tests/unit/operation/intersection/RectangleIntersectionTest.cpp
@@ -1528,4 +1528,27 @@ namespace tut
 
       doClipTest(inp, exp, r, 1e-20);
     }
+
+    // Empty combinations - always return GEOMETRYCOLLECTION EMPTY
+    template<> template<> void object::test<209>()
+    {
+      std::vector<const char*> variants{
+        "POINT EMPTY",
+        "LINESTRING EMPTY",
+        "POLYGON EMPTY",
+        "MULTIPOINT EMPTY",
+        "MULTILINESTRING EMPTY",
+        "MULTIPOLYGON EMPTY",
+        "GEOMETRYCOLLECTION EMPTY",
+        "LINEARRING EMPTY",
+      };
+      for (const auto& inp : variants) {
+        doClipTest(
+          inp,
+          "GEOMETRYCOLLECTION EMPTY",
+          Rectangle(0, 0, 1, 1)
+        );
+      }
+    }
+
 }

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

Summary of changes:
 NEWS                                               |  6 +++++
 .../intersection/RectangleIntersection.cpp         |  5 ++++-
 tests/unit/capi/GEOSClipByRectTest.cpp             | 26 ++++++++++++++++++++++
 .../intersection/RectangleIntersectionTest.cpp     | 23 +++++++++++++++++++
 4 files changed, 59 insertions(+), 1 deletion(-)


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list