Skip to content

Commit

Permalink
Fix bug in intersection of non-contiguous SpanSets
Browse files Browse the repository at this point in the history
  • Loading branch information
fred3m committed Dec 4, 2024
1 parent af9ad5d commit 1413f48
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/geom/SpanSet.cc
Original file line number Diff line number Diff line change
Expand Up @@ -727,16 +727,18 @@ std::shared_ptr<SpanSet> SpanSet::intersect(SpanSet const& other) const {
return std::make_shared<SpanSet>(this->_spanVector);
}
std::vector<Span> tempVec;
auto otherIter = other.begin();
auto otherBeginIter = other.begin();
for (auto const& spn : _spanVector) {
while (otherIter != other.end() && otherIter->getY() <= spn.getY()) {
while(otherBeginIter != other.end() && otherBeginIter->getY() < spn.getY()) {
++otherBeginIter;
}
for (auto otherIter = otherBeginIter; otherIter != other.end() && otherIter->getY() <= spn.getY(); ++otherIter) {
if (spansOverlap(spn, *otherIter)) {
auto newMin = std::max(spn.getMinX(), otherIter->getMinX());
auto newMax = std::min(spn.getMaxX(), otherIter->getMaxX());
auto newSpan = Span(spn.getY(), newMin, newMax);
tempVec.push_back(newSpan);
}
++otherIter;
}
}
return std::make_shared<SpanSet>(std::move(tempVec));
Expand Down

0 comments on commit 1413f48

Please sign in to comment.