From 70afd85c18b7d4f60cd2c40574dc56c01edffa2c Mon Sep 17 00:00:00 2001 From: Adrian Mariano Date: Tue, 4 Jan 2022 23:11:34 -0500 Subject: [PATCH] fix smooth_path and path_to_bezier to handle 1-regions --- beziers.scad | 6 ++++-- rounding.scad | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/beziers.scad b/beziers.scad index d1a2bcb..6e75bba 100644 --- a/beziers.scad +++ b/beziers.scad @@ -747,14 +747,16 @@ function bezier_path(bezier, splinesteps=16, N=3, endpoint=true) = // using `path_tangents()` with `uniform=false` by default. Tangents computed on non-uniform data tend // to display overshoots. See `smooth_path()` for examples. // Arguments: -// path = 2D or 3D point list that the curve must pass through +// path = 2D or 3D point list or 1-region that the curve must pass through // closed = true if the curve is closed . Default: false // tangents = tangents constraining curve direction at each point // uniform = set to true to compute tangents with uniform=true. Default: false // --- // size = absolute size specification for the curve, a number or vector // relsize = relative size specification for the curve, a number or vector. Default: 0.1. -function path_to_bezier(path, closed=false, tangents, uniform=false, size, relsize) = +function path_to_bezier(path, closed, tangents, uniform=false, size, relsize) = + is_1region(path) ? path_to_bezier(path[0], default(closed,true), tangents, uniform, size, relsize) : + let(closed=default(closed,false)) assert(is_bool(closed)) assert(is_bool(uniform)) assert(num_defined([size,relsize])<=1, "Can't define both size and relsize") diff --git a/rounding.scad b/rounding.scad index e40c012..83a506d 100644 --- a/rounding.scad +++ b/rounding.scad @@ -500,9 +500,10 @@ function _rounding_offsets(edgespec,z_dir=1) = // stroke(smooth_path(pts, uniform=false, relsize=0.1),width=.1); // color("red")move_copies(pts)circle(r=.15,$fn=12); module smooth_path(path, tangents, size, relsize, splinesteps=10, uniform=false, closed=false) {no_module();} -function smooth_path(path, tangents, size, relsize, splinesteps=10, uniform=false, closed=false) = +function smooth_path(path, tangents, size, relsize, splinesteps=10, uniform=false, closed) = + is_1region(path) ? smooth_path(path[0], tangents, size, relsize, splinesteps, uniform, default(closed,true)) : let ( - bez = path_to_bezier(path, tangents=tangents, size=size, relsize=relsize, uniform=uniform, closed=closed) + bez = path_to_bezier(path, tangents=tangents, size=size, relsize=relsize, uniform=uniform, closed=default(closed,false)) ) bezier_path(bez,splinesteps=splinesteps);