From ce259945da21066105ad19fa2a9f986df5b2ef6a Mon Sep 17 00:00:00 2001 From: Paul Ramsey Date: Mon, 12 Aug 2024 14:07:08 -0700 Subject: [PATCH] Change API on RelateNG::relate() to always return IM matrix --- capi/geos_ts_c.cpp | 2 +- include/geos/geom/prep/BasicPreparedGeometry.h | 2 +- include/geos/geom/prep/PreparedGeometry.h | 3 ++- include/geos/operation/relateng/RelateNG.h | 2 +- src/geom/prep/BasicPreparedGeometry.cpp | 3 ++- src/operation/relateng/RelateNG.cpp | 4 ++-- tests/unit/operation/relateng/RelateNGTest.h | 2 +- 7 files changed, 10 insertions(+), 8 deletions(-) diff --git a/capi/geos_ts_c.cpp b/capi/geos_ts_c.cpp index 64aaf8e3e5..37b00020ee 100644 --- a/capi/geos_ts_c.cpp +++ b/capi/geos_ts_c.cpp @@ -3755,7 +3755,7 @@ extern "C" { const geos::geom::prep::PreparedGeometry* pg, const Geometry* g) { return execute(extHandle, [&]() -> char * { - return gstrdup(pg->relate(g)); + return gstrdup(pg->relate(g)->toString()); }); } diff --git a/include/geos/geom/prep/BasicPreparedGeometry.h b/include/geos/geom/prep/BasicPreparedGeometry.h index dcd9fe3a6d..a666564b84 100644 --- a/include/geos/geom/prep/BasicPreparedGeometry.h +++ b/include/geos/geom/prep/BasicPreparedGeometry.h @@ -182,7 +182,7 @@ class BasicPreparedGeometry: public PreparedGeometry { /** * Default implementation. */ - std::string relate(const geom::Geometry* g) const override; + std::unique_ptr relate(const geom::Geometry* g) const override; /** * Default implementation. diff --git a/include/geos/geom/prep/PreparedGeometry.h b/include/geos/geom/prep/PreparedGeometry.h index 7369502237..cdb8c777cd 100644 --- a/include/geos/geom/prep/PreparedGeometry.h +++ b/include/geos/geom/prep/PreparedGeometry.h @@ -28,6 +28,7 @@ namespace geos { class Geometry; class Coordinate; class CoordinateSequence; + class IntersectionMatrix; } } @@ -235,7 +236,7 @@ class GEOS_DLL PreparedGeometry { * @param geom the Geometry to test the * @return the DE9IM matrix */ - virtual std::string relate(const geom::Geometry* g) const = 0; + virtual std::unique_ptr relate(const geom::Geometry* g) const = 0; /** \brief * Compares the prepared geometry to the given geometry diff --git a/include/geos/operation/relateng/RelateNG.h b/include/geos/operation/relateng/RelateNG.h index f9b0e92b78..524c750855 100644 --- a/include/geos/operation/relateng/RelateNG.h +++ b/include/geos/operation/relateng/RelateNG.h @@ -272,7 +272,7 @@ class GEOS_DLL RelateNG { bool coveredBy(const Geometry* a); bool equalsTopo(const Geometry* a); bool relate(const Geometry* a, const std::string& pat); - std::string relate(const Geometry* a); + std::unique_ptr relate(const Geometry* a); }; diff --git a/src/geom/prep/BasicPreparedGeometry.cpp b/src/geom/prep/BasicPreparedGeometry.cpp index 9dac0b9656..4d2816fe49 100644 --- a/src/geom/prep/BasicPreparedGeometry.cpp +++ b/src/geom/prep/BasicPreparedGeometry.cpp @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -155,7 +156,7 @@ BasicPreparedGeometry::relate(const geom::Geometry* g, const std::string& pat) c return getRelateNG()->relate(g, pat); } -std::string +std::unique_ptr BasicPreparedGeometry::relate(const geom::Geometry* g) const { return getRelateNG()->relate(g); diff --git a/src/operation/relateng/RelateNG.cpp b/src/operation/relateng/RelateNG.cpp index 28d5830112..42a965ba5e 100644 --- a/src/operation/relateng/RelateNG.cpp +++ b/src/operation/relateng/RelateNG.cpp @@ -269,10 +269,10 @@ RelateNG::relate(const Geometry* b, const std::string& imPattern) } /* public */ -std::string +std::unique_ptr RelateNG::relate(const Geometry* b) { - return evaluate(b)->toString(); + return evaluate(b); } /************************************************************************/ diff --git a/tests/unit/operation/relateng/RelateNGTest.h b/tests/unit/operation/relateng/RelateNGTest.h index 82a39b80f7..a33ef18537 100644 --- a/tests/unit/operation/relateng/RelateNGTest.h +++ b/tests/unit/operation/relateng/RelateNGTest.h @@ -40,7 +40,7 @@ struct test_relateng_support { ensure_equals("preparedContains", prep_a->contains(b), a->contains(b)); ensure_equals("preparedCrosses", prep_a->crosses(b), a->crosses(b)); ensure_equals("preparedTouches", prep_a->touches(b), a->touches(b)); - ensure_equals("preparedRelate", prep_a->relate(b), a->relate(b)->toString()); + ensure_equals("preparedRelate", prep_a->relate(b)->toString(), a->relate(b)->toString()); } void checkIntersectsDisjoint(const std::string& wkta, const std::string& wktb, bool expectedValue)