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

replace polygon-clipping with polyclip-ts #2729

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

cmurphy23
Copy link

@cmurphy23 cmurphy23 commented Oct 9, 2024

This commit replaces the polygon-clipping library with polyclip-ts, a goal mentioned in several issues (#2409, #2277, #2048), with even more issues related to polyon-clipping problems that don't mention polyclip-ts (#2705, #2420, #1983, and others).

This PR is a placeholder, dependent on this PR for polyclip-ts so that the polyclip-ts library doesn't fail the esModuleInterop check. Once those changes have been merged and released, the polyclip-ts version just needs to be incremented in the different modules' package.json files, then turf should should build and the tests should pass.

The affected packages are: intersect, difference, union, dissolve, and mask

It is worth noting that I am not an expert on these algorithms, and in the cases where the test results differed, I simply updated the tests with the new results. The vast majority of the differences were just floating point rounding differences, but there were different results for two turf-difference tests. For the test "issue-721", two polygons are returned for the difference instead of one, where the first polygon is basically identical to the original answer, but a new very small polygon on the border of the polygons has also been found and returned. For "issue-721-inverse", instead of no difference being found, three very small polygons have been found on the borders. I don't actually know what the correct answers are since the test case is truly an edge case and higher precision might produce a different result. However, based on the issues I've mentioned, polyclip-ts seems like the more reliable repo, turfjs is regularly having issues with these operations using polygon-clipping, and it would be nice if it didn't.

Possibly:

Resolves #2409
Resolves #2277
Resolves #2048
Resolves #2705
Resolves #2420
Resolves #1983
... and others (TBC)

  • Is this a bug fix, new functionality, or a breaking change?
    I would argue it's closest to a bug fix.
  • Have read and followed the steps for preparing a pull request.
    I followed the steps, just need polyclip-ts to update and release, then this code will work.

@smallsaucepan
Copy link
Member

Really appreciate you putting this together @cmurphy23. Take there is no workaround for the esModuleInterop issue that might let us get this merged (and those issues resolved) sooner?

Also understand your note about the tests. Anything that looks like more than a rounding change, we can go through together, perhaps with one of the other maintainers.

@cmurphy23
Copy link
Author

No problem, @smallsaucepan, glad to be able to contribute.

The PR for polyclip-ts got merged and a new release was made. This PR now references the new release and should be considered for merging. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment