[geos-commits] [SCM] GEOS branch main updated. f997d40cdd1b9b4a123eae27ed2a4f1061dac329

git at osgeo.org git at osgeo.org
Tue Jan 7 15:04:09 PST 2025


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  f997d40cdd1b9b4a123eae27ed2a4f1061dac329 (commit)
      from  e1c9a7c5c6819383bb57fb15a000cdb06dd47600 (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 f997d40cdd1b9b4a123eae27ed2a4f1061dac329
Author: Martin Davis <mtnclimb at gmail.com>
Date:   Tue Jan 7 15:03:43 2025 -0800

    Improve OffsetCurve to handle mitre joins for polygons

diff --git a/include/geos/operation/buffer/OffsetCurve.h b/include/geos/operation/buffer/OffsetCurve.h
index 3b218aa4a..a6fd79c03 100644
--- a/include/geos/operation/buffer/OffsetCurve.h
+++ b/include/geos/operation/buffer/OffsetCurve.h
@@ -101,6 +101,9 @@ private:
 
     // Methods
 
+    std::unique_ptr<Geometry> computePolygonCurve(
+        const Polygon& polyGeom, double distance);
+
     std::unique_ptr<Geometry> computeCurve(
         const LineString& lineGeom, double distance);
 
diff --git a/src/operation/buffer/OffsetCurve.cpp b/src/operation/buffer/OffsetCurve.cpp
index f524ccdc1..09fc7d074 100644
--- a/src/operation/buffer/OffsetCurve.cpp
+++ b/src/operation/buffer/OffsetCurve.cpp
@@ -66,15 +66,7 @@ OffsetCurve::getCurve()
 
         if (geom.getGeometryTypeId() == GEOS_POINT) return nullptr;
         if (geom.getGeometryTypeId() == GEOS_POLYGON) {
-            auto boundary = geom.buffer(distance)->getBoundary();
-
-            if (boundary->getGeometryTypeId() == GEOS_LINEARRING) {
-                const LinearRing& ring = static_cast<const LinearRing&>(geom);
-                auto ringCs = ring.getCoordinatesRO();
-                std::unique_ptr<Geometry> ls(geom.getFactory()->createLineString(*ringCs));
-                return ls;
-            }
-            return boundary;
+            return computePolygonCurve(static_cast<const Polygon&>(geom), distance);
         }
         return computeCurve(static_cast<const LineString&>(geom), distance);
     };
@@ -141,6 +133,22 @@ OffsetCurve::rawOffset(const LineString& line, double dist)
     return rawOffsetCurve(line, dist, bufParams);
 }
 
+/* private */
+std::unique_ptr<Geometry>
+OffsetCurve::computePolygonCurve(const Polygon& polyGeom, double dist)
+{
+    auto buffer = BufferOp::bufferOp(&polyGeom, dist, bufferParams);
+    std::unique_ptr<Geometry> boundary = buffer->getBoundary();
+    //-- convert LinearRing to LineString if needed
+    if (boundary->getGeometryTypeId() == GEOS_LINEARRING) {
+        const LinearRing& ring = static_cast<LinearRing&>(*boundary);
+        auto ringCs = ring.getCoordinatesRO();
+        std::unique_ptr<Geometry> ls(polyGeom.getFactory()->createLineString(*ringCs));
+        return ls;
+    }
+    return boundary;
+}
+
 /* private */
 std::unique_ptr<Geometry>
 OffsetCurve::computeCurve(const LineString& lineGeom, double dist)
diff --git a/tests/unit/operation/buffer/OffsetCurveTest.cpp b/tests/unit/operation/buffer/OffsetCurveTest.cpp
index 76b01c4df..e845a51f4 100644
--- a/tests/unit/operation/buffer/OffsetCurveTest.cpp
+++ b/tests/unit/operation/buffer/OffsetCurveTest.cpp
@@ -588,6 +588,23 @@ void object::test<43> ()
     );
 }
 
-
+// testPolygonJoinMitre
+template<>
+template<>
+void object::test<44> ()
+{
+    checkOffsetCurve(
+        "POLYGON ((1 1, 1 7, 5 4, 8 8, 8 1, 1 1))",
+        1, 0, BufferParameters::JOIN_MITRE, 5,
+        "LINESTRING (0 0, 0 9, 4.8 5.4, 9 11, 9 0, 0 0)",
+        0.0001
+    );
+    checkOffsetCurve(
+        "POLYGON ((1 1, 1 7, 5 4, 8 8, 8 1, 1 1))",
+        -1, 0, BufferParameters::JOIN_MITRE, 5,
+        "LINESTRING (2 2, 2 5, 5.2 2.6, 7 5, 7 2, 2 2)",
+        0.0001
+    );
+}
 
 } // namespace tut2

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

Summary of changes:
 include/geos/operation/buffer/OffsetCurve.h     |  3 +++
 src/operation/buffer/OffsetCurve.cpp            | 26 ++++++++++++++++---------
 tests/unit/operation/buffer/OffsetCurveTest.cpp | 19 +++++++++++++++++-
 3 files changed, 38 insertions(+), 10 deletions(-)


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list