2019-07-17 14:15:31 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
function normalise(value, { min : input_min, max: input_max }, { min : output_min, max: output_max }) {
|
|
|
|
return (
|
|
|
|
((value - input_min) / (input_max - input_min)) * (output_max - output_min)
|
|
|
|
) + output_min
|
|
|
|
}
|
|
|
|
|
2019-07-29 13:17:28 +00:00
|
|
|
/**
|
|
|
|
* Clamps a value to fit within the specified bounds.
|
|
|
|
* @param {number} value The number to clamp.
|
|
|
|
* @param {number} min The minimum value the number can be.
|
|
|
|
* @param {number} max The maximum value the number can be.
|
|
|
|
* @return {number} The clamped number.
|
|
|
|
*/
|
2019-07-17 14:15:31 +00:00
|
|
|
function clamp(value, min, max) {
|
|
|
|
if(value > max) return max;
|
|
|
|
if(value < min) return min;
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export { normalise, clamp };
|