diff --git a/include/geos/index/chain/MonotoneChain.h b/include/geos/index/chain/MonotoneChain.h index d6b1b1ad6d..a5172f9d78 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 70b6cb3154..35028b5bd4 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/operation/relateng/EdgeSetIntersector.cpp b/src/operation/relateng/EdgeSetIntersector.cpp index 37b3600b83..63332acf1f 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,19 @@ 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); + + if (intersector.isDone()) + return; + }); - testChain->computeOverlaps(&queryChain, &overlapAction); - if (intersector.isDone()) - return; - } - } }