Suppose I have a value
, I usually do this to "clamp" it to a range, here the range [0..1]
. That is if it is below the range start, increase it to the range start, it above the range end, reduce it to the range end.
clampedValue = Math.max(0, Math.min(1, value));
Is there any built in function for clamping to a range?
Is there any built in function for clamping to a range?
No.