@@ -58,29 +58,32 @@ GI.coordinates.(cut_polys)
58
58
[[[5.0, 0.0], [10.0, 0.0], [10.0, 10.0], [5.0, 10.0], [5.0, 0.0]]]
59
59
```
60
60
"""
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 ())
63
66
64
67
#= Cut a given polygon by given line. Add polygon holes back into resulting pieces if there
65
68
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}
67
70
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)
69
72
n_intr_pts = length (intr_list)
70
73
# If an impossible number of intersection points, return original polygon
71
74
if n_intr_pts < 2 || isodd (n_intr_pts)
72
75
return [tuples (poly)]
73
76
end
74
77
# 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)
76
79
# Close coords and create polygons
77
80
for c in cut_coords
78
81
push! (c, c[1 ])
79
82
end
80
83
cut_polys = [GI. Polygon ([c]) for c in cut_coords]
81
84
# Add original polygon holes back in
82
85
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)
84
87
return cut_polys
85
88
end
86
89
97
100
of cut geometry in Vector{Vector{Tuple}} format.
98
101
99
102
Note: 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}
101
104
# Sort and categorize the intersection points
102
105
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)
104
107
# Add first point to output list
105
108
return_coords = [[geom_list[1 ]. point]]
106
109
cross_backs = [(T (Inf ),T (Inf ))]
0 commit comments