31
31
import clipper2 .rectclip .RectClip64 ;
32
32
import clipper2 .rectclip .RectClipLines64 ;
33
33
34
+ /**
35
+ * Line and polygon clipping, and offsetting.
36
+ * <p>
37
+ * This unit has been designed to hide the library's complexities behind a
38
+ * number of simple functions. However, not all of the library's features are
39
+ * accessible here. Less commonly needed features that provide more flexibility
40
+ * can still be accessed from the other units.
41
+ * <p>
42
+ * <h2>Boolean operations for polygon clipping:</h2>
43
+ * <ul>
44
+ * <li><b>AND (intersection)</b> - regions covered by both subject and clip
45
+ * polygons</li>
46
+ * <li><b>OR (union)</b> - regions covered by subject or clip polygons, or both
47
+ * polygons</li>
48
+ * <li><b>NOT (difference)</b> - regions covered by subject, but not clip
49
+ * polygons</li>
50
+ * <li><b>XOR (exclusive or)</b> - regions covered by subject or clip polygons,
51
+ * but not both</li>
52
+ * </ul>
53
+ * Of these four operations, only <code>difference</code> is non-commutative.
54
+ * This means that <code>subject</code> and <code>clip</code> paths are
55
+ * interchangeable except when performing difference operations (and as long as
56
+ * subject paths are closed).
57
+ * <p>
58
+ * All polygon clipping is performed with a Clipper object with the specific
59
+ * boolean operation indicated by the <code>ClipType</code> parameter passed in
60
+ * its Execute method. With regard to <b>open</b> paths (polylines), clipping
61
+ * rules generally match those of closed paths (polygons). However, when there
62
+ * are both polyline and polygon subjects, the following clipping rules apply:
63
+ * </p>
64
+ *
65
+ * <ul>
66
+ * <li><b>union operations</b> - polylines will be clipped by <b>any</b>
67
+ * overlapping polygons so that only non-overlapped portions will be returned in
68
+ * the solution, together with solution polygons</li>
69
+ * <li><b>intersection, difference and xor operations</b> - polylines will be
70
+ * clipped by 'clip' polygons, and there will be no interaction between
71
+ * polylines and any subject polygons</li>
72
+ * </ul>
73
+ *
74
+ * <h2>Polygon Offsetting:</h2>
75
+ * <p>
76
+ * Geometric offsetting refers to the process of creating parallel curves that
77
+ * are offset a specified distance from their starting positions.
78
+ * <p>
79
+ * While all offsetting is performed by the <code>ClipperOffset</code> class in
80
+ * the <code>Clipper.Offset</code> unit, the complexities of constructing and
81
+ * using this class can usually be avoided by using instead the
82
+ * {@link #InflatePaths(PathsD, double, JoinType, EndType, double, double, int)
83
+ * InflatePaths()} function in this class. This function can both inflate and
84
+ * shrink polygons (using positive and negative offsets respectively).
85
+ * Offsetting can be performed using a number of JoinTypes and EndTypes. While
86
+ * both open paths and closed paths can be offset, logically only closed paths
87
+ * can be shrunk (ie with negative offsets).
88
+ * <p>
89
+ * Note: Offsetting shouldn't be confused with the process of polygon
90
+ * <i>translation</i>.
91
+ */
34
92
public final class Clipper {
35
93
36
94
public static final Rect64 InvalidRect64 = new Rect64 (false );
@@ -107,6 +165,10 @@ public static Paths64 BooleanOp(ClipType clipType, Paths64 subject, Paths64 clip
107
165
return solution ;
108
166
}
109
167
168
+ /**
169
+ * This function is a generic alternative to the Intersect, Difference, Union
170
+ * and XOR functions.
171
+ */
110
172
public static void BooleanOp (ClipType clipType , @ Nullable Paths64 subject , @ Nullable Paths64 clip , PolyTree64 polytree , FillRule fillRule ) {
111
173
if (subject == null ) {
112
174
return ;
@@ -123,6 +185,16 @@ public static PathsD BooleanOp(ClipType clipType, PathsD subject, PathsD clip, F
123
185
return BooleanOp (clipType , subject , clip , fillRule , 2 );
124
186
}
125
187
188
+ /**
189
+ * This function is a generic alternative to the Intersect, Difference, Union
190
+ * and XOR functions.
191
+ *
192
+ * @param clipType
193
+ * @param subject
194
+ * @param clip
195
+ * @param fillRule
196
+ * @param precision The desired coordinate precision (up to 8 decimal places).
197
+ */
126
198
public static PathsD BooleanOp (ClipType clipType , PathsD subject , @ Nullable PathsD clip , FillRule fillRule , int precision ) {
127
199
PathsD solution = new PathsD ();
128
200
ClipperD c = new ClipperD (precision );
0 commit comments