[geos-commits] [SCM] GEOS branch master updated. 587049c216625a6444984e3e7293cd62dd494fb6

git at osgeo.org git at osgeo.org
Tue Feb 2 07:03:52 PST 2021


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  587049c216625a6444984e3e7293cd62dd494fb6 (commit)
      from  2d335df0c3ffccec58dcd71508c94ef76c836a46 (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 587049c216625a6444984e3e7293cd62dd494fb6
Author: Brendan C. Ward <bcward at astutespruce.com>
Date:   Mon Feb 1 14:19:19 2021 -0800

    Make sure that Polygon::compareToSameClass compares holes

diff --git a/include/geos/geom/Polygon.h b/include/geos/geom/Polygon.h
index 8d3712a..4b85e25 100644
--- a/include/geos/geom/Polygon.h
+++ b/include/geos/geom/Polygon.h
@@ -134,8 +134,6 @@ public:
 
     std::unique_ptr<Geometry> reverse() const override;
 
-    int compareToSameClass(const Geometry* p) const override; //was protected
-
     const Coordinate* getCoordinate() const override;
 
     double getArea() const override;
@@ -150,6 +148,8 @@ protected:
 
     Polygon(const Polygon& p);
 
+    int compareToSameClass(const Geometry* p) const override;
+
     /**
      * Constructs a <code>Polygon</code> with the given exterior
      * and interior boundaries.
diff --git a/src/geom/Polygon.cpp b/src/geom/Polygon.cpp
index 2acf1f2..708563a 100644
--- a/src/geom/Polygon.cpp
+++ b/src/geom/Polygon.cpp
@@ -329,7 +329,30 @@ int
 Polygon::compareToSameClass(const Geometry* g) const
 {
     const Polygon* p = dynamic_cast<const Polygon*>(g);
-    return shell->compareToSameClass(p->shell.get());
+    int shellComp = shell->compareToSameClass(p->shell.get());
+    if (shellComp != 0) {
+        return shellComp;
+    }
+
+    size_t nHole1 = getNumInteriorRing();
+    size_t nHole2 = p->getNumInteriorRing();
+    if (nHole1 < nHole2) {
+        return -1;
+    }
+    if (nHole1 > nHole2) {
+        return 1;
+    }
+
+    int holeComp = 0;
+    for (size_t i=0; i < nHole1; i++) {
+        const LinearRing *lr = p->getInteriorRingN(i);
+        holeComp = getInteriorRingN(i)->compareToSameClass(lr);
+        if (holeComp != 0) {
+            return holeComp;
+        }
+    }
+
+    return 0;
 }
 
 /*
diff --git a/tests/unit/geom/PolygonTest.cpp b/tests/unit/geom/PolygonTest.cpp
index cd62ae2..970aee2 100644
--- a/tests/unit/geom/PolygonTest.cpp
+++ b/tests/unit/geom/PolygonTest.cpp
@@ -611,4 +611,25 @@ void object::test<42>
     ensure(!poly_->isDimensionStrict(geos::geom::Dimension::L));
 }
 
+
+// test compareToSameClass for polygons including holes
+template<>
+template<>
+void object::test<43>
+()
+{
+    auto poly = reader_.read("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0), (1 1, 1 2, 2 2, 2 1, 1 1))");
+
+    ensure("polygon should equal self",
+        poly->compareTo(poly.get()) == 0);
+
+    auto poly2 = reader_.read("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0), (2 2, 2 3, 3 3, 3 2, 2 2))");
+    ensure("polygons with different holes but same shell are not equal",
+        poly->compareTo(poly2.get()) != 0);
+
+    auto poly3 = reader_.read("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))");
+    ensure("polygons with and without holes are not equal",
+        poly->compareTo(poly3.get()) != 0);
+}
+
 } // namespace tut

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

Summary of changes:
 include/geos/geom/Polygon.h     |  4 ++--
 src/geom/Polygon.cpp            | 25 ++++++++++++++++++++++++-
 tests/unit/geom/PolygonTest.cpp | 21 +++++++++++++++++++++
 3 files changed, 47 insertions(+), 3 deletions(-)


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list