-
Notifications
You must be signed in to change notification settings - Fork 0
8. Miscellaneous
CookieShade edited this page Aug 11, 2016
·
4 revisions
Other general utility functions
Throws an Error
with the provided message if assertion
evaluates to false
. Useful for debugging and error-checking.
BETA.assert(typeof x !== "undefined", "That's an error!"); // Throws an error if x is undefined
Returns true
if a value is a number, and not NaN
.
var isNum = BETA.isNumber(NaN); // false
var isNum = BETA.isNumber(Infinity); // true
Returns x modulo y. Similar to the %
operator, but treats negative remainders correctly.
Clamps val
to the range [a
, b
].
Numbers above the range return the highest bound of the range, while numbers below the range return the lowest bound. Numbers within the range are unaffected.
var clamped = BETA.clamp(5, 0, 1); // 1, as 5 is outside [0, 1]
var unaffected = BETA.clamp(0.6, 0, 1); // 0.6, as 0.6 is in [0, 1]