@@ -58,29 +58,32 @@ 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
6568are 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 ])
7982 end
8083 cut_polys = [GI. Polygon ([c]) for c in cut_coords]
8184 # Add original polygon holes back in
8285 remove_idx = falses (length (cut_polys))
83- _add_holes_to_polys! (T, cut_polys, GI. gethole (poly), remove_idx; exact)
86+ _add_holes_to_polys! (alg, T, cut_polys, GI. gethole (poly), remove_idx; exact)
8487 return cut_polys
8588end
8689
97100of cut geometry in Vector{Vector{Tuple}} format.
98101
99102Note: degenerate cases where intersection points are vertices do not work right now. =#
100- function _cut (:: Type{T} , geom, line, geom_list, intr_list, n_intr_pts; exact) where T
103+ function _cut (alg :: FosterHormannClipping{M, A} , :: Type{T} , geom, line, geom_list, intr_list, n_intr_pts; exact) where {T, M, A}
101104 # Sort and categorize the intersection points
102105 sort! (intr_list, by = x -> geom_list[x]. fracs[2 ])
103- _flag_ent_exit! (GI. LineTrait (), line, geom_list; exact)
106+ _flag_ent_exit! (alg, GI. LineTrait (), line, geom_list; exact)
104107 # Add first point to output list
105108 return_coords = [[geom_list[1 ]. point]]
106109 cross_backs = [(T (Inf ),T (Inf ))]
0 commit comments