Skip to content

Commit

Permalink
PreparedPolygonIntersects: Use SimplePointInAreaLocator for first test (
Browse files Browse the repository at this point in the history
#777)

This provides better performance in cases where the prepared polygon is
only used for one test.
  • Loading branch information
dbaston authored Dec 20, 2022
1 parent d86aeab commit 1a45736
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions include/geos/geom/prep/PreparedPolygon.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class PreparedPolygon : public BasicPreparedGeometry {
bool isRectangle;
mutable std::unique_ptr<noding::FastSegmentSetIntersectionFinder> segIntFinder;
mutable std::unique_ptr<algorithm::locate::PointOnGeometryLocator> ptOnGeomLoc;
mutable std::unique_ptr<algorithm::locate::PointOnGeometryLocator> indexedPtOnGeomLoc;
mutable noding::SegmentString::ConstVect segStrings;
mutable std::unique_ptr<operation::distance::IndexedFacetDistance> indexedDistance;

Expand Down
12 changes: 10 additions & 2 deletions src/geom/prep/PreparedPolygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <geos/operation/predicate/RectangleIntersects.h>
#include <geos/algorithm/locate/PointOnGeometryLocator.h>
#include <geos/algorithm/locate/IndexedPointInAreaLocator.h>
#include <geos/algorithm/locate/SimplePointInAreaLocator.h>
// std
#include <cstddef>

Expand Down Expand Up @@ -68,11 +69,18 @@ algorithm::locate::PointOnGeometryLocator*
PreparedPolygon::
getPointLocator() const
{
// If we are only going to locate a single point, it's faster to do a brute-force SimplePointInAreaLocator
// instead of an IndexedPointInAreaLocator. There's a reasonable chance we will only use this locator
// once (for example, if we get here through Geometry::intersects). So we create a simple locator for the
// first usage and switch to an indexed locator when it is clear we're in a multiple-use scenario.
if(! ptOnGeomLoc) {
ptOnGeomLoc.reset(new algorithm::locate::IndexedPointInAreaLocator(getGeometry()));
ptOnGeomLoc = detail::make_unique<algorithm::locate::SimplePointInAreaLocator>(&getGeometry());
return ptOnGeomLoc.get();
} else if (!indexedPtOnGeomLoc) {
indexedPtOnGeomLoc = detail::make_unique<algorithm::locate::IndexedPointInAreaLocator>(getGeometry());
}

return ptOnGeomLoc.get();
return indexedPtOnGeomLoc.get();
}

bool
Expand Down

0 comments on commit 1a45736

Please sign in to comment.