Changed unit(dflt=) to unit(error=)

This commit is contained in:
Garth Minette 2020-07-11 23:23:12 -07:00
parent dde616dad5
commit 0be0708c2b
2 changed files with 7 additions and 7 deletions

View file

@ -106,13 +106,13 @@ function vceil(v) = [for (x=v) ceil(x)];
// Function: unit() // Function: unit()
// Usage: // Usage:
// unit(v, [dflt]); // unit(v, [error]);
// Description: // Description:
// Returns unit length normalized version of vector v. If passed a zero-length vector, // Returns the unit length normalized version of vector v. If passed a zero-length vector,
// asserts an error unless `dflt` is given, in which case the value of `dflt` is returned. // asserts an error unless `error` is given, in which case the value of `error` is returned.
// Arguments: // Arguments:
// v = The vector to normalize. // v = The vector to normalize.
// dflt = If given, and input is a zero-length vector, this value is returned. Default: `undef` (assert error on zero-length vector) // error = If given, and input is a zero-length vector, this value is returned. Default: Assert error on zero-length vector.
// Examples: // Examples:
// unit([10,0,0]); // Returns: [1,0,0] // unit([10,0,0]); // Returns: [1,0,0]
// unit([0,10,0]); // Returns: [0,1,0] // unit([0,10,0]); // Returns: [0,1,0]
@ -120,9 +120,9 @@ function vceil(v) = [for (x=v) ceil(x)];
// unit([0,-10,0]); // Returns: [0,-1,0] // unit([0,-10,0]); // Returns: [0,-1,0]
// unit([0,0,0],[1,2,3]); // Returns: [1,2,3] // unit([0,0,0],[1,2,3]); // Returns: [1,2,3]
// unit([0,0,0]); // Asserts an error. // unit([0,0,0]); // Asserts an error.
function unit(v, dflt) = function unit(v, error=[[["ASSERT"]]]) =
assert(is_vector(v), str("Expected a vector. Got: ",v)) assert(is_vector(v), str("Expected a vector. Got: ",v))
norm(v)<EPSILON? (is_undef(dflt)? assert(norm(v)>=EPSILON) : dflt) : norm(v)<EPSILON? (error==[[["ASSERT"]]]? assert(norm(v)>=EPSILON) : error) :
v/norm(v); v/norm(v);

View file

@ -8,7 +8,7 @@
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
BOSL_VERSION = [2,0,390]; BOSL_VERSION = [2,0,391];
// Section: BOSL Library Version Functions // Section: BOSL Library Version Functions