Skip to content

Commit d2e4c63

Browse files
committed
format
1 parent 6956c15 commit d2e4c63

File tree

16 files changed

+366
-311
lines changed

16 files changed

+366
-311
lines changed

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<name>Clipper2</name>
99
<properties>
1010
<jmh.version>1.35</jmh.version>
11+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1112
</properties>
1213
<build>
1314
<plugins>

src/main/java/clipper2/Clipper.java

Lines changed: 114 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package clipper2;
22

3+
import java.util.ArrayList;
4+
import java.util.Arrays;
5+
import java.util.Collections;
6+
import java.util.List;
7+
38
import clipper2.core.ClipType;
49
import clipper2.core.FillRule;
510
import clipper2.core.InternalClipper;
@@ -26,16 +31,12 @@
2631
import clipper2.rectclip.RectClip;
2732
import clipper2.rectclip.RectClipLines;
2833

29-
import java.util.ArrayList;
30-
import java.util.Arrays;
31-
import java.util.Collections;
32-
import java.util.List;
33-
3434
public final class Clipper {
3535

3636
public static final Rect64 MaxInvalidRect64 = new Rect64(Long.MAX_VALUE, Long.MAX_VALUE, Long.MIN_VALUE, Long.MIN_VALUE);
3737

38-
public static final RectD MaxInvalidRectD = new RectD(Double.MAX_VALUE, Double.MAX_VALUE, -Double.MAX_VALUE, -Double.MAX_VALUE);
38+
public static final RectD MaxInvalidRectD = new RectD(Double.MAX_VALUE, Double.MAX_VALUE, -Double.MAX_VALUE,
39+
-Double.MAX_VALUE);
3940
private static final String PRECISION_RANGE_ERROR = "Error: Precision is out of range.";
4041

4142
public static Paths64 Intersect(Paths64 subject, Paths64 clip, FillRule fillRule) {
@@ -145,7 +146,7 @@ public static Paths64 InflatePaths(Paths64 paths, double delta, JoinType joinTyp
145146
* <p>
146147
* Caution: Offsetting self-intersecting polygons may produce unexpected
147148
* results.
148-
*
149+
*
149150
* @param paths
150151
* @param delta With closed paths (polygons), a positive <code>delta</code>
151152
* specifies how much outer polygon contours will expand and
@@ -184,7 +185,8 @@ public static PathsD InflatePaths(PathsD paths, double delta, JoinType joinType,
184185
return InflatePaths(paths, delta, joinType, endType, 2.0, 2);
185186
}
186187

187-
public static PathsD InflatePaths(PathsD paths, double delta, JoinType joinType, EndType endType, double miterLimit, int precision) {
188+
public static PathsD InflatePaths(PathsD paths, double delta, JoinType joinType, EndType endType, double miterLimit,
189+
int precision) {
188190
if (precision < -8 || precision > 8) {
189191
throw new IllegalArgumentException(PRECISION_RANGE_ERROR);
190192
}
@@ -196,43 +198,48 @@ public static PathsD InflatePaths(PathsD paths, double delta, JoinType joinType,
196198
return ScalePathsD(tmp, 1 / scale);
197199
}
198200

199-
public static Path64 RectClip(Rect64 rect, Path64 path)
200-
{
201-
if (rect.IsEmpty() || path.isEmpty()) return new Path64();
201+
public static Path64 RectClip(Rect64 rect, Path64 path) {
202+
if (rect.IsEmpty() || path.isEmpty()) {
203+
return new Path64();
204+
}
202205
RectClip rc = new RectClip(rect);
203206
return rc.ExecuteInternal(path);
204207
}
205208

206-
public static Paths64 RectClip(Rect64 rect, Paths64 paths)
207-
{
208-
if (rect.IsEmpty() || paths.isEmpty()) return new Paths64();
209+
public static Paths64 RectClip(Rect64 rect, Paths64 paths) {
210+
if (rect.IsEmpty() || paths.isEmpty()) {
211+
return new Paths64();
212+
}
209213

210214
Paths64 result = new Paths64(paths.size());
211215
RectClip rc = new RectClip(rect);
212216
for (Path64 path : paths) {
213217
Rect64 pathRec = GetBounds(path);
214-
if (!rect.Intersects(pathRec))
218+
if (!rect.Intersects(pathRec)) {
215219
continue;
216-
else if (rect.Contains(pathRec))
220+
} else if (rect.Contains(pathRec)) {
217221
result.add(path);
218-
else
219-
{
222+
} else {
220223
Path64 p = rc.ExecuteInternal(path);
221-
if (p.size() > 0) result.add(p);
224+
if (p.size() > 0) {
225+
result.add(p);
226+
}
222227
}
223228
}
224229
return result;
225230
}
226231

227-
public static PathD RectClip(RectD rect, PathD path){
232+
public static PathD RectClip(RectD rect, PathD path) {
228233
return RectClip(rect, path, 2);
229234
}
230235

231-
public static PathD RectClip(RectD rect, PathD path, int precision)
232-
{
233-
if (precision < -8 || precision > 8)
236+
public static PathD RectClip(RectD rect, PathD path, int precision) {
237+
if (precision < -8 || precision > 8) {
234238
throw new IllegalArgumentException(PRECISION_RANGE_ERROR);
235-
if (rect.IsEmpty() || path.size() == 0) return new PathD();
239+
}
240+
if (rect.IsEmpty() || path.size() == 0) {
241+
return new PathD();
242+
}
236243
double scale = Math.pow(10, precision);
237244
Rect64 r = ScaleRect(rect, scale);
238245
Path64 tmpPath = ScalePath64(path, scale);
@@ -241,105 +248,114 @@ public static PathD RectClip(RectD rect, PathD path, int precision)
241248
return ScalePathD(tmpPath, 1 / scale);
242249
}
243250

244-
public static PathsD RectClip(RectD rect, PathsD paths)
245-
{
251+
public static PathsD RectClip(RectD rect, PathsD paths) {
246252
return RectClip(rect, paths, 2);
247253
}
248254

249-
public static PathsD RectClip(RectD rect, PathsD paths, int precision)
250-
{
251-
if (precision < -8 || precision > 8)
255+
public static PathsD RectClip(RectD rect, PathsD paths, int precision) {
256+
if (precision < -8 || precision > 8) {
252257
throw new IllegalArgumentException(PRECISION_RANGE_ERROR);
253-
if (rect.IsEmpty() || paths.size() == 0) return new PathsD();
258+
}
259+
if (rect.IsEmpty() || paths.size() == 0) {
260+
return new PathsD();
261+
}
254262
double scale = Math.pow(10, precision);
255263
Rect64 r = ScaleRect(rect, scale);
256264
RectClip rc = new RectClip(r);
257265
PathsD result = new PathsD(paths.size());
258266
for (PathD p : paths) {
259267
RectD pathRec = GetBounds(p);
260-
if (!rect.Intersects(pathRec))
268+
if (!rect.Intersects(pathRec)) {
261269
continue;
262-
else if (rect.Contains(pathRec))
270+
} else if (rect.Contains(pathRec)) {
263271
result.add(p);
264-
else
265-
{
272+
} else {
266273
Path64 p64 = ScalePath64(p, scale);
267274
p64 = rc.ExecuteInternal(p64);
268-
if (p64.size() > 0)
275+
if (p64.size() > 0) {
269276
result.add(ScalePathD(p64, 1 / scale));
277+
}
270278
}
271279
}
272280
return result;
273281
}
274-
public static Paths64 RectClipLines(Rect64 rect, Path64 path)
275-
{
276-
if (rect.IsEmpty() || path.size() == 0) return new Paths64();
282+
283+
public static Paths64 RectClipLines(Rect64 rect, Path64 path) {
284+
if (rect.IsEmpty() || path.size() == 0) {
285+
return new Paths64();
286+
}
277287
RectClipLines rco = new RectClipLines(rect);
278288
return rco.NewExecuteInternal(path);
279289
}
280290

281-
public static Paths64 RectClipLines(Rect64 rect, Paths64 paths)
282-
{
291+
public static Paths64 RectClipLines(Rect64 rect, Paths64 paths) {
283292
Paths64 result = new Paths64(paths.size());
284-
if (rect.IsEmpty() || paths.size() == 0) return result;
293+
if (rect.IsEmpty() || paths.size() == 0) {
294+
return result;
295+
}
285296
RectClipLines rco = new RectClipLines(rect);
286297
for (Path64 path : paths) {
287298
Rect64 pathRec = GetBounds(path);
288-
if (!rect.Intersects(pathRec))
299+
if (!rect.Intersects(pathRec)) {
289300
continue;
290-
else if (rect.Contains(pathRec))
301+
} else if (rect.Contains(pathRec)) {
291302
result.add(path);
292-
else
293-
{
303+
} else {
294304
Paths64 pp = rco.NewExecuteInternal(path);
295-
if (pp.size() > 0) result.addAll(pp);
305+
if (pp.size() > 0) {
306+
result.addAll(pp);
307+
}
296308
}
297309
}
298310
return result;
299311
}
300312

301-
public static PathsD RectClipLines(RectD rect, PathD path)
302-
{
313+
public static PathsD RectClipLines(RectD rect, PathD path) {
303314
return RectClipLines(rect, path, 2);
304315
}
305316

306-
public static PathsD RectClipLines(RectD rect, PathD path, int precision)
307-
{
308-
if (precision < -8 || precision > 8)
317+
public static PathsD RectClipLines(RectD rect, PathD path, int precision) {
318+
if (precision < -8 || precision > 8) {
309319
throw new IllegalArgumentException(PRECISION_RANGE_ERROR);
310-
if (rect.IsEmpty() || path.size() == 0) return new PathsD();
320+
}
321+
if (rect.IsEmpty() || path.size() == 0) {
322+
return new PathsD();
323+
}
311324
double scale = Math.pow(10, precision);
312325
Rect64 r = ScaleRect(rect, scale);
313326
Path64 tmpPath = ScalePath64(path, scale);
314327
RectClipLines rco = new RectClipLines(r);
315328
Paths64 tmpPaths = rco.NewExecuteInternal(tmpPath);
316329
return ScalePathsD(tmpPaths, 1 / scale);
317330
}
318-
public static PathsD RectClipLines(RectD rect, PathsD paths)
319-
{
331+
332+
public static PathsD RectClipLines(RectD rect, PathsD paths) {
320333
return RectClipLines(rect, paths, 2);
321334
}
322335

323-
public static PathsD RectClipLines(RectD rect, PathsD paths, int precision)
324-
{
325-
if (precision < -8 || precision > 8)
336+
public static PathsD RectClipLines(RectD rect, PathsD paths, int precision) {
337+
if (precision < -8 || precision > 8) {
326338
throw new IllegalArgumentException(PRECISION_RANGE_ERROR);
339+
}
327340
PathsD result = new PathsD(paths.size());
328-
if (rect.IsEmpty() || paths.size() == 0) return result;
341+
if (rect.IsEmpty() || paths.size() == 0) {
342+
return result;
343+
}
329344
double scale = Math.pow(10, precision);
330345
Rect64 r = ScaleRect(rect, scale);
331346
RectClipLines rco = new RectClipLines(r);
332347
for (PathD p : paths) {
333348
RectD pathRec = GetBounds(p);
334-
if (!rect.Intersects(pathRec))
349+
if (!rect.Intersects(pathRec)) {
335350
continue;
336-
else if (rect.Contains(pathRec))
351+
} else if (rect.Contains(pathRec)) {
337352
result.add(p);
338-
else
339-
{
353+
} else {
340354
Path64 p64 = ScalePath64(p, scale);
341355
Paths64 pp64 = rco.NewExecuteInternal(p64);
342-
if (pp64.size() == 0) continue;
356+
if (pp64.size() == 0) {
357+
continue;
358+
}
343359
PathsD ppd = ScalePathsD(pp64, 1 / scale);
344360
result.addAll(ppd);
345361
}
@@ -361,7 +377,7 @@ public static Paths64 MinkowskiDiff(Path64 pattern, Path64 path, boolean isClose
361377
* orientation, this value may be positive or negative. If the winding is
362378
* clockwise, then the area will be positive and conversely, if winding is
363379
* counter-clockwise, then the area will be negative.
364-
*
380+
*
365381
* @param path
366382
* @return
367383
*/
@@ -386,7 +402,7 @@ public static double Area(Path64 path) {
386402
* orientation, this value may be positive or negative. If the winding is
387403
* clockwise, then the area will be positive and conversely, if winding is
388404
* counter-clockwise, then the area will be negative.
389-
*
405+
*
390406
* @param paths
391407
* @return
392408
*/
@@ -506,14 +522,9 @@ public static PointD ScalePointD(Point64 pt, double scale) {
506522
return result;
507523
}
508524

509-
public static Rect64 ScaleRect(RectD rec, double scale)
510-
{
511-
Rect64 result = new Rect64(
512-
(long) (rec.left * scale),
513-
(long) (rec.top * scale),
514-
(long) (rec.right * scale),
515-
(long) (rec.bottom * scale)
516-
);
525+
public static Rect64 ScaleRect(RectD rec, double scale) {
526+
Rect64 result = new Rect64((long) (rec.left * scale), (long) (rec.top * scale), (long) (rec.right * scale),
527+
(long) (rec.bottom * scale));
517528
return result;
518529
}
519530

@@ -692,26 +703,40 @@ public static PathsD ReversePaths(PathsD paths) {
692703
return result;
693704
}
694705

695-
public static Rect64 GetBounds(Path64 path)
696-
{
706+
public static Rect64 GetBounds(Path64 path) {
697707
Rect64 result = MaxInvalidRect64;
698708
for (Point64 pt : path) {
699-
if (pt.x < result.left) result.left = pt.x;
700-
if (pt.x > result.right) result.right = pt.x;
701-
if (pt.y < result.top) result.top = pt.y;
702-
if (pt.y > result.bottom) result.bottom = pt.y;
709+
if (pt.x < result.left) {
710+
result.left = pt.x;
711+
}
712+
if (pt.x > result.right) {
713+
result.right = pt.x;
714+
}
715+
if (pt.y < result.top) {
716+
result.top = pt.y;
717+
}
718+
if (pt.y > result.bottom) {
719+
result.bottom = pt.y;
720+
}
703721
}
704722
return result.IsEmpty() ? new Rect64() : result;
705723
}
706724

707-
public static RectD GetBounds(PathD path)
708-
{
725+
public static RectD GetBounds(PathD path) {
709726
RectD result = MaxInvalidRectD;
710727
for (PointD pt : path) {
711-
if (pt.x < result.left) result.left = pt.x;
712-
if (pt.x > result.right) result.right = pt.x;
713-
if (pt.y < result.top) result.top = pt.y;
714-
if (pt.y > result.bottom) result.bottom = pt.y;
728+
if (pt.x < result.left) {
729+
result.left = pt.x;
730+
}
731+
if (pt.x > result.right) {
732+
result.right = pt.x;
733+
}
734+
if (pt.y < result.top) {
735+
result.top = pt.y;
736+
}
737+
if (pt.y > result.bottom) {
738+
result.bottom = pt.y;
739+
}
715740
}
716741
return result.IsEmpty() ? new RectD() : result;
717742
}
@@ -927,7 +952,7 @@ public static void RDP(Path64 path, int begin, int end, double epsSqrd, List<Boo
927952
* segments. These segments don't enhance curve quality, but they will slow path
928953
* processing (whether during file storage, or when rendering, or in subsequent
929954
* offsetting procedures).
930-
*
955+
*
931956
* @param path
932957
* @param epsilon
933958
* @return
@@ -963,7 +988,7 @@ public static Path64 RamerDouglasPeuckerPath(Path64 path, double epsilon) {
963988
* segments. These segments don't enhance curve quality, but they will slow path
964989
* processing (whether during file storage, or when rendering, or in subsequent
965990
* offsetting procedures).
966-
*
991+
*
967992
* @param paths
968993
* @param epsilon
969994
* @return
@@ -1086,8 +1111,8 @@ public static Path64 TrimCollinear(Path64 path, boolean isOpen) {
10861111
} else if (InternalClipper.CrossProduct(last, path.get(len - 1), result.get(0)) != 0) {
10871112
result.add(path.get(len - 1));
10881113
} else {
1089-
while (result.size() > 2
1090-
&& InternalClipper.CrossProduct(result.get(result.size() - 1), result.get(result.size() - 2), result.get(0)) == 0) {
1114+
while (result.size() > 2 && InternalClipper.CrossProduct(result.get(result.size() - 1), result.get(result.size() - 2),
1115+
result.get(0)) == 0) {
10911116
result.remove(result.size() - 1);
10921117
}
10931118
if (result.size() < 3) {

0 commit comments

Comments
 (0)