1
0
Fork 0

Add a math.clamp function.

This commit is contained in:
James Turner 2016-08-19 11:59:14 +01:00
parent e6646d9f8f
commit 3834fcc36e

View file

@ -27,6 +27,12 @@ var avg = func {
return x; return x;
} }
# this follows std::clamp for argument order, as opposed to
# qBound which uses (min, value, max)
var clamp = func(value, min, max) {
return (value < min) ? min : (value > max) ? max : value;
}
# note - mathlib defines an fmod function (added after this was written) # note - mathlib defines an fmod function (added after this was written)
# It uses C-library fmod(), which has different rounding behaviour to # It uses C-library fmod(), which has different rounding behaviour to
# this code (eg, fmod(-5, 4) gives -1, whereas this code gives 3) # this code (eg, fmod(-5, 4) gives -1, whereas this code gives 3)