浏览代码

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

undefined
Sam Hocevar 10 年前
父节点
当前提交
49692b8ba3
共有 2 个文件被更改,包括 11 次插入1 次删除
  1. +2
    -1
      src/lol/math/functions.h
  2. +9
    -0
      src/lol/math/vector.h

+ 2
- 1
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) \


+ 9
- 0
src/lol/math/vector.h 查看文件

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


正在加载...
取消
保存