-
Notifications
You must be signed in to change notification settings - Fork 83
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
Conversation
…x-hull-2d with monotone-chain-convex-hull
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).
Perhaps again a matter of putting coordinates in the right order when calling the orientation check? |
Rejigged again @mourner |
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.
👍 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]; | ||
}); |
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.
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; |
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.
Nit: now that you have cross
shortcut below, you use that for less code.
Resolves #16
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.