mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2025-01-30 00:09:37 +00:00
Added useful functions for argument handling.
This commit is contained in:
parent
70f268775c
commit
e4837a0b21
1 changed files with 18 additions and 0 deletions
18
math.scad
18
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
|
||||
|
|
Loading…
Reference in a new issue