From b2fff4c33f45c8e61bbe1f6549e69ef46ef8b2fa Mon Sep 17 00:00:00 2001 From: Sam Potts Date: Mon, 15 Apr 2019 22:08:09 +1000 Subject: Increase speed limits --- src/js/utils/numbers.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/js/utils/numbers.js (limited to 'src/js/utils/numbers.js') diff --git a/src/js/utils/numbers.js b/src/js/utils/numbers.js new file mode 100644 index 00000000..f6eb65c8 --- /dev/null +++ b/src/js/utils/numbers.js @@ -0,0 +1,17 @@ +/** + * Returns a number whose value is limited to the given range. + * + * Example: limit the output of this computation to between 0 and 255 + * (x * 255).clamp(0, 255) + * + * @param {Number} input + * @param {Number} min The lower boundary of the output range + * @param {Number} max The upper boundary of the output range + * @returns A number in the range [min, max] + * @type Number + */ +export function clamp(input = 0, min = 0, max = 255) { + return Math.min(Math.max(input, min), max); +} + +export default { clamp }; -- cgit v1.2.3