@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
22 lines (21 loc) • 481 B
JavaScript
/**
* Clamps a value to 0..1 range
* Same as `clamp(value, 0, 1)`
* Works the same as `saturate` function in GLSL
* @param {number} value
* @returns {number}
*/
export function clamp01(value) {
if (value < 0) {
return 0;
} else if (value > 1) {
return 1;
} else {
return value;
}
}
/**
* Shortcut following GLSL naming, see {@link clamp01}
* @type {function(number): number}
*/
export const saturate = clamp01;