Skip to content

Commit 502dfe0

Browse files
committed
javadocs
1 parent fbe6a22 commit 502dfe0

File tree

3 files changed

+115
-14
lines changed

3 files changed

+115
-14
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>micycle</groupId>
66
<artifactId>clipper2</artifactId>
7-
<version>1.2.4-SNAPSHOT</version>
7+
<version>1.2.4</version>
88
<name>Clipper2</name>
99
<properties>
1010
<jmh.version>1.36</jmh.version>

src/main/java/clipper2/Clipper.java

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,64 @@
3131
import clipper2.rectclip.RectClip64;
3232
import clipper2.rectclip.RectClipLines64;
3333

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+
*/
3492
public final class Clipper {
3593

3694
public static final Rect64 InvalidRect64 = new Rect64(false);
@@ -107,6 +165,10 @@ public static Paths64 BooleanOp(ClipType clipType, Paths64 subject, Paths64 clip
107165
return solution;
108166
}
109167

168+
/**
169+
* This function is a generic alternative to the Intersect, Difference, Union
170+
* and XOR functions.
171+
*/
110172
public static void BooleanOp(ClipType clipType, @Nullable Paths64 subject, @Nullable Paths64 clip, PolyTree64 polytree, FillRule fillRule) {
111173
if (subject == null) {
112174
return;
@@ -123,6 +185,16 @@ public static PathsD BooleanOp(ClipType clipType, PathsD subject, PathsD clip, F
123185
return BooleanOp(clipType, subject, clip, fillRule, 2);
124186
}
125187

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+
*/
126198
public static PathsD BooleanOp(ClipType clipType, PathsD subject, @Nullable PathsD clip, FillRule fillRule, int precision) {
127199
PathsD solution = new PathsD();
128200
ClipperD c = new ClipperD(precision);

src/main/java/clipper2/offset/ClipperOffset.java

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,51 @@
2424
import tangible.RefObject;
2525

2626
/**
27-
* Geometric offsetting refers to the process of creating parallel curves that
28-
* are offset a specified distance from their primary curves.
27+
* Manages the process of offsetting (inflating/deflating) both open and closed
28+
* paths using different join types and end types.
2929
* <p>
30-
* The ClipperOffset class manages the process of offsetting
31-
* (inflating/deflating) both open and closed paths using a number of different
32-
* join types and end types. The library user will rarely need to access this
33-
* unit directly since it will generally be easier to use the
34-
* {@link Clipper#InflatePaths(Paths64, double, JoinType, EndType)
35-
* InflatePaths()} function when doing polygon offsetting.
30+
* Geometric <b>offsetting</b> refers to the process of creating <b>parallel
31+
* curves</b> that are offset a specified distance from their primary curves.
3632
* <p>
37-
* Caution: Offsetting self-intersecting polygons may produce unexpected
38-
* results.
33+
* Library users will rarely need to access this class directly since it's
34+
* generally easier to use the {@link Clipper#InflatePaths(Paths64, double, JoinType, EndType)
35+
* InflatePaths()} function for polygon
36+
* offsetting.
3937
* <p>
40-
* Note: When inflating polygons, it's important that you select
41-
* {@link EndType#Polygon}. If you select one of the open path end types instead
42-
* (including EndType.Join), you'll simply inflate the polygon's outline.
38+
* <b>Notes:</b>
39+
* <ul>
40+
* <li>When offsetting <i>closed</i> paths (polygons), a positive offset delta
41+
* specifies how much outer polygon contours will expand and inner "hole"
42+
* contours will contract. The converse occurs with negative deltas.</li>
43+
* <li>You cannot offset <i>open</i> paths (polylines) with negative deltas
44+
* because it's not possible to contract/shrink open paths.</li>
45+
* <li>When offsetting, it's important not to confuse <b>EndType.Polygon</b>
46+
* with <b>EndType.Joined</b>. <b>EndType.Polygon</b> should be used when
47+
* offsetting polygons (closed paths). <b>EndType.Joined</b> should be used with
48+
* polylines (open paths).</li>
49+
* <li>Offsetting should <b>not</b> be performed on <b>intersecting closed
50+
* paths</b>, as doing so will almost always produce undesirable results.
51+
* Intersections must be removed before offsetting, which can be achieved
52+
* through a <b>Union</b> clipping operation.</li>
53+
* <li>It is OK to offset self-intersecting open paths (polylines), though the
54+
* intersecting (overlapping) regions will be flattened in the solution
55+
* polygon.</li>
56+
* <li>When offsetting closed paths (polygons), the <b>winding direction</b> of
57+
* paths in the solution will match that of the paths prior to offsetting.
58+
* Polygons with hole regions should comply with <b>NonZero filling</b>.</li>
59+
* <li>When offsetting open paths (polylines), the solutions will always have
60+
* <b>Positive orientation</b>.</li>
61+
* <li>Path <b>order</b> following offsetting very likely <i>won't</i> match
62+
* path order prior to offsetting.</li>
63+
* <li>While the ClipperOffset class itself won't accept paths with floating
64+
* point coordinates, the <b>InflatePaths</b> function will accept paths with
65+
* floating point coordinates.</li>
66+
* <li>Redundant segments should be removed before offsetting (see
67+
* {@link Clipper#SimplifyPaths(Paths64, double)
68+
* SimplifyPaths()}), and between offsetting operations too. These redundant
69+
* segments not only slow down offsetting, but they can cause unexpected
70+
* blemishes in offset solutions.</li>
71+
* </ul>
4372
*/
4473
public class ClipperOffset {
4574

0 commit comments

Comments
 (0)