Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect intersection of MultiPolygon and Point #5589

Open
LostDragonist opened this issue Mar 6, 2025 · 3 comments · May be fixed by #5590
Open

Incorrect intersection of MultiPolygon and Point #5589

LostDragonist opened this issue Mar 6, 2025 · 3 comments · May be fixed by #5590
Labels
bug Something isn't working PR is more than welcomed Extra attention is needed

Comments

@LostDragonist
Copy link
Contributor

LostDragonist commented Mar 6, 2025

maplibre-gl-js version: 5.2.0 (latest tested, bug goes back 9+ years)

browser: Chrome 133

Steps to Trigger Behavior

  1. Create a MultiPolygon where an even number of Polygons appear the same location.
  2. Attempt to use queryRenderedFeatures at that location to detect the MultiPolygon.
  3. Observe you get no results.

Link to Demonstration

https://jsbin.com/bufawog/edit?html,output

Check the console for output.

Expected Behavior

Using queryRenderedFeatures on an even number of overlapping Polygons in a MultiPolygon should work detect the MultiPolygon.

Actual Behavior

Using queryRenderedFeatures on an even number of overlapping Polygons in a MultiPolygon does not detect the MultiPolygon.

@LostDragonist
Copy link
Contributor Author

I have traced this issue back to this: https://github.com/LostDragonist/maplibre-gl-js/blob/main/src/util/intersection_tests.ts#L144

c is being flipped between true and false as part of the polygon ray-tracing algorithm. That's fine. The issues are that:

  1. c is not being reset between polygons. This has the potential to lead to some false-positives (theoretically? haven't reproduced that yet)
  2. When c == true after processing a complete polygon, the entire function should return true as being within any Polygon of a MultiPolygon means you are within that MultiPolygon. There's not the same concept of "holes" that Polygons have. The MultiPolygon rendering supports this fact.

I'll be working up a PR for this shortly.

@HarelM HarelM added bug Something isn't working PR is more than welcomed Extra attention is needed labels Mar 6, 2025
@HarelM
Copy link
Collaborator

HarelM commented Mar 6, 2025

Is this considered a valid multipolygon, where two polygons overlap each other?

@LostDragonist
Copy link
Contributor Author

Nothing in RFC 7946 (current or previous revisions) calls it out as being invalid or having special considerations.

There's actually already a query integration test in place that uses a multipolygon with two overlapping polygons. The reason that one currently works is that it tests against a bounding box instead of just point. Therefore it hits a different code path that doesn't have the same issues.

@LostDragonist LostDragonist linked a pull request Mar 6, 2025 that will close this issue
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working PR is more than welcomed Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants