Browse Source

math: add saturate(x) as a shortcut to clamp(x,0,1).

undefined
Sam Hocevar 10 years ago
parent
commit
49692b8ba3
2 changed files with 11 additions and 1 deletions
  1. +2
    -1
      src/lol/math/functions.h
  2. +9
    -0
      src/lol/math/vector.h

+ 2
- 1
src/lol/math/functions.h View File

@@ -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) \


+ 9
- 0
src/lol/math/vector.h View File

@@ -1032,6 +1032,15 @@ static inline vec_t<T,N> fract(vec_t<T,N,SWIZZLE> const &a)
return ret;
}

template<typename T, int N, int SWIZZLE>
static inline vec_t<T,N> saturate(vec_t<T,N,SWIZZLE> const &a)
{
vec_t<T,N> ret;
for (int i = 0; i < N; ++i)
ret[i] = saturate(a[i]);
return ret;
}

template<typename T, int N, int SWIZZLE>
static inline vec_t<T,N> normalize(vec_t<T,N,SWIZZLE> const &a)
{


Loading…
Cancel
Save