-
Notifications
You must be signed in to change notification settings - Fork 993
@turf/boolean-contains: Add MultiPolygon support for non-polygon types #3010
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
base: master
Are you sure you want to change the base?
Conversation
|
Thanks heaps for putting this together @rexxars. To some of your questions:
We asked ourselves this recently, and discovered some performance differences for what should be equivalent approaches. Before pressing ahead, we wanted to understand why that was happening first. Though yes, ideally we would have a single implementation that served both operations.
Generally speaking, we try to have each package export a single function (helpers and meta being the exceptions). Any other packages that do that is doing so probably because we've never had a good place to keep common code in the monorepo. We're half way through adding an internal code only package. Suspect between your two PRs there might be some good candidates? |
Curious! Not a blocker for this PR, was just curious about the context around it
Many of the same methods are implemented in
For reference, these are all the (currently) exported methods from
I could see the rationale for exporting the
Yes, that appears correct. |
|
I would guess it's mostly historical "just in case" exporting. Can you see any drawbacks to the below as a plan:
Not asking you to commit to any of this beyond what you've already done. Just making the most of your recent perusal of those two packages. |
|
Yep, happy with that plan. If I could be slightly selfish, I'd love to have this merged and released and then do some follow-up PRs to address point 2-4 (happy to help with this and more, but they're not backwards incompatible changes). I'm trying to use this library in groq-js (for our geo functions) and that would unblock that work :) |
| if (!booleanPointInPolygon(coord, polygon)) { | ||
| return false; | ||
| } | ||
| // Track if at least one point is strictly in the interior |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you mind expanding on the reasoning here? I would have expected for a MultiPoint to be contained in a poly every point of that MP is contained.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The topological definition of "contains" per the DE-9IM says
that A contains B requires two conditions:
- No point of B lies in the exterior of A (tested on line 298)
- At least one point of the interior of B lies in the interior of A (tested below)
If every point of the MultiPoint (B) sits exactly on the polygons boundary (eg. on an edge or vertex), then the interiors of A and B never intersect.
This is point two of what I mentioned in the PR description:
Fixes(?) behavior of
booleanContainsto return true if every point is inside/on boundary of some polygon in the MultiPolygon, and at least one is strictly interior. This previously returned false, but differs frombooleanWithinand doesn't match DE-9IM semantics. In my eyes this is a bugfix, not a breaking change

Changes:
booleanContainsto support MultiPolygon as the containing geometry for additional geometry types. Previously,booleanContains(MultiPolygon, X)only worked when X was a Polygon.booleanContainsto return true if every point is inside/on boundary of some polygon in the MultiPolygon, and at least one is strictly interior. This previously returned false, but differs frombooleanWithinand doesn't match DE-9IM semantics. In my eyes this is a bugfix, not a breaking changeNew supported combinations:
Follows DE-9IM "contains" semantics:
Questions:
booleanContainsdocumentation states booleanContains(a, b) is equivalent to booleanWithin(b, a) - if that's true, why doesbooleanWithinnot import thebooleanContainsmodule and swap the argument order instead of redefining all the logic?@private(such ascompareCoords). I wasn't sure if I should export the new helper methods or not, and if they should be marked as private