diff --git a/capi/geos_ts_c.cpp b/capi/geos_ts_c.cpp index 2ac48477c..b6efb7e03 100644 --- a/capi/geos_ts_c.cpp +++ b/capi/geos_ts_c.cpp @@ -94,7 +94,6 @@ #include #include -#include #include #include @@ -210,7 +209,6 @@ using geos::operation::overlayng::OverlayNG; using geos::operation::overlayng::UnaryUnionNG; using geos::operation::overlayng::OverlayNGRobust; using geos::operation::relateng::RelateNG; -using geos::operation::relateng::RelatePredicate; using geos::operation::valid::TopologyValidationError; using geos::precision::GeometryPrecisionReducer; @@ -583,7 +581,7 @@ extern "C" { GEOSDisjoint_r(GEOSContextHandle_t extHandle, const Geometry* g1, const Geometry* g2) { return execute(extHandle, 2, [&]() { - return RelateNG::disjoint(g1, g2); + return g1->disjoint(g2); }); } @@ -591,7 +589,7 @@ extern "C" { GEOSTouches_r(GEOSContextHandle_t extHandle, const Geometry* g1, const Geometry* g2) { return execute(extHandle, 2, [&]() { - return RelateNG::touches(g1, g2); + return g1->touches(g2); }); } @@ -599,7 +597,7 @@ extern "C" { GEOSIntersects_r(GEOSContextHandle_t extHandle, const Geometry* g1, const Geometry* g2) { return execute(extHandle, 2, [&]() { - return RelateNG::intersects(g1, g2); + return g1->intersects(g2); }); } @@ -607,7 +605,7 @@ extern "C" { GEOSCrosses_r(GEOSContextHandle_t extHandle, const Geometry* g1, const Geometry* g2) { return execute(extHandle, 2, [&]() { - return RelateNG::crosses(g1, g2); + return g1->crosses(g2); }); } @@ -615,7 +613,7 @@ extern "C" { GEOSWithin_r(GEOSContextHandle_t extHandle, const Geometry* g1, const Geometry* g2) { return execute(extHandle, 2, [&]() { - return RelateNG::within(g1, g2); + return g1->within(g2); }); } @@ -623,7 +621,7 @@ extern "C" { GEOSContains_r(GEOSContextHandle_t extHandle, const Geometry* g1, const Geometry* g2) { return execute(extHandle, 2, [&]() { - return RelateNG::contains(g1, g2); + return g1->contains(g2); }); } @@ -631,7 +629,7 @@ extern "C" { GEOSOverlaps_r(GEOSContextHandle_t extHandle, const Geometry* g1, const Geometry* g2) { return execute(extHandle, 2, [&]() { - return RelateNG::overlaps(g1, g2); + return g1->overlaps(g2); }); } @@ -639,7 +637,7 @@ extern "C" { GEOSCovers_r(GEOSContextHandle_t extHandle, const Geometry* g1, const Geometry* g2) { return execute(extHandle, 2, [&]() { - return RelateNG::covers(g1, g2); + return g1->covers(g2); }); } @@ -647,7 +645,7 @@ extern "C" { GEOSCoveredBy_r(GEOSContextHandle_t extHandle, const Geometry* g1, const Geometry* g2) { return execute(extHandle, 2, [&]() { - return RelateNG::coveredBy(g1, g2); + return g1->coveredBy(g2); }); } @@ -655,7 +653,7 @@ extern "C" { GEOSEquals_r(GEOSContextHandle_t extHandle, const Geometry* g1, const Geometry* g2) { return execute(extHandle, 2, [&]() { - return RelateNG::equalsTopo(g1, g2); + return g1->equals(g2); }); } diff --git a/include/geos/geom/prep/BasicPreparedGeometry.h b/include/geos/geom/prep/BasicPreparedGeometry.h index 068ade2bc..f061de451 100644 --- a/include/geos/geom/prep/BasicPreparedGeometry.h +++ b/include/geos/geom/prep/BasicPreparedGeometry.h @@ -61,12 +61,12 @@ class BasicPreparedGeometry: public PreparedGeometry { std::vector representativePts; mutable std::unique_ptr relate_ng; - std::unique_ptr& getRelateNG() const + RelateNG& getRelateNG() const { if (relate_ng == nullptr) relate_ng = RelateNG::prepare(baseGeom); - return relate_ng; + return *relate_ng; } protected: diff --git a/include/geos/index/chain/MonotoneChain.h b/include/geos/index/chain/MonotoneChain.h index d6b1b1ad6..a5172f9d7 100644 --- a/include/geos/index/chain/MonotoneChain.h +++ b/include/geos/index/chain/MonotoneChain.h @@ -151,9 +151,6 @@ class GEOS_DLL MonotoneChain { return context; } - void setId(int p_id) { id = p_id; } - int getId() const { return id; } - private: void computeSelect(const geom::Envelope& searchEnv, @@ -201,9 +198,6 @@ class GEOS_DLL MonotoneChain { /// Owned by this class mutable geom::Envelope env; - /// Useful for optimizing chain comparisons - int id = 0; - }; } // namespace geos::index::chain diff --git a/include/geos/operation/relateng/EdgeSetIntersector.h b/include/geos/operation/relateng/EdgeSetIntersector.h index 70b6cb315..35028b5bd 100644 --- a/include/geos/operation/relateng/EdgeSetIntersector.h +++ b/include/geos/operation/relateng/EdgeSetIntersector.h @@ -59,7 +59,7 @@ class GEOS_DLL EdgeSetIntersector { // HPRtree index = new HPRtree(); const Envelope* envelope = nullptr; std::deque monoChains; - int idCounter = 0; + std::size_t overlapCounter = 0; // Methods @@ -76,7 +76,6 @@ class GEOS_DLL EdgeSetIntersector { std::vector& edgesB, const Envelope* env) : envelope(env) - , idCounter(0) { addEdges(edgesA); addEdges(edgesB); diff --git a/src/geom/prep/BasicPreparedGeometry.cpp b/src/geom/prep/BasicPreparedGeometry.cpp index c346fcf42..0718a37b0 100644 --- a/src/geom/prep/BasicPreparedGeometry.cpp +++ b/src/geom/prep/BasicPreparedGeometry.cpp @@ -93,73 +93,73 @@ BasicPreparedGeometry::isAnyTargetComponentInTest(const geom::Geometry* testGeom bool BasicPreparedGeometry::within(const geom::Geometry* g) const { - return getRelateNG()->within(g); + return getRelateNG().within(g); } bool BasicPreparedGeometry::contains(const geom::Geometry* g) const { - return getRelateNG()->contains(g); + return getRelateNG().contains(g); } bool BasicPreparedGeometry::containsProperly(const geom::Geometry* g) const { - return getRelateNG()->relate(g, "T**FF*FF*"); + return getRelateNG().relate(g, "T**FF*FF*"); } bool BasicPreparedGeometry::coveredBy(const geom::Geometry* g) const { - return getRelateNG()->coveredBy(g); + return getRelateNG().coveredBy(g); } bool BasicPreparedGeometry::covers(const geom::Geometry* g) const { - return getRelateNG()->covers(g); + return getRelateNG().covers(g); } bool BasicPreparedGeometry::crosses(const geom::Geometry* g) const { - return getRelateNG()->crosses(g); + return getRelateNG().crosses(g); } bool BasicPreparedGeometry::disjoint(const geom::Geometry* g) const { - return getRelateNG()->disjoint(g); + return getRelateNG().disjoint(g); } bool BasicPreparedGeometry::intersects(const geom::Geometry* g) const { - return getRelateNG()->intersects(g); + return getRelateNG().intersects(g); } bool BasicPreparedGeometry::overlaps(const geom::Geometry* g) const { - return getRelateNG()->overlaps(g); + return getRelateNG().overlaps(g); } bool BasicPreparedGeometry::touches(const geom::Geometry* g) const { - return getRelateNG()->touches(g); + return getRelateNG().touches(g); } bool BasicPreparedGeometry::relate(const geom::Geometry* g, const std::string& pat) const { - return getRelateNG()->relate(g, pat); + return getRelateNG().relate(g, pat); } std::unique_ptr BasicPreparedGeometry::relate(const geom::Geometry* g) const { - return getRelateNG()->relate(g); + return getRelateNG().relate(g); } diff --git a/src/operation/relateng/EdgeSetIntersector.cpp b/src/operation/relateng/EdgeSetIntersector.cpp index 37b3600b8..5a33ef387 100644 --- a/src/operation/relateng/EdgeSetIntersector.cpp +++ b/src/operation/relateng/EdgeSetIntersector.cpp @@ -22,6 +22,7 @@ #include #include #include +#include using geos::geom::Geometry; @@ -54,7 +55,7 @@ EdgeSetIntersector::addToIndex(const SegmentString* segStr) for (MonotoneChain& mc : segChains) { if (envelope == nullptr || envelope->intersects(mc.getEnvelope())) { - mc.setId(idCounter++); + // mc.setId(idCounter++); monoChains.push_back(mc); MonotoneChain* mcPtr = &(monoChains.back()); index.insert(mcPtr->getEnvelope(), mcPtr); @@ -68,26 +69,18 @@ EdgeSetIntersector::process(EdgeSegmentIntersector& intersector) { EdgeSegmentOverlapAction overlapAction(intersector); - for (const MonotoneChain& queryChain : monoChains) { + // Replaces JTS implementation that manually iterates on the + // monoChains with the automatic queryPairs method in TemplateSTRTree + index.queryPairs([this, &overlapAction, &intersector](const MonotoneChain* queryChain, const MonotoneChain* testChain) { - std::vector overlapChains; - index.query(queryChain.getEnvelope(), [&overlapChains](const MonotoneChain* mc) { - overlapChains.push_back(mc); - }); + if (overlapCounter++ % 100000 == 0) + GEOS_CHECK_FOR_INTERRUPTS(); - for (const MonotoneChain* testChain : overlapChains) { - /** - * following test makes sure we only compare each pair of chains once - * and that we don't compare a chain to itself - */ - if (testChain->getId() <= queryChain.getId()) - continue; + testChain->computeOverlaps(queryChain, &overlapAction); + + return !intersector.isDone(); + }); - testChain->computeOverlaps(&queryChain, &overlapAction); - if (intersector.isDone()) - return; - } - } }