Skip to content

Commit

Permalink
Avoid MonotoneChain self-compare in SimpleMCSweepLineIntersector
Browse files Browse the repository at this point in the history
This is a hotspot in validity profiling. This commit reduces the runtime
of GEOSisValid from 3.7s to 2.0s for the 5,489 polygons in the
HydroBASINS level 5 dataset, and from 610ms to 360ms for the individual
polygon components of the boundary of Australia in the GADM country
dataset.
  • Loading branch information
dbaston committed Dec 2, 2019
1 parent fbb1804 commit 7ed0c82
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ Changes in 3.9.0
2020-xx-xx

- New things:
-
-

- Improvements:
- Stack allocate segments in OverlapUnion (Paul Ramsey)
- Improve performance of GEOSisValid (Dan Baston)


Changes in 3.8.0
Expand Down
8 changes: 8 additions & 0 deletions src/geomgraph/index/SimpleMCSweepLineIntersector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@ SimpleMCSweepLineIntersector::processOverlaps(size_t start, size_t end,
auto& ev1 = events[i];
if(ev1->isInsert()) {
MonotoneChain* mc1 = (MonotoneChain*) ev1->getObject();

if (mc1 == mc0) {
// Don't try to compute intersections between a MonotoneChain
// and itself. SegmentIntersector::addIntersections will just
// ignore them anyway.
continue;
}

// don't compare edges in same group
// null group indicates that edges should be compared
if(ev0->edgeSet == nullptr || (ev0->edgeSet != ev1->edgeSet)) {
Expand Down

0 comments on commit 7ed0c82

Please sign in to comment.