Added useful functions for argument handling.

This commit is contained in:
Revar Desmera 2019-02-27 03:51:19 -08:00
parent 70f268775c
commit e4837a0b21

View file

@ -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