@@ -15,10 +15,10 @@ private RotatingCalipers() {
15
15
}
16
16
17
17
// -------------------- Inner Classes --------------------
18
- public record PointPair (Point p1 , Point p2 , double distance ) {
18
+ public static record PointPair (Point p1 , Point p2 , double distance ) {
19
19
}
20
20
21
- public record Rectangle (Point [] corners , double width , double height , double area ) {
21
+ public static record Rectangle (Point [] corners , double width , double height , double area ) {
22
22
}
23
23
24
24
// -------------------- Diameter --------------------
@@ -86,19 +86,13 @@ public static double width(List<Point> points) {
86
86
87
87
double minProjV = Double .MAX_VALUE ;
88
88
double maxProjV = -Double .MAX_VALUE ;
89
+
89
90
for (Point p : hull ) {
90
91
double projV = p .x () * vx + p .y () * vy ;
91
- if (projV < minProjV ) {
92
- minProjV = projV ;
93
- }
94
- if (projV > maxProjV ) {
95
- maxProjV = projV ;
96
- }
97
- }
98
- double width = maxProjV - minProjV ;
99
- if (width < minWidth ) {
100
- minWidth = width ;
92
+ minProjV = Math .min (minProjV , projV );
93
+ maxProjV = Math .max (maxProjV , projV );
101
94
}
95
+ minWidth = Math .min (minWidth , maxProjV - minProjV );
102
96
}
103
97
return minWidth ;
104
98
}
@@ -138,18 +132,10 @@ public static Rectangle minAreaBoundingRectangle(List<Point> points) {
138
132
for (Point p : hull ) {
139
133
double projU = p .x () * ux + p .y () * uy ;
140
134
double projV = p .x () * vx + p .y () * vy ;
141
- if (projU < minU ) {
142
- minU = projU ;
143
- }
144
- if (projU > maxU ) {
145
- maxU = projU ;
146
- }
147
- if (projV < minV ) {
148
- minV = projV ;
149
- }
150
- if (projV > maxV ) {
151
- maxV = projV ;
152
- }
135
+ minU = Math .min (minU , projU );
136
+ maxU = Math .max (maxU , projU );
137
+ minV = Math .min (minV , projV );
138
+ maxV = Math .max (maxV , projV );
153
139
}
154
140
155
141
double width = maxU - minU ;
@@ -160,8 +146,12 @@ public static Rectangle minAreaBoundingRectangle(List<Point> points) {
160
146
minArea = area ;
161
147
bestWidth = width ;
162
148
bestHeight = height ;
163
- bestCorners = new Point [] {new Point ((int ) (ux * minU + vx * minV ), (int ) (uy * minU + vy * minV )), new Point ((int ) (ux * maxU + vx * minV ), (int ) (uy * maxU + vy * minV )), new Point ((int ) (ux * maxU + vx * maxV ), (int ) (uy * maxU + vy * maxV )),
164
- new Point ((int ) (ux * minU + vx * maxV ), (int ) (uy * minU + vy * maxV ))};
149
+ bestCorners = new Point [] {
150
+ new Point ((int )(ux * minU + vx * minV ), (int )(uy * minU + vy * minV )),
151
+ new Point ((int )(ux * maxU + vx * minV ), (int )(uy * maxU + vy * minV )),
152
+ new Point ((int )(ux * maxU + vx * maxV ), (int )(uy * maxU + vy * maxV )),
153
+ new Point ((int )(ux * minU + vx * maxV ), (int )(uy * minU + vy * maxV ))
154
+ };
165
155
}
166
156
}
167
157
0 commit comments