Skip to content

Commit 8929109

Browse files
Sushant NadavadeSushant Nadavade
authored andcommitted
CLI improvements are complete
1 parent 5d3913f commit 8929109

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.thealgorithms.geometry;
22

33
import java.util.ArrayList;
4+
import java.util.Collection;
45
import java.util.Collections;
56
import java.util.List;
67

@@ -60,7 +61,7 @@ public String toString() {
6061
* @return PointPair containing the two points with maximum distance and the distance
6162
* @throws IllegalArgumentException if points is null or has less than 2 points
6263
*/
63-
public static PointPair computeDiameter(List<Point> points) {
64+
public static PointPair computeDiameter(Collection<Point> points) {
6465
if (points == null || points.size() < 2) {
6566
throw new IllegalArgumentException("Points list must contain at least 2 points");
6667
}
@@ -83,6 +84,7 @@ public static PointPair computeDiameter(List<Point> points) {
8384
double maxDistance = 0.0;
8485

8586
int j = 1;
87+
// Indexed loop required for rotating calipers algorithm
8688
for (int i = 0; i < n; i++) {
8789
Point p1 = hull.get(i);
8890

@@ -116,7 +118,7 @@ public static PointPair computeDiameter(List<Point> points) {
116118
* @return The minimum width of the polygon
117119
* @throws IllegalArgumentException if points is null or has less than 2 points
118120
*/
119-
public static double computeWidth(List<Point> points) {
121+
public static double computeWidth(Collection<Point> points) {
120122
if (points == null || points.size() < 2) {
121123
throw new IllegalArgumentException("Points list must contain at least 2 points");
122124
}
@@ -158,7 +160,7 @@ public static double computeWidth(List<Point> points) {
158160
* @return Rectangle containing the minimum-area bounding rectangle
159161
* @throws IllegalArgumentException if points is null or has less than 2 points
160162
*/
161-
public static Rectangle computeMinimumAreaBoundingRectangle(List<Point> points) {
163+
public static Rectangle computeMinimumAreaBoundingRectangle(Collection<Point> points) {
162164
if (points == null || points.size() < 2) {
163165
throw new IllegalArgumentException("Points list must contain at least 2 points");
164166
}
@@ -284,6 +286,7 @@ private static List<Point> ensureCounterClockwiseOrder(List<Point> hull) {
284286

285287
Point bottomMost = hull.get(0);
286288
int bottomIndex = 0;
289+
// Must check all points to find the true bottommost point
287290
for (int i = 1; i < hull.size(); i++) {
288291
Point p = hull.get(i);
289292
if (p.y() < bottomMost.y() || (p.y() == bottomMost.y() && p.x() < bottomMost.x())) {

0 commit comments

Comments
 (0)