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

turf-union, turf-difference, turf-intersect: Swap out martinez-polygon-clipping for polygon-clipping used in v7. #1916

Merged
merged 8 commits into from
Jul 8, 2020

Conversation

mbullington
Copy link
Contributor

@mbullington mbullington commented Jun 11, 2020

  • Use a meaningful title for the pull request. Include the name of the package modified.
  • Have read How To Contribute.
  • Run npm test at the sub modules where changes have occurred.
  • Run npm run lint to ensure code style at the turf module level.

Swap out all instances of martinez-polygon-clipping for polygon-clipping, which should fix errors expressed here: #1866

I regen'ed all of the tests, then independently checked each changed output file for correctness.

I'm very new to using Lerna and just used Yarn normally, please let me know if I did something incorrect for dependencies and how to properly fix.

Huge shoutout to @rowanwins who provided the basis for most of these changes in the v7 branch!

@mbullington
Copy link
Contributor Author

Not sure how I'm able to request reviews, so just mentioning people. :)

@rowanwins @mfedderly

@mfedderly mfedderly requested a review from rowanwins June 11, 2020 19:05
Copy link
Collaborator

@mfedderly mfedderly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look really good, I'm just hoping to get some minor clean up before we merge it. I spent a bunch of time hand-checking the geojsons and they look correct.

Can you go into packages/turf-mask/test.js and packages/turf-dissolve/test.js and delete the test skipping logic you deleted in packages/turf-union/test.js? The geojson files should be good (or at most need to be regenerated for small changes), but the tests had to be skipped to get the build to pass when I made (#1862).

Thanks!

if (differenced.length === 0) return null;
if (differenced.length === 1) return polygon(differenced[0], properties);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we keep this Polygon return? Seems like quite a bit of the tests changed just because of that. Otherwise we should change the types and jsdoc to match the new implementation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In inclined to agree with @mfedderly - it's kind of annoying when things get returned as a multipolygon when they aren't

@@ -6,8 +6,6 @@ const write = require('write-json-file');
const combine = require('@turf/combine').default;
const union = require('./dist/js/index.js').default;

const SKIP=["union4.geojson"];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you leave this skipping deleted, but keep the union4.geojson tests? The test should be fine but it was skipped here because it was failing because of the martinez-polygon-clipping issues.

throw new Error("poly1 and poly2 must be either polygons or multiPolygons");
}

// @ts-ignore
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you get rid of the @ts-ignore here?

Best case you can do something that casts to the [number,number] from a number[].

function foo(data: [number, number]) { }
const data: number[] = [1, 2];
foo(data as [number,number]);

Worst case you can do something like geom1.coordinates as any or geom1.coordinates as unknown as any.


const unioned: any = martinez.union(coords1, coords2);
// @ts-ignore
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please try to get rid of the @ts-ignore. See the same comment in turf-intersect/index.js.

// @ts-ignore
// Type error because Turf allows for arbitrary coordinate dimensions.
const intersection = polygonClipping.intersection(geom1.coordinates, geom2.coordinates);
if (intersection.length === 0) return null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment here about trying to return a Polygon if the intersection is a single polygon and not a MultiPolygon.

if (unioned.length === 0) return null;
if (unioned.length === 1) return polygon(unioned[0], options.properties);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to still return a Polygon here as well?

Copy link
Member

@rowanwins rowanwins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking really good @mbullington - if you're able to do fix up @mfedderly comments then I think it's good to go! Thanks for following up on this long standing issue.

@ngottlieb
Copy link
Contributor

@mbullington anything I can do to help this PR get merged?

@mfedderly
Copy link
Collaborator

@ngottlieb not sure what happened with the original author, but if you want to fork this PR and make the changes suggested I'd be happy to take a look. If I went and made the changes myself it disqualifies me from being able to merge the PR so its better if someone else does it.

@ngottlieb
Copy link
Contributor

@mfedderly I'll try to take a look today. Have not contributed to Turf code before so have to get up to speed but the referenced changes look pretty straightforward.

@mbullington
Copy link
Contributor Author

Hi, I took a look at all the requested changes and they sound good. Unfortunately I've been swamped the past few weeks, @ngottlieb if you're interested in helping out that would be amazing! Otherwise I can try & take a look later in the week

@ngottlieb
Copy link
Contributor

@mbullington I submitted a PR with the changes requested -- mbullington#1

@ngottlieb
Copy link
Contributor

apologies if this is an awkward way of submitting it, I wasn't sure how best to add the changes to this PR

@mfedderly
Copy link
Collaborator

@ngottlieb the changes look great, once @mbullington merges that PR I'll get this PR merged. Thanks for the help everyone!

@mbullington
Copy link
Contributor Author

mbullington commented Jul 8, 2020

Should be ready to go. Thanks everyone for helping finish my PR! Esp @ngottlieb

@mfedderly mfedderly merged commit 908dedb into Turfjs:master Jul 8, 2020
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.

4 participants