-
-
Notifications
You must be signed in to change notification settings - Fork 359
Add Graham Scan in Java #459
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
Conversation
return 0; | ||
}; | ||
|
||
hull.sort(angleComparator); |
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.
The code in this method up to this point could be written as:
gift = gift
.stream()
.distinct()
.sorted(Comparator.comparingDouble(point -> -point.y))
.collect(Collectors.toList());
Point pivot = gift.get(0);
// Sort the remaining Points based on the angle between the pivot and itself
List<Point> hull = gift.subList(1, gift.size());
hull.sort(Comparator.comparingDouble(point -> polarAngle(point, pivot)));
which I think is a bit more readable.
} | ||
|
||
public static void main(String[] args) { | ||
ArrayList<Point> points = new ArrayList<Point>(); |
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.
It's good practice to not repeat type parameters when it's not necessary:
ArrayList<Point> points = new ArrayList<>();
|
||
List<Point> convexHull = grahamScan(points); | ||
|
||
convexHull.stream().forEach(p -> System.out.printf("% 1.0f, % 1.0f\n", p.x, p.y)); |
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.
You don't need the .stream()
here, List<T>
already has a forEach
method.
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 to me, thanks for incorporating the changes.
No description provided.