Skip to content

Commit 840ba77

Browse files
Sushant NadavadeSushant Nadavade
authored andcommitted
changes made - 2
1 parent 8929109 commit 840ba77

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/main/java/com/thealgorithms/geometry/RotatingCalipers.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,11 @@ public static PointPair computeDiameter(Collection<Point> points) {
8484
double maxDistance = 0.0;
8585

8686
int j = 1;
87-
// Indexed loop required for rotating calipers algorithm
87+
// Rotating calipers algorithm requires indexed access for antipodal point tracking
8888
for (int i = 0; i < n; i++) {
8989
Point p1 = hull.get(i);
9090

91+
// Find antipodal point for current vertex
9192
while (true) {
9293
Point next = hull.get((j + 1) % n);
9394
double dist1 = distance(p1, hull.get(j));
@@ -284,13 +285,18 @@ private static List<Point> ensureCounterClockwiseOrder(List<Point> hull) {
284285
return hull;
285286
}
286287

288+
// Find bottommost point (lowest y, then leftmost x)
287289
Point bottomMost = hull.get(0);
288290
int bottomIndex = 0;
289-
// Must check all points to find the true bottommost point
291+
290292
for (int i = 1; i < hull.size(); i++) {
291-
Point p = hull.get(i);
292-
if (p.y() < bottomMost.y() || (p.y() == bottomMost.y() && p.x() < bottomMost.x())) {
293-
bottomMost = p;
293+
Point current = hull.get(i);
294+
// Check if current point is better than current best
295+
boolean isBetter = current.y() < bottomMost.y() ||
296+
(current.y() == bottomMost.y() && current.x() < bottomMost.x());
297+
298+
if (isBetter) {
299+
bottomMost = current;
294300
bottomIndex = i;
295301
}
296302
}

0 commit comments

Comments
 (0)