Skip to content

Commit 64fbbb5

Browse files
Add stroking and cleanup.
1 parent 96d70e4 commit 64fbbb5

28 files changed

Lines changed: 4417 additions & 1786 deletions

‎PolygonClipper.sln‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1717
.gitattributes = .gitattributes
1818
.gitignore = .gitignore
1919
reference\10.1016@j.advengsoft.2013.04.004.pdf = reference\10.1016@j.advengsoft.2013.04.004.pdf
20+
reference\129902.129906.pdf = reference\129902.129906.pdf
2021
ci-build.ps1 = ci-build.ps1
2122
ci-pack.ps1 = ci-pack.ps1
2223
ci-test.ps1 = ci-test.ps1

‎README.md‎

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ SixLabors.PolygonClipper
1313

1414
</div>
1515

16-
SixLabors.PolygonClipper provides boolean operations on polygons in C# using a Martínez-Rueda sweep-line implementation. It supports union, intersection, difference, and xor on complex polygons with holes and multiple contours. Self-intersection normalization is provided via a separate Clipper2-inspired pipeline.
16+
SixLabors.PolygonClipper provides high-performance polygon clipping and stroking in C#.
17+
Boolean operations (union, intersection, difference, xor) are implemented with a Martinez-Rueda sweep-line pipeline for complex polygons with holes and multiple contours.
18+
Self-intersection normalization is handled by a dedicated Vatti/Clipper2-inspired remover, and `PolygonStroker` builds stroke geometry on top of that normalization path.
1719

1820
## Features
1921

@@ -22,14 +24,15 @@ SixLabors.PolygonClipper provides boolean operations on polygons in C# using a M
2224
- Preserves topology: output polygons include hole/contour hierarchy
2325
- Deterministic and robust sweep line algorithm with O((n + k) log n) complexity
2426
- Includes self-intersection removal (Clipper2-inspired) to normalize input contours for boolean operations
27+
- Includes `PolygonStroker` for configurable geometric stroking (joins, caps, miter limits)
2528
- Uses double precision geometry without coordinate quantization
2629

2730
## Usage
2831

29-
The API centers around `Polygon` and `Contour` types. Construct input polygons using contours, then apply Boolean operations via the `PolygonClipper` class:
32+
The API centers around `Polygon` and `Contour` types. Construct input polygons using contours, then apply Boolean operations via `PolygonClipper`:
3033

3134
```csharp
32-
Polygon result = PolygonClipper.Intersection(subject, clipping);
35+
Polygon result = PolygonClipper.Union(subject, clipping);
3336
```
3437

3538
You can also normalize input before boolean operations if your contours contain self-intersections:
@@ -38,17 +41,40 @@ You can also normalize input before boolean operations if your contours contain
3841
Polygon clean = PolygonClipper.RemoveSelfIntersections(input);
3942
```
4043

44+
### Stroking
45+
46+
Use `PolygonStroker` to generate filled stroke polygons from input contours:
47+
48+
```csharp
49+
Polygon stroked = PolygonStroker.Stroke(input, width: 12);
50+
```
51+
52+
Configure join/cap behavior through `StrokeOptions`:
53+
54+
```csharp
55+
StrokeOptions options = new()
56+
{
57+
LineJoin = LineJoin.Round,
58+
LineCap = LineCap.Round,
59+
MiterLimit = 4,
60+
InnerMiterLimit = 1.01,
61+
ArcDetailScale = 1
62+
};
63+
64+
Polygon stroked = PolygonStroker.Stroke(input, width: 12, options);
65+
```
66+
4167
## Algorithm References
4268

4369
This project draws on the following algorithm and implementation references:
4470

45-
> F. Martínez et al., "A simple algorithm for Boolean operations on polygons", *Advances in Engineering Software*, 64 (2013), pp. 11-19.
71+
> F. Martinez et al., "A simple algorithm for Boolean operations on polygons", *Advances in Engineering Software*, 64 (2013), pp. 11-19.
4672
> https://doi.org/10.1016/j.advengsoft.2013.04.004
4773
4874
> B. R. Vatti, "A generic solution to polygon clipping", *Communications of the ACM*, 35(7), 1992, pp. 56-63.
4975
> https://dl.acm.org/doi/pdf/10.1145/129902.129906
5076
51-
> 21re, *rust-geo-booleanop* (Rust Martínez-Rueda implementation reference).
77+
> 21re, *rust-geo-booleanop* (Rust Martinez-Rueda implementation reference).
5278
> https://github.com/21re/rust-geo-booleanop
5379
5480
> Angus Johnson, *Clipper2* polygon clipping library (reference implementation for the self-intersection pipeline).

0 commit comments

Comments
 (0)