Skip to content

Commit b44cdbd

Browse files
author
Nemanja Jovanovic
committed
Add Weiler-Atherton clipping algorithm
Changes the default clipping algorithm for intersections.
1 parent e9037d0 commit b44cdbd

File tree

7 files changed

+546
-16
lines changed

7 files changed

+546
-16
lines changed

docs/src/algorithms/clipping.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,31 @@ viz(poly)
3232
viz!(other, color = :black, alpha = 0.2)
3333
viz!(boundary(clipped), color = :red, segmentsize = 3)
3434
Mke.current_figure()
35-
```
35+
```
36+
37+
## WeilerAtherton
38+
39+
```@docs
40+
WeilerAtherton
41+
```
42+
43+
```@example clipping
44+
# polygon to clip
45+
outer = Ring((8, 0), (4, 8), (2, 8), (-2, 0), (0, 0), (1, 2), (5, 2), (6, 0))
46+
inner = Ring((4, 4), (2, 4), (3, 6))
47+
poly = PolyArea([outer, inner])
48+
49+
# clipping geometry can be a polygon with holes
50+
other = poly |> Rotate(pi) |> Translate(8.0, 8.0)
51+
52+
# clipped polygon
53+
clipped = clip(poly, other, WeilerAtherton())
54+
55+
viz(poly)
56+
viz!(other, color = :black, alpha = 0.2)
57+
viz!(boundary(clipped), color = :red, segmentsize = 3)
58+
Mke.current_figure()
59+
```
60+
61+
Algorithm is by default limited with a maximum number of vertices of 50 for each ring of the resulting polygon.
62+
The limit can be adjusted using a ScopedValue WEILER_ATHERTON_MAX_VERTICES_NUM.

src/Meshes.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@ export
426426
# clipping
427427
ClippingMethod,
428428
SutherlandHodgman,
429+
WeilerAtherton,
429430
clip,
430431

431432
# intersections

src/clipping.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ function clip end
2121
# ----------------
2222

2323
include("clipping/sutherlandhodgman.jl")
24+
include("clipping/weileratherton.jl")

0 commit comments

Comments
 (0)