Skip to content

Conversation

@Pitouli
Copy link
Contributor

@Pitouli Pitouli commented Jan 18, 2025

Perf improvement

No breaking changes; it simply return early once it confirmed that the point is inside at least one polygon, instead of checking all the other polygons.

Fix edge case

If the point was on the edge of a polygon, the function was returning immediately "true" if the option ignoreBoundary was false, and false otherwise.

But the RFC does not say that polygons inside a multipolygon cannot overlap, it only says a multipolygon is an array of polygons.
https://datatracker.ietf.org/doc/html/rfc7946#section-3.1.7

So in case the point is on the border of one of the polygon and ignoreBoundary is true, the loop should continue to see if the point is inside an another polygon.

Note that some libraries seems to consider that multipolygon must not overlap
Leaflet/Leaflet#6173 (comment)
But this PR is not even a breaking change if we consider this definition, since for a non overlapping multipolygons the result of the function will stay the same ; the only difference is that it will indeed loop over all the polygons instead of exiting early.

Tests

The tests have been ran for this package, and a new case has been created to specifically test the situation with a multipolygon with a point on the borders of a small polygon inside a bigger one.

I let Github CI run the full tests.

Pitouli and others added 3 commits January 18, 2025 18:04
Optimize booleanPointInPolygon to return "true" as soon as one polygon contains the point instead of looping over all the polygons
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants