Tweaked get_radius() to assertt non-redundant args.

This commit is contained in:
Revar Desmera 2019-09-18 19:29:38 -07:00
parent 1e587ee0f3
commit bae6952ece

View file

@ -74,12 +74,16 @@ function all_defined(v,recursive=false) = max([for (x=v) is_undef(x)||(recursive
// Function: get_radius()
// Usage:
// get_radius([r1], [r], [d1], [d], [dflt]);
// get_radius([r1], [r2], [r], [d1], [d2], [d], [dflt]);
// Description:
// Given various radii and diameters, returns the most specific radius.
// If a diameter is most specific, returns half its value, giving the radius.
// If no radii or diameters are defined, returns the value of dflt.
// Value specificity order is r1, d1, r, d, then dflt
// Value specificity order is r1, r2, d1, d2, r, d, then dflt
// Only one of `r1`, `r2`, `d1`, or `d2` can be defined at once, or else it
// errors out, complaining about conflicting radius/diameter values.
// Only one of `r` or `d` can be defined at once, or else it errors out,
// complaining about conflicting radius/diameter values.
// Arguments:
// r1 = Most specific radius.
// d1 = Most specific diameter.
@ -89,11 +93,11 @@ function all_defined(v,recursive=false) = max([for (x=v) is_undef(x)||(recursive
// d = Most general diameter.
// dflt = Value to return if all other values given are `undef`.
function get_radius(r1=undef, r2=undef, r=undef, d1=undef, d2=undef, d=undef, dflt=undef) = (
!is_undef(r1)? r1 :
!is_undef(r2)? r2 :
!is_undef(r1)? assert(is_undef(r2)&&is_undef(d1)&&is_undef(d2), "Conflicting or redundant radius/diameter arguments given.") r1 :
!is_undef(r2)? assert(is_undef(d1)&&is_undef(d2), "Conflicting or redundant radius/diameter arguments given.") r2 :
!is_undef(d1)? d1/2 :
!is_undef(d2)? d2/2 :
!is_undef(r)? r :
!is_undef(r)? assert(is_undef(d), "Conflicting or redundant radius/diameter arguments given.") r :
!is_undef(d)? d/2 :
dflt
);