|
1 | 1 | [](https://jitpack.io/#micycle1/Clipper2-java) |
2 | 2 |
|
3 | | - |
4 | 3 | # Clipper2-java |
5 | | -A Java port of _[Clipper2](https://github.com/AngusJohnson/Clipper2)_, an open source freeware software library that performs line and polygon clipping, and offsetting. |
| 4 | +A Java port of _[Clipper2](https://github.com/AngusJohnson/Clipper2)_, an open source freeware library that performs robust 2D line and polygon clipping, and offsetting. |
| 5 | + |
| 6 | +## What is Clipper2-java? |
| 7 | + |
| 8 | +Clipper2-java is a fast planar geometry library for: |
| 9 | + |
| 10 | +- **Boolean clipping** of polygons and polylines: `Intersection`, `Union`, `Difference`, `Xor` |
| 11 | +- **Offsetting / buffering** (inflate/deflate) of closed polygons and open polylines (`ClipperOffset` / `Clipper.InflatePaths`) |
| 12 | +- **Rectangle clipping** for polygons and polylines (`RectClip`, `RectClipLines`) |
| 13 | +- **Minkowski sum/difference** |
| 14 | +- Utilities: area, bounds, orientation, simplification (RDP), trimming duplicates/collinear vertices |
6 | 15 |
|
7 | 16 | ## Usage |
8 | 17 |
|
9 | 18 | ### Overview |
10 | 19 |
|
11 | | -The interface of *Clipper2-java* is identical to the original C# version. |
| 20 | +The interface of *Clipper2-java* aims to match the original C# version closely. |
12 | 21 |
|
13 | | -The `Clipper` class provides static methods for clipping, path-offsetting, minkowski-sums and path simplification. |
14 | | -For more complex clipping operations (e.g. when clipping open paths or when outputs are expected to include polygons nested within holes of others), use the `Clipper64` or `ClipperD` classes directly. |
| 22 | +For simple use cases, the static methods in `clipper2.Clipper` are sufficient. |
15 | 23 |
|
16 | | -### Maven |
17 | | -*Clipper2-java* is available as Maven/Gradle artifact via [Jitpack](https://jitpack.io/#micycle1/Clipper2-java). |
| 24 | +For advanced scenarios (open paths, PolyTree nesting, reusing engines), use `Clipper64` / `ClipperD` directly. |
18 | 25 |
|
19 | | -### Example |
| 26 | +### Coordinates & precision |
20 | 27 |
|
21 | | -```java |
22 | | -Paths64 subj = new Paths64(); |
23 | | -Paths64 clip = new Paths64(); |
24 | | -subj.add(Clipper.MakePath(new int[] { 100, 50, 10, 79, 65, 2, 65, 98, 10, 21 })); |
25 | | -clip.add(Clipper.MakePath(new int[] { 98, 63, 4, 68, 77, 8, 52, 100, 19, 12 })); |
26 | | -Paths64 solution = Clipper.Union(subj, clip, FillRule.NonZero); |
27 | | -solution.get(0).forEach(p -> System.out.println(p.toString())); |
28 | | -``` |
| 28 | +Clipper2’s core algorithms operate on **integer coordinates** for numerical robustness. |
| 29 | + |
| 30 | +- Use **`Path64` / `Paths64`** (with `long` coordinates) for best performance and robustness. |
| 31 | +- Use **`PathD` / `PathsD`** (with `double` coordinates) for convenience. These are **scaled and rounded to integers internally** using a user-specified precision. |
| 32 | + |
| 33 | +### Installation (Maven / Gradle) |
29 | 34 |
|
| 35 | +*Clipper2-java* is available as a Maven/Gradle artifact via [Jitpack](https://jitpack.io/#micycle1/Clipper2-java). |
30 | 36 |
|
31 | 37 | ## Port Info |
32 | 38 | * _tangiblesoftwaresolutions_' C# to Java Converter did the heavy lifting (but then a lot of manual work was required). |
|
0 commit comments