Skip to content

Commit

Permalink
Add Weiler-Atherton clipping algorithm
Browse files Browse the repository at this point in the history
Changes the default clipping algorithm for intersections.
  • Loading branch information
Nemanja Jovanovic committed Aug 30, 2024
1 parent 66eed30 commit bd5c309
Show file tree
Hide file tree
Showing 9 changed files with 605 additions and 17 deletions.
24 changes: 24 additions & 0 deletions docs/src/algorithms/clipping.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,30 @@ other = Box((0,1), (3,7))
# clipped polygon
clipped = clip(poly, other, SutherlandHodgmanClipping())
viz(poly)
viz!(other, color = :black, alpha = 0.2)
viz!(boundary(clipped), color = :red, segmentsize = 3)
Mke.current_figure()
```

## Weiler-Atherton

```@docs
WeilerAthertonClipping
```

```@example clipping
# polygon to clip
outer = Ring((8, 0), (4, 8), (2, 8), (-2, 0), (0, 0), (1, 2), (5, 2), (6, 0))
inner = Ring((4, 4), (2, 4), (3, 6))
poly = PolyArea([outer, inner])
# clipping geometry can be a polygon with holes
other = poly |> Rotate(pi) |> Translate(8.0, 8.0)
# clipped polygon
clipped = clip(poly, other, WeilerAthertonClipping())
viz(poly)
viz!(other, color = :black, alpha = 0.2)
viz!(boundary(clipped), color = :red, segmentsize = 3)
Expand Down
1 change: 1 addition & 0 deletions src/Meshes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ export
# clipping
ClippingMethod,
SutherlandHodgmanClipping,
WeilerAthertonClipping,
clip,

# intersections
Expand Down
1 change: 1 addition & 0 deletions src/clipping.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ function clip end
# ----------------

include("clipping/sutherlandhodgman.jl")
include("clipping/weileratherton.jl")
Loading

0 comments on commit bd5c309

Please sign in to comment.