diff --git a/attachments.scad b/attachments.scad index 132dc8d..eaf674e 100644 --- a/attachments.scad +++ b/attachments.scad @@ -468,7 +468,8 @@ function find_anchor(anchor, geom) = mm = pointlist_bounds(select(rpts,idxs)), avgy = (mm[0].y+mm[1].y)/2, avgz = (mm[0].z+mm[1].z)/2, - pos = rot(from=RIGHT, to=anchor, p=[maxx, avgy, avgz]) + mpt = approx(point2d(anchor),[0,0])? [maxx,0,0] : [maxx, avgy, avgz], + pos = rot(from=RIGHT, to=anchor, p=mpt) ) [anchor, pos, anchor, oang] ) : type == "rect"? ( //size, size2 let( diff --git a/regions.scad b/regions.scad index 5e4e330..4982705 100644 --- a/regions.scad +++ b/regions.scad @@ -211,20 +211,190 @@ function split_nested_region(region) = lev = candout[0], parent = candout[1] ) if (lev % 2 == 0) [ - parent, + clockwise_polygon(parent), for (path = paths) if ( path[0] == lev+1 && point_in_polygon( lerp(path[1][0], path[1][1], 0.5), parent ) >= 0 - ) path[1] + ) ccw_polygon(path[1]) ] ] ) outs; +// Section: Region Extrusion and VNFs + +function _path_path_closest_vertices(path1,path2) = + let( + dists = [for (i=idx(path1)) let(j=closest_point(path1[i],path2)) [j,norm(path2[j]-path1[i])]], + i1 = min_index(subindex(dists,1)), + 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 _cleave_simple_region(region) = + len(region)==0? [] : + len(region)<=1? clockwise_polygon(region[0]) : + let( + dists = [ + for (i=[1:1:len(region)-1]) + _path_path_closest_vertices(region[0],region[i]) + ], + idxi = min_index(subindex(dists,0)), + newoline = _join_paths_at_vertices( + region[0], region[idxi+1], + dists[idxi][1], dists[idxi][2] + ) + ) len(region)==2? clockwise_polygon(newoline) : + let( + orgn = [ + newoline, + for (i=idx(region)) + if (i>0 && i!=idxi+1) + region[i] + ] + ) + assert(len(orgn)