# Changeset 1311Tweet

Ignore:
Timestamp:
Apr 30, 2012, 3:12:44 AM (9 years ago)
Message:

math: add min(), max() and clamp() for half, real and vector types.

Location:
trunk/src
Files:
4 edited

Unmodified
Removed
• ## trunk/src/lol/math/half.h

 r1176 }; static inline half min(half a, half b) { return a < b ? a : b; } static inline half max(half a, half b) { return a > b ? a : b; } static inline half clamp(half x, half a, half b) { return (x < a) ? a : (x > b) ? b : x; } #define DECLARE_COERCE_HALF_NUMERIC_OPS(op, type, ret, x2, h2) \ inline ret operator op(type x, half h) { return x2 op h2; } \
• ## trunk/src/lol/math/real.h

 r1163 bool operator !() const; operator bool() const; /* Comparison functions */ template friend Real min(Real const &a, Real const &b); template friend Real max(Real const &a, Real const &b); template friend Real clamp(Real const &x, Real const &a, Real const &b); /* Trigonometric functions */ template<> real::operator bool() const; template<> real min(real const &a, real const &b); template<> real max(real const &a, real const &b); template<> real clamp(real const &x, real const &a, real const &b); template<> real sin(real const &x); template<> real cos(real const &x);
• ## trunk/src/lol/math/vector.h

 r1305 */ /* * vec +(vec, vec)   (also complex & quaternion) * vec -(vec, vec)   (also complex & quaternion) * vec *(vec, vec) * vec /(vec, vec) */ #define DECLARE_VECTOR_VECTOR_COERCE_OP(tname, op, tprefix, t1, t2, tf) \ tprefix \ } /* * vec +=(vec, vec)   (also complex & quaternion) * vec -=(vec, vec)   (also complex & quaternion) * vec *=(vec, vec) * vec /=(vec, vec) */ #define DECLARE_VECTOR_VECTOR_OP(tname, op, tprefix, type) \ tprefix \ } /* * vec min(vec, vec)     (also max) * vec min(vec, scalar)  (also max) * vec min(scalar, vec)  (also max) */ #define DECLARE_VECTOR_MINMAX_OP(tname, op, tprefix, type) \ tprefix \ inline tname op(tname const &a, tname const &b) \ { \ using std::op; \ tname ret; \ for (size_t n = 0; n < sizeof(a) / sizeof(type); n++) \ ret[n] = op(a[n], b[n]); \ return ret; \ } \ \ tprefix \ inline tname op(tname const &a, type const &b) \ { \ using std::op; \ tname ret; \ for (size_t n = 0; n < sizeof(a) / sizeof(type); n++) \ ret[n] = op(a[n], b); \ return ret; \ } \ \ tprefix \ inline tname op(type const &a, tname const &b) \ { \ using std::op; \ tname ret; \ for (size_t n = 0; n < sizeof(b) / sizeof(type); n++) \ ret[n] = op(a, b[n]); \ return ret; \ } /* * vec clamp(vec, vec, vec) * vec clamp(vec, vec, scalar) * vec clamp(vec, scalar, vec) */ #define DECLARE_VECTOR_CLAMP_OP(tname, tprefix, type) \ tprefix \ inline tname clamp(tname const &x, \ tname const &a, tname const &b) \ { \ return max(min(x, b), a); \ } \ \ tprefix \ inline tname clamp(tname const &x, \ type const &a, tname const &b) \ { \ return max(min(x, b), a); \ } \ \ tprefix \ inline tname clamp(tname const &x, \ tname const &a, type const &b) \ { \ return max(min(x, b), a); \ } /* * bool ==(vec, vec)   (also complex & quaternion) * bool !=(vec, vec)   (also complex & quaternion) * bool >=(vec, vec) * bool <=(vec, vec) * bool >(vec, vec) * bool <(vec, vec) */ #define DECLARE_VECTOR_VECTOR_BOOLOP(tname, op, op2, ret, tprefix, t1, t2) \ tprefix \ } /* * vec *(vec, scalar)   (also complex & quaternion) * vec *(scalar, vec)   (also complex & quaternion) * vec /(vec, scalar)   (also complex & quaternion) * vec /(scalar, vec)   (also complex & quaternion) */ #define DECLARE_VECTOR_SCALAR_COERCE_OP(tname, op, tprefix, t1, t2, tf) \ tprefix \ } /* * vec *=(vec, scalar)   (also complex & quaternion) * vec /=(vec, scalar)   (also complex & quaternion) */ #define DECLARE_VECTOR_SCALAR_OP(tname, op, tprefix, type) \ tprefix \ \ DECLARE_VECTOR_VECTOR_OP(tname, -, tprefix, type) \ DECLARE_VECTOR_VECTOR_OP(tname, +, tprefix, type) DECLARE_VECTOR_VECTOR_OP(tname, +, tprefix, type) \ \ DECLARE_VECTOR_MINMAX_OP(tname, min, tprefix, type) \ DECLARE_VECTOR_MINMAX_OP(tname, max, tprefix, type) \ DECLARE_VECTOR_CLAMP_OP(tname, tprefix, type) #define DECLARE_VECTOR_COERCE_OPS(tname, tprefix, t1, t2, tf) \
• ## trunk/src/math/real.cpp

 r1180 } template<> real min(real const &a, real const &b) { return (a < b) ? a : b; } template<> real max(real const &a, real const &b) { return (a > b) ? a : b; } template<> real clamp(real const &x, real const &a, real const &b) { return (x < a) ? a : (x > b) ? b : x; } template<> real re(real const &x) {
Note: See TracChangeset for help on using the changeset viewer.