@@ -66,21 +66,23 @@ function _union(
6666 # First, I get the exteriors of the two polygons
6767 ext_a = GI. getexterior (poly_a)
6868 ext_b = GI. getexterior (poly_b)
69+
70+ crs = mutual_crs (poly_a, poly_b)
6971 # Then, I get the union of the exteriors
7072 a_list, b_list, a_idx_list = _build_ab_list (alg, T, ext_a, ext_b, _union_delay_cross_f, _union_delay_bounce_f; exact)
71- polys = _trace_polynodes (alg, T, a_list, b_list, a_idx_list, _union_step, poly_a, poly_b)
73+ polys = _trace_polynodes (alg, T, a_list, b_list, a_idx_list, _union_step, poly_a, poly_b; crs )
7274 n_pieces = length (polys)
7375 # Check if one polygon totally within other and if so, return the larger polygon
7476 a_in_b, b_in_a = false , false
7577 if n_pieces == 0 # no crossing points, determine if either poly is inside the other
7678 a_in_b, b_in_a = _find_non_cross_orientation (alg, a_list, b_list, ext_a, ext_b; exact)
7779 if a_in_b
78- push! (polys, GI. Polygon ([_linearring (tuples (ext_b))]))
80+ push! (polys, GI. Polygon ([_linearring (tuples (ext_b; crs ))]; crs ))
7981 elseif b_in_a
80- push! (polys, GI. Polygon ([_linearring (tuples (ext_a))]))
82+ push! (polys, GI. Polygon ([_linearring (tuples (ext_a; crs ))]; crs ))
8183 else
82- push! (polys, tuples (poly_a))
83- push! (polys, tuples (poly_b))
84+ push! (polys, tuples (poly_a; crs ))
85+ push! (polys, tuples (poly_b; crs ))
8486 return polys
8587 end
8688 elseif n_pieces > 1
@@ -94,7 +96,7 @@ function _union(
9496 end
9597 # Add in holes
9698 if GI. nhole (poly_a) != 0 || GI. nhole (poly_b) != 0
97- _add_union_holes! (alg, polys, a_in_b, b_in_a, poly_a, poly_b; exact)
99+ _add_union_holes! (alg, polys, a_in_b, b_in_a, poly_a, poly_b; exact, crs )
98100 end
99101 # Remove unneeded collinear points on same edge
100102 _remove_collinear_points! (alg, polys, [false ], poly_a, poly_b)
@@ -121,11 +123,11 @@ _union_step(x, _) = x ? (-1) : 1
121123#= Add holes from two polygons to the exterior polygon formed by their union. If adding the
122124the holes reveals that the polygons aren't actually intersecting, return the original
123125polygons. =#
124- function _add_union_holes! (alg:: FosterHormannClipping , polys, a_in_b, b_in_a, poly_a, poly_b; exact)
126+ function _add_union_holes! (alg:: FosterHormannClipping , polys, a_in_b, b_in_a, poly_a, poly_b; exact, crs )
125127 if a_in_b
126- _add_union_holes_contained_polys! (alg, polys, poly_a, poly_b; exact)
128+ _add_union_holes_contained_polys! (alg, polys, poly_a, poly_b; exact, crs )
127129 elseif b_in_a
128- _add_union_holes_contained_polys! (alg, polys, poly_b, poly_a; exact)
130+ _add_union_holes_contained_polys! (alg, polys, poly_b, poly_a; exact, crs )
129131 else # Polygons intersect, but neither is contained in the other
130132 n_a_holes = GI. nhole (poly_a)
131133 ext_poly_a = GI. Polygon (StaticArrays. SVector (GI. getexterior (poly_a)))
166168#= Add holes holes to the union of two polygons where one of the original polygons was
167169inside of the other. If adding the the holes reveal that the polygons aren't actually
168170intersecting, return the original polygons.=#
169- function _add_union_holes_contained_polys! (alg:: FosterHormannClipping , polys, interior_poly, exterior_poly; exact)
171+ function _add_union_holes_contained_polys! (alg:: FosterHormannClipping , polys, interior_poly, exterior_poly; exact, crs )
170172 union_poly = polys[1 ]
171173 ext_int_ring = GI. getexterior (interior_poly)
172174 for (i, ih) in enumerate (GI. gethole (exterior_poly))
@@ -176,8 +178,8 @@ function _add_union_holes_contained_polys!(alg::FosterHormannClipping, polys, in
176178 if ! on_ih && ! out_ih
177179 #= interior polygon is completely within the ith hole - polygons aren't
178180 touching and do not actually form a union =#
179- polys[1 ] = tuples (interior_poly)
180- push! (polys, tuples (exterior_poly))
181+ polys[1 ] = tuples (interior_poly; crs )
182+ push! (polys, tuples (exterior_poly; crs ))
181183 return polys
182184 else
183185 #= interior polygon is partially within the ith hole - area of interior
@@ -231,19 +233,20 @@ function _union(
231233 if ! isnothing (fix_multipoly) # Fix multipoly_b to prevent repeated regions in the output
232234 multipoly_b = fix_multipoly (multipoly_b)
233235 end
234- polys = [tuples (poly_a, T)]
236+ crs = mutual_crs (poly_a, multipoly_b)
237+ polys = [tuples (poly_a, T; crs)]
235238 for poly_b in GI. getpolygon (multipoly_b)
236239 if intersects (#= TODO : alg.manifold, =# polys[1 ], poly_b)
237240 # If polygons intersect and form a new polygon, swap out polygon
238241 new_polys = union (alg, polys[1 ], poly_b; target)
239242 if length (new_polys) > 1 # case where they intersect by just one point
240- push! (polys, tuples (poly_b, T)) # add poly_b to list
243+ push! (polys, tuples (poly_b, T; crs )) # add poly_b to list
241244 else
242245 polys[1 ] = new_polys[1 ]
243246 end
244247 else
245248 # If they don't intersect, poly_b is now a part of the union as its own polygon
246- push! (polys, tuples (poly_b, T))
249+ push! (polys, tuples (poly_b, T; crs ))
247250 end
248251 end
249252 return polys
0 commit comments