diff --git a/src/lol/math/functions.h b/src/lol/math/functions.h index a87c5657..abdca31b 100644 --- a/src/lol/math/functions.h +++ b/src/lol/math/functions.h @@ -235,7 +235,8 @@ static inline ldouble ceil(ldouble x) { return std::ceil(x); } static inline T fract(T x) { return x - lol::floor(x); } \ static inline T min(T x, T y) { return std::min(x, y); } \ static inline T max(T x, T y) { return std::max(x, y); } \ - static inline T clamp(T x, T y, T z) { return min(max(x, y), z); } + static inline T clamp(T x, T y, T z) { return min(max(x, y), z); } \ + static inline T saturate(T x) { return min(max(x, (T)0), (T)1); } #define LOL_GENERIC_FUNC_SIGNED(T) \ LOL_GENERIC_FUNC(T) \ diff --git a/src/lol/math/vector.h b/src/lol/math/vector.h index 284c711c..5c6b92a8 100644 --- a/src/lol/math/vector.h +++ b/src/lol/math/vector.h @@ -1032,6 +1032,15 @@ static inline vec_t fract(vec_t const &a) return ret; } +template +static inline vec_t saturate(vec_t const &a) +{ + vec_t ret; + for (int i = 0; i < N; ++i) + ret[i] = saturate(a[i]); + return ret; +} + template static inline vec_t normalize(vec_t const &a) {