[geos-commits] [SCM] GEOS branch master updated. 862ed68db6977aceb5767fd92748ecc6c06e3ad2

git at osgeo.org git at osgeo.org
Mon Nov 16 06:12:53 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  862ed68db6977aceb5767fd92748ecc6c06e3ad2 (commit)
      from  d66382ff8150a468a2f376da5ebb74c8cabdc437 (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 862ed68db6977aceb5767fd92748ecc6c06e3ad2
Author: Sandro Santilli <strk at kbt.io>
Date:   Mon Nov 16 15:10:38 2020 +0100

    Add OverlayNG Z tests
    
    Porting commit 0524f550f76e32fb0c2f1badc3775d67a9fa9189 from JTS

diff --git a/tests/unit/operation/overlayng/OverlayNGZTest.cpp b/tests/unit/operation/overlayng/OverlayNGZTest.cpp
index 6ee56af..8ac55b4 100644
--- a/tests/unit/operation/overlayng/OverlayNGZTest.cpp
+++ b/tests/unit/operation/overlayng/OverlayNGZTest.cpp
@@ -1,5 +1,11 @@
 //
 // Test Suite for handling of Z in geos::operation::overlayng::OverlayNG class.
+//
+//
+// Ported from JTS
+// modules/core/src/test/java/org/locationtech/jts/operation/overlayng/OverlyNGZTest.java
+// 0524f550f76e32fb0c2f1badc3775d67a9fa9189
+//
 
 #include <tut/tut.hpp>
 #include <utility.h>
@@ -24,13 +30,23 @@ struct test_overlayngz_data {
 
     WKTReader r;
 
-    void checkIntersection(const std::string& wktA, const std::string& wktB, const std::string& wktExpected)
+    void checkOverlay(int opCode, const std::string& wktA, const std::string& wktB, const std::string& wktExpected)
     {
         std::unique_ptr<Geometry> a = r.read(wktA);
         std::unique_ptr<Geometry> b = r.read(wktB);
         std::unique_ptr<Geometry> expected = r.read(wktExpected);
-        std::unique_ptr<Geometry> result = OverlayNG::overlay(a.get(), b.get(), OverlayNG::INTERSECTION);
-        ensure_equals_geometry(expected.get(), result.get());
+        std::unique_ptr<Geometry> result = OverlayNG::overlay(a.get(), b.get(), opCode);
+        ensure_equals_geometry_xyz(expected.get(), result.get());
+    }
+
+    void checkIntersection(const std::string& wktA, const std::string& wktB, const std::string& wktExpected)
+    {
+        checkOverlay(OverlayNG::INTERSECTION, wktA, wktB, wktExpected);
+    }
+
+    void checkDifference(const std::string& wktA, const std::string& wktB, const std::string& wktExpected)
+    {
+        checkOverlay(OverlayNG::DIFFERENCE, wktA, wktB, wktExpected);
     }
 
 };
@@ -44,7 +60,7 @@ group test_overlayngz_group("geos::operation::overlayng::OverlayNGZ");
 // Test Cases
 //
 
-// testLineIntersectionInterpolated
+// testLineIntersectionPointInterpolated
 template<>
 template<>
 void object::test<1> ()
@@ -52,5 +68,29 @@ void object::test<1> ()
     checkIntersection("LINESTRING (0 0 0, 10 10 10)", "LINESTRING (10 0 0, 0 10 10)", "POINT(5 5 5)");
 }
 
+// testLineIntersectionPoint
+template<>
+template<>
+void object::test<2> ()
+{
+    checkIntersection(
+        "LINESTRING (0 0 0, 10 10 10)",
+        "LINESTRING (10 0 0, 5 5 999, 0 10 10)",
+        "POINT(5 5 999)"
+    );
+}
+
+//  testLineDifferenceLineInterpolated
+template<>
+template<>
+void object::test<3> ()
+{
+    checkDifference(
+        "LINESTRING (0 0 0, 10 10 10)",
+        "LINESTRING (5 5, 6 6)",
+        "MULTILINESTRING ((0 0 0, 5 5 5), (6 6 6, 10 10 10))"
+    );
+}
+
 
 } // namespace tut
