Skip to content

Commit f8b773d

Browse files
Clean up code
1 parent edf9759 commit f8b773d

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

contents/graham_scan/code/rust/graham_scan.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ impl Ord for Point {
2626
}
2727
}
2828

29-
// Check if the turn of the points is counter clockwise.
3029
fn counter_clockwise(a: &Point, b: &Point, c: &Point) -> bool {
3130
(b.x - a.x) * (c.y - a.y) >= (b.y - a.y) * (c.x - a.x)
3231
}
@@ -37,15 +36,15 @@ fn polar_angle(reference: &Point, point: &Point) -> f64 {
3736
}
3837

3938
fn graham_scan(mut points: Vec<Point>) -> Vec<Point> {
40-
// First, sort the points so the one with the lowest y-coordinate comes first (the pivot)
4139
points.sort_unstable();
4240

43-
// Take ownership of the pivot point
4441
let pivot = points.remove(0);
4542

4643
// Sort all points based on the angle between the pivot point and itself
47-
&mut points
48-
.sort_by(|a, b| (polar_angle(a, &pivot).partial_cmp(&polar_angle(b, &pivot))).unwrap());
44+
&mut points.sort_by(|a, b| (polar_angle(a, &pivot).
45+
partial_cmp(&polar_angle(b, &pivot))
46+
).unwrap()
47+
);
4948

5049
// Reinsert the pivot point
5150
points.insert(0, pivot);

0 commit comments

Comments
 (0)