fix smooth_path and path_to_bezier to handle 1-regions

This commit is contained in:
Adrian Mariano 2022-01-04 23:11:34 -05:00
parent fe9a9a5d01
commit 70afd85c18
2 changed files with 7 additions and 4 deletions

View file

@ -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 // using `path_tangents()` with `uniform=false` by default. Tangents computed on non-uniform data tend
// to display overshoots. See `smooth_path()` for examples. // to display overshoots. See `smooth_path()` for examples.
// Arguments: // 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 // closed = true if the curve is closed . Default: false
// tangents = tangents constraining curve direction at each point // tangents = tangents constraining curve direction at each point
// uniform = set to true to compute tangents with uniform=true. Default: false // uniform = set to true to compute tangents with uniform=true. Default: false
// --- // ---
// size = absolute size specification for the curve, a number or vector // 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. // 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(closed))
assert(is_bool(uniform)) assert(is_bool(uniform))
assert(num_defined([size,relsize])<=1, "Can't define both size and relsize") assert(num_defined([size,relsize])<=1, "Can't define both size and relsize")

View file

@ -500,9 +500,10 @@ function _rounding_offsets(edgespec,z_dir=1) =
// stroke(smooth_path(pts, uniform=false, relsize=0.1),width=.1); // stroke(smooth_path(pts, uniform=false, relsize=0.1),width=.1);
// color("red")move_copies(pts)circle(r=.15,$fn=12); // 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();} 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 ( 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); bezier_path(bez,splinesteps=splinesteps);