From e4837a0b218b6d2767c7d4f96d7c428e7b454f8e Mon Sep 17 00:00:00 2001 From: Revar Desmera <revarbat@gmail.com> Date: Wed, 27 Feb 2019 03:51:19 -0800 Subject: [PATCH] Added useful functions for argument handling. --- math.scad | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/math.scad b/math.scad index f360aa6..e78c630 100644 --- a/math.scad +++ b/math.scad @@ -380,8 +380,26 @@ function slice(arr,st,end) = let( ) [for (i=[s:e-1]) if (e>s) arr[i]]; +function default(v,dflt) = v==undef? dflt : v; + + +function get_radius(r1=undef, r=undef, d1=undef, d=undef, dflt=undef) = ( + (r1!=undef)? r1 : + (d1!=undef)? d1/2 : + (r!=undef)? r : + (d!=undef)? d/2 : + dflt +); + + +// Returns the first item in the list that is not undef. function first_defined(v) = [for (x = v) if (x!=undef) x][0]; +// If given a vector, returns the vector. If given a scalar, returns [scalar, scalar, scalar] +function scalar_vec(v) = v[0]==undef? [v,v,v] : v; + + + // vim: noexpandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap