UNPKG

rc-js-util

Version:

A collection of TS and C++ utilities to help writing performant and correct applications, achieved through strict typing and (removable) invariant checking.

32 lines 1.03 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.mathBound = void 0; const _debug_js_1 = require("../../debug/_debug.js"); /** * @public * Bound a value in to a range. * * @returns The `value` if it lies between `min` and `max`, otherwise `min` if smaller and `max` if greater. * * @remarks * NaN input will cause a debug error. * * See {@link mathBound}. */ function mathBound(value, min, max) { _BUILD.DEBUG && _debug_js_1._Debug.runBlock(() => { _debug_js_1._Debug.assert(!isNaN(value), "expected value to be a number"); _debug_js_1._Debug.assert(!isNaN(min), "expected min to be a number"); _debug_js_1._Debug.assert(!isNaN(max), "expected max to be a number"); _debug_js_1._Debug.assert(max >= min, "expected max to be greater than or equal to min"); }); if (value > max) { return max; } if (value < min) { return min; } return value; } exports.mathBound = mathBound; //# sourceMappingURL=math-bound.js.map