From 044b635bed9feb1e65b952832610056a953fc291 Mon Sep 17 00:00:00 2001 From: Adrian Mariano Date: Sat, 2 Oct 2021 09:35:06 -0400 Subject: [PATCH 1/3] make reference to builtins.scad properly relative --- shapes2d.scad | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shapes2d.scad b/shapes2d.scad index 5654a50..bfeed33 100644 --- a/shapes2d.scad +++ b/shapes2d.scad @@ -14,7 +14,7 @@ // include ////////////////////////////////////////////////////////////////////// -use +use // Section: 2D Primitives From 5e0537fc31b5863e3686c0ec2b7b6ef6eea6a5f5 Mon Sep 17 00:00:00 2001 From: Adrian Mariano Date: Sat, 2 Oct 2021 12:03:00 -0400 Subject: [PATCH 2/3] Add center option to path_text --- shapes3d.scad | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/shapes3d.scad b/shapes3d.scad index f1a82c4..6bc29f1 100644 --- a/shapes3d.scad +++ b/shapes3d.scad @@ -2112,6 +2112,7 @@ function _cut_interp(pathcut, path, data) = // font = font to use // --- // lettersize = scalar or array giving size of letters +// center = center text on the path instead of starting at the first point. Default: false // offset = distance to shift letters "up" (towards the reader). Not allowed for 2D path. Default: 0 // normal = direction or list of directions pointing towards the reader of the text. Not allowed for 2D path. // top = direction or list of directions pointing toward the top of the text @@ -2173,7 +2174,7 @@ function _cut_interp(pathcut, path, data) = // path = zrot(-120,p=concat(arc(100, r=25, angle=[0,90]), back(50,p=arc(100, r=25, angle=[268, 180])))); // color("red")stroke(path,width=.2); // path_text(path, "A shorter example", size=5, lettersize=5/1.2, font="Courier"); -module path_text(path, text, font, size, thickness, lettersize, offset=0, reverse=false, normal, top, textmetrics=false) +module path_text(path, text, font, size, thickness, lettersize, offset=0, reverse=false, normal, top, center=false, textmetrics=false) { dummy2=assert(is_path(path,[2,3]),"Must supply a 2d or 3d path") assert(num_defined([normal,top])<=1, "Cannot define both \"normal\" and \"top\""); @@ -2200,9 +2201,12 @@ module path_text(path, text, font, size, thickness, lettersize, offset=0, revers : textmetrics ? [for(letter=text) let(t=textmetrics(letter, font=font, size=size)) t.advance[0]] : assert(false, "textmetrics disabled: Must specify letter size"); - dummy1 = assert(sum(lsize)<=path_length(path),"Path is too short for the text"); + textlength = sum(lsize); + dummy1 = assert(textlength<=path_length(path),"Path is too short for the text"); + + start = center ? (path_length(path) - textlength)/2 : 0; - pts = _path_cut_points(path, add_scalar([0, each cumsum(lsize)],lsize[0]/2), direction=true); + pts = _path_cut_points(path, add_scalar([0, each cumsum(lsize)],start+lsize[0]/2), direction=true); usernorm = is_def(normal); usetop = is_def(top); From 2a64c89b8f4363274c3e17277f7069e381563b5c Mon Sep 17 00:00:00 2001 From: Adrian Mariano Date: Sun, 3 Oct 2021 09:46:39 -0400 Subject: [PATCH 3/3] 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)