Skip to content

@turf/boolean-within: add MultiPolygon support, de-duplicate logic#3011

Draft
rexxars wants to merge 3 commits intoTurfjs:masterfrom
rexxars:refactor/within-mirror-contains
Draft

@turf/boolean-within: add MultiPolygon support, de-duplicate logic#3011
rexxars wants to merge 3 commits intoTurfjs:masterfrom
rexxars:refactor/within-mirror-contains

Conversation

@rexxars
Copy link

@rexxars rexxars commented Jan 30, 2026

Note: builds on #3010 - review that one first.

The @turf/boolean-within module is basically a duplicate of @turf/boolean-contains, with the argument order swapped. This PR removes the duplicate logic, instead importing the @turf/boolean-contains module and calling it directly, with swapped argument orders. This has multiple benefits:

  1. Gains support for MultiPolygon (through #3010)
  2. Prevents drift/differences between the two (one difference was already identified and fixed in #3010)
  3. Reduces the bundle size for anyone who should depend on both modules

(This was also suggested by @bratter in this issue I just found)

I would argue that one could consider deprecating this entire module in favor of @turf/boolean-contains (or the other way around), as keeping the test suites in sync between the two is slightly annoying - but leaving this up to you as maintainers to decide :)

Fixes #1444

@bratter
Copy link
Contributor

bratter commented Jan 31, 2026

Nice! My 2c is to not deprecate as they are both commonly accepted de-9im terms.

@smallsaucepan
Copy link
Member

Thanks for this PR too. Let's discuss on #3010 knowing that applies here as well.

Believe worth keeping both contains and within as sometimes one expresses the relationship more naturally, saving the user some mental gymnastics.

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.

Feature request: Support MultiPolygon booleanWithin Polygon

3 participants