Bläddra i källkod

math: implement fract() for vectors and scalar types.

legacy
Sam Hocevar sam 12 år sedan
förälder
incheckning
e00d987083
3 ändrade filer med 47 tillägg och 1 borttagningar
  1. +1
    -0
      src/lol/math/half.h
  2. +15
    -0
      src/lol/math/math.h
  3. +31
    -1
      src/lol/math/vector.h

+ 1
- 0
src/lol/math/half.h Visa fil

@@ -125,6 +125,7 @@ static inline half fmod(half a, half b)
using std::fmod;
return (half)fmod((float)a, (float)b);
}
static inline half fract(half a) { return (half)fract((float)a); }
static inline half abs(half a) { return half::makebits(a.bits & 0x7fffu); }

static inline half clamp(half x, half a, half b)


+ 15
- 0
src/lol/math/math.h Visa fil

@@ -33,6 +33,9 @@ namespace lol
static inline double sqrt(double const &x) { return std::sqrt(x); }
static inline float sqrt(float const &x) { return std::sqrt(x); }

static inline double exp(double const &x) { return std::exp(x); }
static inline float exp(float const &x) { return std::exp(x); }

static inline double sin(double const &x) { return std::sin(x); }
static inline double cos(double const &x) { return std::cos(x); }
static inline double tan(double const &x) { return std::tan(x); }
@@ -138,6 +141,18 @@ static inline float fmod(float x, float y) { return std::fmod(x, y); }
static inline double fmod(double x, double y) { return std::fmod(x, y); }
static inline ldouble fmod(ldouble x, ldouble y) { return std::fmod(x, y); }

static inline uint8_t fract(uint8_t x) { return 0; }
static inline int8_t fract(int8_t x) { return 0; }
static inline uint16_t fract(uint16_t x) { return 0; }
static inline int16_t fract(int16_t x) { return 0; }
static inline uint32_t fract(uint32_t x) { return 0; }
static inline int32_t fract(int32_t x) { return 0; }
static inline uint64_t fract(uint64_t x) { return 0; }
static inline int64_t fract(int64_t x) { return 0; }
static inline float fract(float x) { return x - std::floor(x); }
static inline double fract(double x) { return x - std::floor(x); }
static inline ldouble fract(ldouble x) { return x - std::floor(x); }

static inline uint8_t min(uint8_t x, uint8_t y) { return std::min(x, y); }
static inline int8_t min(int8_t x, int8_t y) { return std::min(x, y); }
static inline uint16_t min(uint16_t x, uint16_t y) { return std::min(x, y); }


+ 31
- 1
src/lol/math/vector.h Visa fil

@@ -1134,6 +1134,25 @@ extern Quat<T> slerp(Quat<T> const &qa, Quat<T> const &qb, T f);
return max(min(x, b), a); \
}

/*
* vec mix(vec, vec, vec)
* vec mix(vec, vec, scalar)
*/
#define LOL_VECTOR_MIX_FUN(tname, tprefix, type) \
tprefix \
inline tname<type> mix(tname<type> const &x, \
tname<type> const &y, tname<type> const &a) \
{ \
return x + a * (y - x); \
} \
\
tprefix \
inline tname<type> mix(tname<type> const &x, \
tname<type> const &y, type const &a) \
{ \
return x + a * (y - x); \
}

/*
* bool ==(vec, vec) (also complex & quaternion)
* bool !=(vec, vec) (also complex & quaternion)
@@ -1218,6 +1237,15 @@ extern Quat<T> slerp(Quat<T> const &qa, Quat<T> const &qb, T f);
} \
\
tprefix \
inline tname<type> fract(tname<type> const &a) \
{ \
tname<type> ret; \
for (size_t n = 0; n < sizeof(a) / sizeof(type); n++) \
ret[n] = fract(a[n]); \
return ret; \
} \
\
tprefix \
inline tname<type> normalize(tname<type> const &a) \
{ \
type norm = (type)length(a); \
@@ -1293,7 +1321,8 @@ extern Quat<T> slerp(Quat<T> const &qa, Quat<T> const &qb, T f);
LOL_VECTOR_MINMAX_FUN(tname, min, tprefix, type) \
LOL_VECTOR_MINMAX_FUN(tname, max, tprefix, type) \
LOL_VECTOR_MINMAX_FUN(tname, fmod, tprefix, type) \
LOL_VECTOR_CLAMP_FUN(tname, tprefix, type)
LOL_VECTOR_CLAMP_FUN(tname, tprefix, type) \
LOL_VECTOR_MIX_FUN(tname, tprefix, type)

#define LOL_VECTOR_COERCE_OPS(tname, tprefix, t1, t2, tf) \
LOL_VECTOR_VECTOR_COERCE_OP(tname, *, tprefix, t1, t2, tf) \
@@ -1563,6 +1592,7 @@ ACTIVATE_COERCE_NAMESPACES(real)
#undef LOL_VECTOR_VECTOR_OP
#undef LOL_VECTOR_MINMAX_FUN
#undef LOL_VECTOR_CLAMP_FUN
#undef LOL_VECTOR_MIX_FUN
#undef LOL_VECTOR_VECTOR_BOOL_OP
#undef LOL_VECTOR_SCALAR_COERCE_OP
#undef LOL_SCALAR_VECTOR_COERCE_OP


Laddar…
Avbryt
Spara