File tree Expand file tree Collapse file tree 1 file changed +11
-5
lines changed
src/main/java/com/thealgorithms/geometry Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments