Skip to content

Commit 8435b07

Browse files
committed
Pass algorithm all the way through cut
This is a shorter change list as a sampler, to show what needs to happen.
1 parent 1a7acc2 commit 8435b07

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/methods/clipping/cut.jl

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,21 +58,24 @@ GI.coordinates.(cut_polys)
5858
[[[5.0, 0.0], [10.0, 0.0], [10.0, 10.0], [5.0, 10.0], [5.0, 0.0]]]
5959
```
6060
"""
61-
cut(geom, line, ::Type{T} = Float64) where {T <: AbstractFloat} =
62-
_cut(T, GI.trait(geom), geom, GI.trait(line), line; exact = True())
61+
cut(geom, line, ::Type{T} = Float64) where {T <: AbstractFloat} = cut(FosterHormannClipping(), geom, line, T)
62+
cut(m::Manifold, geom, line, ::Type{T} = Float64) where {T <: AbstractFloat} = cut(FosterHormannClipping(m), geom, line, T)
63+
64+
cut(alg::FosterHormannClipping{M, A}, geom, line, ::Type{T} = Float64) where {T <: AbstractFloat, M, A} =
65+
_cut(alg, T, GI.trait(geom), geom, GI.trait(line), line; exact = True())
6366

6467
#= Cut a given polygon by given line. Add polygon holes back into resulting pieces if there
6568
are any holes. =#
66-
function _cut(::Type{T}, ::GI.PolygonTrait, poly, ::GI.LineTrait, line; exact) where T
69+
function _cut(alg::FosterHormannClipping{M, A}, ::Type{T}, ::GI.PolygonTrait, poly, ::GI.LineTrait, line; exact) where {T, M, A}
6770
ext_poly = GI.getexterior(poly)
68-
poly_list, intr_list = _build_a_list(T, ext_poly, line; exact)
71+
poly_list, intr_list = _build_a_list(alg, T, ext_poly, line; exact)
6972
n_intr_pts = length(intr_list)
7073
# If an impossible number of intersection points, return original polygon
7174
if n_intr_pts < 2 || isodd(n_intr_pts)
7275
return [tuples(poly)]
7376
end
7477
# Cut polygon by line
75-
cut_coords = _cut(T, ext_poly, line, poly_list, intr_list, n_intr_pts; exact)
78+
cut_coords = _cut(alg, T, ext_poly, line, poly_list, intr_list, n_intr_pts; exact)
7679
# Close coords and create polygons
7780
for c in cut_coords
7881
push!(c, c[1])

0 commit comments

Comments
 (0)