-
Notifications
You must be signed in to change notification settings - Fork 412
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
Graham's Scan implementation #123
Conversation
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.
Looks great, thanks! 🍻
return P; | ||
} | ||
preprocessing(P); | ||
console.log(P); |
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.
Could you please remove this debugging info?
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.
Sure, i forgot it.
let j = convexHull.length; | ||
while (j >= 2 && | ||
vectorOp. | ||
parallelogramArea(convexHull[j-2], convexHull[j-1], P[i]) <= 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.
Can we use the isClockwise
helper here? (or !isCounterClockwise
)
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.
Actually we can't, because both isClockwise and isCounterClockwise return false when the points are collinear, but we want to remove them from the convexHull when they are collinear.
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.
Actually we can use !isCounterClockwise, it will do the same job. I'll change it soon.
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.
Looks good, but it would be nice to make two small changes:
- for consistency, always use arrow functions
- variable names always starting in lower case (i.e. the P passed to the grahamScan function).
Other than that, everything is great, thanks for the contribution!
My changes provide an implementation of the Graham's scan algorithm, basic 2D vector operations and tests for both.