From 2a64c89b8f4363274c3e17277f7069e381563b5c Mon Sep 17 00:00:00 2001 From: Adrian Mariano Date: Sun, 3 Oct 2021 09:46:39 -0400 Subject: [PATCH] improved _cleave_connected_regions --- regions.scad | 46 ++++++---------------------------------------- 1 file changed, 6 insertions(+), 40 deletions(-) diff --git a/regions.scad b/regions.scad index 76dd863..22aafd5 100644 --- a/regions.scad +++ b/regions.scad @@ -302,14 +302,8 @@ function _path_path_closest_vertices(path1,path2) = i2 = dists[i1][0] ) [dists[i1][1], i1, i2]; -function _join_paths_at_vertices(path1,path2,seg1,seg2) = - let( - path1 = close_path(clockwise_polygon(polygon_shift(path1, seg1))), - path2 = close_path(ccw_polygon(polygon_shift(path2, seg2))) - ) cleanup_path(deduplicate([each path1, each path2])); - -function new_join_paths_at_vertices(path1,path2,v1,v2) = +function _join_paths_at_vertices(path1,path2,v1,v2) = let( repeat_start = !approx(path1[v1],path2[v2]), path1 = clockwise_polygon(polygon_shift(path1,v1)), @@ -325,7 +319,7 @@ function new_join_paths_at_vertices(path1,path2,v1,v2) = // Given a region that is connected and has its outer border in region[0], // produces a polygon with the same points that has overlapping connected paths -// to join internal holes to the outer border. +// to join internal holes to the outer border. Output is a single path. function _cleave_connected_region(region) = len(region)==0? [] : len(region)<=1? clockwise_polygon(region[0]) : @@ -335,36 +329,7 @@ function _cleave_connected_region(region) = _path_path_closest_vertices(region[0],region[i]) ], idxi = min_index(subindex(dists,0)), - outline = _join_paths_at_vertices( - region[0], region[idxi+1], - dists[idxi][1], dists[idxi][2] - ) - ) - len(region)==2? clockwise_polygon(outline) : // We joined 2 regions, so we're done - let( - newregion = [ - outline, - for (i=idx(region)) - if (i>0 && i!=idxi+1) - region[i] - ] - ) - assert(len(newregion)