@@ -16,7 +16,24 @@ Boolean operations on polygons (union, intersection, difference, xor).
1616
1717# Installing
1818
19- TODO: Complete this section once published to 'central'.
19+ To use polybool-java, you need to use the following Maven dependency:
20+
21+ ``` xml
22+ <!-- Maven -->
23+ <dependency >
24+ <groupId >com.menecats</groupId >
25+ <artifactId >polybool-java</artifactId >
26+ <version >1.0.1</version >
27+ </dependency >
28+ ```
29+
30+ ``` groovy
31+ // Gradle (Groovy)
32+ implementation 'com.menecats:polybool-java:1.0.1'
33+ ```
34+
35+ or download jars from Maven repository (or via quick links on
36+ the [ Release page] ( https://github.com/Menecats/polybool-java/releases ) )
2037
2138# Example
2239
@@ -75,13 +92,13 @@ public class PolyBoolExample {
7592## Basic Usage
7693
7794``` java
78- Epsilon eps = new Epsilon ();
95+ Epsilon eps= new Epsilon ();
7996
80- Polygon poly = PolyBool . union(eps, poly1, poly2);
81- Polygon poly = PolyBool . intersect(eps, poly1, poly2);
82- Polygon poly = PolyBool . difference(eps, poly1, poly2); // poly1 - poly2
83- Polygon poly = PolyBool . differenceRev(eps, poly1, poly2); // poly2 - poly1
84- Polygon poly = PolyBool . xor(eps, poly1, poly2);
97+ Polygon poly= PolyBool . union(eps,poly1,poly2);
98+ Polygon poly= PolyBool . intersect(eps,poly1,poly2);
99+ Polygon poly= PolyBool . difference(eps,poly1,poly2); // poly1 - poly2
100+ Polygon poly= PolyBool . differenceRev(eps,poly1,poly2); // poly2 - poly1
101+ Polygon poly= PolyBool . xor(eps,poly1,poly2);
85102```
86103
87104Where ` poly1 ` , ` poly2 ` , and the return value are ` Polygon ` objects.
@@ -108,18 +125,18 @@ Only `"Polygon"` and `"MultiPolygon"` types are supported.
108125# Core API
109126
110127``` java
111- Epsilon eps = new Epsilon ();
128+ Epsilon eps= new Epsilon ();
112129
113- Segments segments = PolyBool . segments(eps, polygon);
114- Combined combined = PolyBool . combine(eps, segments1, segments2);
130+ Segments segments= PolyBool . segments(eps,polygon);
131+ Combined combined= PolyBool . combine(eps,segments1,segments2);
115132
116- Segments segments = PolyBool . selectUnion(combined);
117- Segments segments = PolyBool . selectIntersect(combined);
118- Segments segments = PolyBool . selectDifference(combined);
119- Segments segments = PolyBool . selectDifferenceRev(combined);
120- Segments segments = PolyBool . selectXor(combined);
133+ Segments segments= PolyBool . selectUnion(combined);
134+ Segments segments= PolyBool . selectIntersect(combined);
135+ Segments segments= PolyBool . selectDifference(combined);
136+ Segments segments= PolyBool . selectDifferenceRev(combined);
137+ Segments segments= PolyBool . selectXor(combined);
121138
122- Polygon polygon = PolyBool . polygon(eps, segments);
139+ Polygon polygon= PolyBool . polygon(eps,segments);
123140```
124141
125142Depending on your needs, it might be more efficient to construct your own sequence of operations
@@ -167,13 +184,13 @@ Instead, it's more efficient to use the core API directly, like this:
167184
168185``` java
169186// works AND efficient
170- Segments segments = PolyBool . segments(eps, polygons[0 ]);
171- for (int i = 1 ; i < polygons. length; i++ ) {
172- Segments seg2 = PolyBool . segments(eps, polygons[i]);
173- Combined comb = PolyBool . combine(eps, segments, seg2);
174- segments = PolyBool . selectUnion(comb);
175- }
176- return PolyBool . polygon(eps, segments);
187+ Segments segments= PolyBool . segments(eps,polygons[0 ]);
188+ for (int i= 1 ;i < polygons. length;i++ ){
189+ Segments seg2= PolyBool . segments(eps,polygons[i]);
190+ Combined comb= PolyBool . combine(eps,segments,seg2);
191+ segments = PolyBool . selectUnion(comb);
192+ }
193+ return PolyBool . polygon(eps,segments);
177194```
178195
179196## Advanced Example 2
@@ -223,14 +240,14 @@ be:
223240``` java
224241// union the polygon with nothing in order to clean up the data
225242// works but not efficient
226- Polygon cleaned = PolyBool . union(eps, polygon, new Polygon ());
243+ Polygon cleaned= PolyBool . union(eps,polygon,new Polygon ());
227244```
228245
229246Instead, skip the combination and selection phase:
230247
231248``` java
232249// works AND efficient
233- Polygon cleaned = PolyBool . polygon(eps, PolyBool . segments(eps, polygon));
250+ Polygon cleaned= PolyBool . polygon(eps,PolyBool . segments(eps,polygon));
234251```
235252
236253# Epsilon
@@ -242,39 +259,39 @@ exactly the same.
242259Normally you would expect this to work:
243260
244261``` java
245- if ( A == B ) {
246- /* A and B are equal */ ;
247- } else {
248- /* A and B are not equal */ ;
249- }
262+ if ( A == B ) {
263+ /* A and B are equal */ ;
264+ } else {
265+ /* A and B are not equal */ ;
266+ }
250267```
251268
252269But for inexact floating point math, instead we use:
253270
254271``` java
255- if (Math . abs(A - B ) < epsilon) {
256- /* A and B are equal */ ;
257- } else {
258- /* A and B are not equal */ ;
259- }
272+ if (Math . abs(A - B ) < epsilon){
273+ /* A and B are equal */ ;
274+ } else {
275+ /* A and B are not equal */ ;
276+ }
260277```
261278
262279You can set the epsilon while you invoke polybool functions by creating an ` Epsilon ` instance
263280
264281``` java
265- Epsilon eps = new Epsilon ();
282+ Epsilon eps= new Epsilon ();
266283
267- PolyBool . segments(eps, poly);
284+ PolyBool . segments(eps,poly);
268285```
269286
270287You can specify a custom epsilon value while you instantiate an ` Epsilon ` object or you can change it on an existing one
271288
272289``` java
273- Epsilon eps = new Epsilon (myCustomEpsilonValue);
290+ Epsilon eps= new Epsilon (myCustomEpsilonValue);
274291
275- eps. epsilon(anotherCustomEpsilonValue);
292+ eps. epsilon(anotherCustomEpsilonValue);
276293
277- PolyBool . segments(eps, poly);
294+ PolyBool . segments(eps,poly);
278295```
279296
280297The default epsilon value is ` 0.0000000001 (1e-10) ` .
0 commit comments