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 some troublesome dependencies #17

Merged
merged 4 commits into from
May 18, 2020
Merged

Replace some troublesome dependencies #17

merged 4 commits into from
May 18, 2020

Conversation

rowanwins
Copy link
Contributor

Resolves #16

  • replace robust-orientation with robust-predicates, and
  • replace monotone-convex-hull-2d with monotone-chain-convex-hull
    • I did look at inlining the convex hull algorithm using the one suggested however it produced different results whereas the other package I picked produced the same results out of the box. Looks like there are a few minor variations in the implementation.

I did also do a before/after performance comparison and there seems to be negligible difference. If you're interested I'm happy to submit the benchmark setup I created with benchmarkjs.

@mourner
Copy link
Member

mourner commented May 14, 2020

The problem with this convex hull dependency is that it's not robust, so it will be inconsistent (convex hull non-robust while concaveman core algorithm robust).

I did look at inlining the convex hull algorithm using the one suggested however it produced different results

Perhaps again a matter of putting coordinates in the right order when calling the orientation check?

@rowanwins
Copy link
Contributor Author

Rejigged again @mourner

Copy link
Member

@mourner mourner left a comment

Choose a reason for hiding this comment

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

👍 apart from a few nits.

index.js Outdated
function convexHull(points) {
points.sort(function (a, b) {
return a[0] === b[0] ? a[1] - b[1] : a[0] - b[0];
});
Copy link
Member

Choose a reason for hiding this comment

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

Nit: I prefer to not inline anonymous functions wherever possible (this one could be extracted as compareByX to the top level).

index.js Outdated
orient(p1, q1, p2) > 0 !== orient(p1, q1, q2) > 0 &&
orient(p2, q2, p1) > 0 !== orient(p2, q2, q1) > 0;
orient(p1[0], p1[1], q1[0], q1[1], p2[0], p2[1]) > 0 !== orient(p1[0], p1[1], q1[0], q1[1], q2[0], q2[1]) > 0 &&
orient(p2[0], p2[1], q2[0], q2[1], p1[0], p1[1]) > 0 !== orient(p2[0], p2[1], q2[0], q2[1], q1[0], q1[1]) > 0;
Copy link
Member

Choose a reason for hiding this comment

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

Nit: now that you have cross shortcut below, you use that for less code.

@mourner mourner merged commit 27ab4f5 into mapbox:master May 18, 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.

Look at replacing robust-orientation with robust-predicates
2 participants