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

git at osgeo.org git at osgeo.org
Mon Apr 24 11:53:54 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, main has been updated
       via  fb8c78acbf351ac1e124d2a872f997c9d4851a0c (commit)
      from  5211fea4b9abec25a9b61437e8dee74dfdc49012 (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 fb8c78acbf351ac1e124d2a872f997c9d4851a0c
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date:   Mon Apr 24 11:53:11 2023 -0700

    Add some CAPI tests for the Coverage functionality.

diff --git a/capi/geos_c.h.in b/capi/geos_c.h.in
index 2179a4f2a..c68b2ff5e 100644
--- a/capi/geos_c.h.in
+++ b/capi/geos_c.h.in
@@ -3771,7 +3771,7 @@ extern GEOSGeometry GEOS_DLL *GEOSCoverageUnion(const GEOSGeometry *g);
 *
 * \since 3.12
 */
-extern int GEOSCoverageIsValid(
+extern int GEOS_DLL GEOSCoverageIsValid(
     const GEOSGeometry* input,
     double gapWidth,
     GEOSGeometry** invalidEdges);
diff --git a/capi/geos_ts_c.cpp b/capi/geos_ts_c.cpp
index fdf987f2f..e166e112a 100644
--- a/capi/geos_ts_c.cpp
+++ b/capi/geos_ts_c.cpp
@@ -2456,7 +2456,6 @@ extern "C" {
         return execute(extHandle, [&]() {
             std::ptrdiff_t stride = 2 + hasZ + hasM;
             auto coords = geos::detail::make_unique<CoordinateSequence>(size, hasZ, hasM, false);
-
             if (hasZ) {
                 if (hasM) {
                     // XYZM
@@ -4091,12 +4090,12 @@ extern "C" {
             std::vector<std::unique_ptr<Geometry>> invalid = cov.validate();
             bool hasInvalid = CoverageValidator::hasInvalidResult(invalid);
 
-            if (invalidEdges && hasInvalid) {
+            if (invalidEdges) {
                 const GeometryFactory* gf = input->getFactory();
                 for (auto& g : invalid) {
                     // Replace nullptr with 'MULTILINESTRING EMPTY'
                     if (g == nullptr) {
-                        auto empty = gf->createEmpty(GEOS_MULTILINESTRING);
+                        auto empty = gf->createEmpty(1);
                         g.reset(empty.release());
                     }
                 }
diff --git a/tests/unit/capi/GEOSCoverageIsValidTest.cpp b/tests/unit/capi/GEOSCoverageIsValidTest.cpp
new file mode 100644
index 000000000..79d54d88a
--- /dev/null
+++ b/tests/unit/capi/GEOSCoverageIsValidTest.cpp
@@ -0,0 +1,93 @@
+//
+// Test Suite for C-API GEOSCoverageIsValid
+
+#include <tut/tut.hpp>
+// geos
+#include <geos_c.h>
+// std
+#include <cstdarg>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+
+#include "capi_test_utils.h"
+
+namespace tut {
+//
+// Test Group
+//
+
+// Common data used in test cases.
+struct test_capicoverageisvalid_data : public capitest::utility {
+
+    test_capicoverageisvalid_data() {
+    }
+
+    ~test_capicoverageisvalid_data() {
+    }
+
+};
+
+
+typedef test_group<test_capicoverageisvalid_data> group;
+typedef group::object object;
+
+group test_capicoverageisvalid_group("capi::GEOSCoverageIsValid");
+
+//
+// Test Cases
+//
+
+// GEOSCoverageIsValid - all
+template<>
+template<> void object::test<1>
+()
+{
+    const char* inputWKT = "GEOMETRYCOLLECTION(POLYGON ((100 100, 200 200, 300 100, 200 101, 100 100)), POLYGON ((150 0, 100 100, 200 101, 300 100, 250 0, 150 0)))";
+    int allValid;
+
+    input_ = fromWKT(inputWKT);
+    allValid = GEOSCoverageIsValid(input_, 0.1, &result_);
+
+    ensure( "valid check is true", allValid > 0 );
+    ensure( "result is not null", result_ != nullptr );
+    ensure( "type is geometrycollection", GEOSGeomTypeId(result_) == GEOS_GEOMETRYCOLLECTION );
+
+    const char* expectedWKT = "GEOMETRYCOLLECTION(LINESTRING EMPTY, LINESTRING EMPTY)";
+
+    expected_ = fromWKT(expectedWKT);
+
+    // std::cout << toWKT(result_) << std::endl;
+    // std::cout << toWKT(expected_) << std::endl;
+
+    ensure_geometry_equals(result_, expected_, 0.01);
+}
+
+// GEOSCoverageIsValid - invalid
+template<>
+template<> void object::test<2>
+()
+{
+    const char* inputWKT = "GEOMETRYCOLLECTION(POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)), POLYGON ((1 0, 2 0, 2 1, 1 0.9, 1 0)))";
+    int allValid;
+
+    input_ = fromWKT(inputWKT);
+    allValid = GEOSCoverageIsValid(input_, 0.1, &result_);
+
+    ensure( "valid check is false", allValid == 0 );
+    ensure( "result is not null", result_ != nullptr );
+    ensure( "type is geometrycollection", GEOSGeomTypeId(result_) == GEOS_GEOMETRYCOLLECTION );
+
+    const char* expectedWKT = "GEOMETRYCOLLECTION (LINESTRING (1 0, 1 1), LINESTRING (2 1, 1 0.9, 1 0))";
+
+    expected_ = fromWKT(expectedWKT);
+
+    // std::cout << toWKT(result_) << std::endl;
+    // std::cout << toWKT(expected_) << std::endl;
+
+    ensure_geometry_equals(result_, expected_, 0.01);
+}
+
+
+
+} // namespace tut
diff --git a/tests/unit/capi/GEOSCoverageSimplifyTest.cpp b/tests/unit/capi/GEOSCoverageSimplifyTest.cpp
index 18c65bd9b..830a58c47 100644
--- a/tests/unit/capi/GEOSCoverageSimplifyTest.cpp
+++ b/tests/unit/capi/GEOSCoverageSimplifyTest.cpp
@@ -81,5 +81,25 @@ template<> void object::test<2>
 }
 
 
+// GEOSCoverageSimplifyVW
+template<>
+template<> void object::test<3>
+()
+{
+    const char* inputWKT = "GEOMETRYCOLLECTION(POLYGON(( 0 0,10 0,10.1 5,10 10,0 10,0 0)),POLYGON((10 0,20 0,20 10,10 10,10.1 5,10 0)))";
+
+    input_ = fromWKT(inputWKT);
+    result_ = GEOSCoverageSimplifyVW(input_, 1.0, 0);
+
+    ensure( result_ != nullptr );
+    ensure( GEOSGeomTypeId(result_) == GEOS_GEOMETRYCOLLECTION );
+
+    const char* expectedWKT = "GEOMETRYCOLLECTION(POLYGON((0 0,10 0,10 10,0 10,0 0)),POLYGON((10 0,20 0,20 10,10 10,10 0)))";
+
+    expected_ = fromWKT(expectedWKT);
+    ensure_geometry_equals(result_, expected_, 0.1);
+}
+
+
 
 } // namespace tut
diff --git a/tests/unit/coverage/CoverageSimplifierTest.cpp b/tests/unit/coverage/CoverageSimplifierTest.cpp
index 3d4c6f92f..64e4a1a01 100644
--- a/tests/unit/coverage/CoverageSimplifierTest.cpp
+++ b/tests/unit/coverage/CoverageSimplifierTest.cpp
@@ -367,7 +367,21 @@ void object::test<19> ()
 
 }
 
-
+//---------------------------------
+// all inputs empty
+// template<>
+// template<>
+// void object::test<20> ()
+// {
+//     checkResult(readArray({
+//             "POLYGON EMPTY",
+//             "POLYGON EMPTY" }),
+//         1.5,
+//         readArray({
+//             "POLYGON EMPTY",
+//             "POLYGON EMPTY" })
+//     );
+// }
 
 
 } // namespace tut
diff --git a/tests/unit/coverage/CoverageValidatorTest.cpp b/tests/unit/coverage/CoverageValidatorTest.cpp
index 519942b9a..fd8bc6cd6 100644
--- a/tests/unit/coverage/CoverageValidatorTest.cpp
+++ b/tests/unit/coverage/CoverageValidatorTest.cpp
@@ -23,13 +23,13 @@ struct test_coveragevalidator_data {
     WKTWriter w;
 
     void
-    printResult(std::unique_ptr<Geometry>& actual, std::unique_ptr<Geometry>& expected)
+    printResult(const Geometry& actual, const Geometry& expected)
     {
         std::cout << std::endl;
         std::cout << "--actual--" << std::endl;
-        std::cout << w.write(actual.get()) << std::endl;
+        std::cout << w.write(actual) << std::endl;
         std::cout << "--expect--" << std::endl;
-        std::cout << w.write(expected.get()) << std::endl;
+        std::cout << w.write(expected) << std::endl;
     }
 
     void
diff --git a/tests/unit/geom/GeometryFactoryTest.cpp b/tests/unit/geom/GeometryFactoryTest.cpp
index bb00b7708..30b01ae11 100644
--- a/tests/unit/geom/GeometryFactoryTest.cpp
+++ b/tests/unit/geom/GeometryFactoryTest.cpp
@@ -113,6 +113,7 @@ void object::test<2>
     auto geo = gf->createEmptyGeometry();
     ensure("createEmptyGeometry() returned null pointer.", geo != nullptr);
     ensure_equals(geo->getSRID(), gf->getSRID());
+    ensure_equals(geo->getSRID(), srid_);
     ensure_equals(geo->getPrecisionModel()->getType(), PrecisionModel::FIXED);
 } // test<2>
 
@@ -238,6 +239,7 @@ void object::test<8>
     ensure_equals(pt->getNumPoints(), 0u);
     ensure_equals(pt->getLength(), 0.0);
     ensure_equals(pt->getArea(), 0.0);
+    ensure_equals(pt->getSRID(), srid_);
 }
 
 // Test of createPoint(const Coordinate &coordinate) const

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

Summary of changes:
 capi/geos_c.h.in                               |  2 +-
 capi/geos_ts_c.cpp                             |  5 +-
 tests/unit/capi/GEOSCoverageIsValidTest.cpp    | 93 ++++++++++++++++++++++++++
 tests/unit/capi/GEOSCoverageSimplifyTest.cpp   | 20 ++++++
 tests/unit/coverage/CoverageSimplifierTest.cpp | 16 ++++-
 tests/unit/coverage/CoverageValidatorTest.cpp  |  6 +-
 tests/unit/geom/GeometryFactoryTest.cpp        |  2 +
 7 files changed, 136 insertions(+), 8 deletions(-)
 create mode 100644 tests/unit/capi/GEOSCoverageIsValidTest.cpp


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list