diff --git a/tests/unit/utility.h b/tests/unit/utility.h
index c3da601..a24c126 100644
--- a/tests/unit/utility.h
+++ b/tests/unit/utility.h
@@ -235,6 +235,98 @@ ensure_equals_geometry(geos::geom::Geometry const* lhs,
     ensure_equals_geometry(lhs, &pg);
 }
 
+template <typename T>
+inline void
+ensure_equals_dims(T const *, T const *,
+                   unsigned int dims,
+                   double tolerance = 0.0);
+
+template <>
+inline void
+ensure_equals_dims(const geos::geom::CoordinateSequence *seq1,
+                   const geos::geom::CoordinateSequence *seq2,
+                   unsigned int dims, double tolerance)
+{
+    assert(nullptr != seq1);
+    assert(nullptr != seq2);
+
+    ensure_equals (seq1->size(), seq2->size());
+
+    ensure( seq1->getDimension() >= dims );
+    ensure( seq2->getDimension() >= dims );
+
+    for (unsigned int i = 0; i < seq1->size(); i++) {
+      for (unsigned int j = 0; j < dims; j++) {
+        double val1 = seq1->getOrdinate(i, j);
+        double val2 = seq2->getOrdinate(i, j);
+        if ( std::isnan(val1) )
+        {
+            ensure( std::isnan(val2) );
+        }
+        else
+        {
+            if ( tolerance )
+                ensure_distance( val1, val2, tolerance );
+            else
+                ensure_equals( val1, val2 );
+        }
+      }
+    }
+}
+
+template <typename T> inline void ensure_equals_exact_geometry_xyz(const T *lhs_in, const T *rhs_in, double tolerance = 0.0);
+
+template <>
+inline void
+ensure_equals_exact_geometry_xyz(const geos::geom::Geometry *lhs_in,
+                                 const geos::geom::Geometry *rhs_in,
+                                 double tolerance)
+{
+    assert(nullptr != lhs_in);
+    assert(nullptr != rhs_in);
+
+    using geos::geom::Point;
+    using geos::geom::LineString;
+    using geos::geom::Polygon;
+    using geos::geom::CoordinateSequence;
+    using geos::geom::GeometryCollection;
+
+    ensure_equals("type id do not match",
+                  lhs_in->getGeometryTypeId(), rhs_in->getGeometryTypeId());
+
+
+    if (const Point* g = dynamic_cast<const Point *>(lhs_in)) {
+      const Point *g2 = static_cast<const Point *>(rhs_in);
+      return ensure_equals_dims( g->getCoordinatesRO(), g2->getCoordinatesRO(), 3, tolerance);
+    }
+    else if (const LineString* g = dynamic_cast<const LineString *>(lhs_in)) {
+      const LineString *g2 = static_cast<const LineString *>(rhs_in);
+      return ensure_equals_dims( g->getCoordinatesRO(), g2->getCoordinatesRO(), 3, tolerance);
+    }
+    else if (dynamic_cast<const Polygon *>(lhs_in)) {
+      assert("Not implemented yet" == 0);
+    }
+    else if (const GeometryCollection* g = dynamic_cast<const GeometryCollection *>(lhs_in)) {
+      const GeometryCollection *g2 = static_cast<const GeometryCollection *>(rhs_in);
+      for (unsigned int i = 0; i < g->getNumGeometries(); i++) {
+        ensure_equals_exact_geometry_xyz(g->getGeometryN(i), g2->getGeometryN(i), tolerance);
+      }
+    }
+}
+
+template <typename T>
+inline void
+ensure_equals_geometry_xyz(const T *lhs_in,
+                           const T *rhs_in,
+                           double tolerance=0.0)
+{
+    std::unique_ptr<geos::geom::Geometry> g1 = lhs_in->clone();
+    g1->normalize();
+    std::unique_ptr<geos::geom::Geometry> g2 = rhs_in->clone();
+    g2->normalize();
+    ensure_equals_exact_geometry_xyz(g1.get(), g2.get(), tolerance);
+}
+
 //
 // Utility functions
 //

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

Summary of changes:
 tests/unit/operation/overlayng/OverlayNGZTest.cpp | 48 +++++++++++-
 tests/unit/utility.h                              | 92 +++++++++++++++++++++++
 2 files changed, 136 insertions(+), 4 deletions(-)


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list