From 4907d593aa6aa31c25dbe73933bf66995a04e498 Mon Sep 17 00:00:00 2001 From: Paul Ramsey Date: Thu, 25 Jul 2024 11:41:01 -0700 Subject: [PATCH] Add envelope condition in support of RelateNG --- .../MCIndexSegmentSetMutualIntersector.h | 21 ++++++++++++++++--- .../MCIndexSegmentSetMutualIntersector.cpp | 13 ++++++++++-- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/include/geos/noding/MCIndexSegmentSetMutualIntersector.h b/include/geos/noding/MCIndexSegmentSetMutualIntersector.h index abc687919d..12fe5d8b3e 100644 --- a/include/geos/noding/MCIndexSegmentSetMutualIntersector.h +++ b/include/geos/noding/MCIndexSegmentSetMutualIntersector.h @@ -20,12 +20,15 @@ #include // inherited namespace geos { +namespace geom { + class Envelope; +} namespace index { -class SpatialIndex; + class SpatialIndex; } namespace noding { -class SegmentString; -class SegmentIntersector; + class SegmentString; + class SegmentIntersector; } } @@ -51,6 +54,17 @@ class MCIndexSegmentSetMutualIntersector : public SegmentSetMutualIntersector { , nOverlaps(0) , overlapTolerance(p_tolerance) , indexBuilt(false) + , envelope(nullptr) + {} + + MCIndexSegmentSetMutualIntersector(const geom::Envelope* p_envelope) + : monoChains() + , indexCounter(0) + , processCounter(0) + , nOverlaps(0) + , overlapTolerance(0.0) + , indexBuilt(false) + , envelope(p_envelope) {} MCIndexSegmentSetMutualIntersector() @@ -117,6 +131,7 @@ class MCIndexSegmentSetMutualIntersector : public SegmentSetMutualIntersector { */ bool indexBuilt; MonoChains indexChains; + const geom::Envelope* envelope; void addToIndex(SegmentString* segStr); diff --git a/src/noding/MCIndexSegmentSetMutualIntersector.cpp b/src/noding/MCIndexSegmentSetMutualIntersector.cpp index 148ace410c..b5b5e4d490 100644 --- a/src/noding/MCIndexSegmentSetMutualIntersector.cpp +++ b/src/noding/MCIndexSegmentSetMutualIntersector.cpp @@ -12,6 +12,7 @@ * **********************************************************************/ +#include #include #include #include @@ -47,8 +48,14 @@ MCIndexSegmentSetMutualIntersector::addToMonoChains(SegmentString* segStr) { if (segStr->size() == 0) return; + MonoChains segChains; MonotoneChainBuilder::getChains(segStr->getCoordinates(), - segStr, monoChains); + segStr, segChains); + for (auto& mc : segChains) { + if (envelope == nullptr || envelope->intersects(mc.getEnvelope())) { + monoChains.push_back(mc); + } + } } @@ -89,7 +96,9 @@ MCIndexSegmentSetMutualIntersector::process(SegmentString::ConstVect* segStrings { if (!indexBuilt) { for (auto& mc: indexChains) { - index.insert(&(mc.getEnvelope(overlapTolerance)), &mc); + if (envelope == nullptr || envelope->intersects(mc.getEnvelope())) { + index.insert(&(mc.getEnvelope(overlapTolerance)), &mc); + } } indexBuilt = true; }