diff options
Diffstat (limited to 'indra/llmath/v2math.h')
-rw-r--r-- | indra/llmath/v2math.h | 140 |
1 files changed, 70 insertions, 70 deletions
diff --git a/indra/llmath/v2math.h b/indra/llmath/v2math.h index a61c946304..a0ba3ec505 100644 --- a/indra/llmath/v2math.h +++ b/indra/llmath/v2math.h @@ -36,7 +36,7 @@ class LLQuaternion; // Llvector2 = |x y z w| -static const U32 LENGTHOFVECTOR2 = 2; +static constexpr U32 LENGTHOFVECTOR2 = 2; class LLVector2 { @@ -82,7 +82,7 @@ class LLVector2 const LLVector2& scaleVec(const LLVector2& vec); // scales per component by vec - bool isNull(); // Returns true if vector has a _very_small_ length + bool isNull() const; // Returns true if vector has a _very_small_ length bool isExactlyZero() const { return !mV[VX] && !mV[VY]; } F32 operator[](int idx) const { return mV[idx]; } @@ -113,16 +113,16 @@ class LLVector2 // Non-member functions -F32 angle_between(const LLVector2 &a, const LLVector2 &b); // Returns angle (radians) between a and b -bool are_parallel(const LLVector2 &a, const LLVector2 &b, F32 epsilon=F_APPROXIMATELY_ZERO); // Returns true if a and b are very close to parallel -F32 dist_vec(const LLVector2 &a, const LLVector2 &b); // Returns distance between a and b -F32 dist_vec_squared(const LLVector2 &a, const LLVector2 &b);// Returns distance squared between a and b -F32 dist_vec_squared2D(const LLVector2 &a, const LLVector2 &b);// Returns distance squared between a and b ignoring Z component -LLVector2 lerp(const LLVector2 &a, const LLVector2 &b, F32 u); // Returns a vector that is a linear interpolation between a and b +F32 angle_between(const LLVector2& a, const LLVector2& b); // Returns angle (radians) between a and b +bool are_parallel(const LLVector2& a, const LLVector2& b, F32 epsilon = F_APPROXIMATELY_ZERO); // Returns true if a and b are very close to parallel +F32 dist_vec(const LLVector2& a, const LLVector2& b); // Returns distance between a and b +F32 dist_vec_squared(const LLVector2& a, const LLVector2& b);// Returns distance squared between a and b +F32 dist_vec_squared2D(const LLVector2& a, const LLVector2& b);// Returns distance squared between a and b ignoring Z component +LLVector2 lerp(const LLVector2& a, const LLVector2& b, F32 u); // Returns a vector that is a linear interpolation between a and b // Constructors -inline LLVector2::LLVector2(void) +inline LLVector2::LLVector2() { mV[VX] = 0.f; mV[VY] = 0.f; @@ -153,27 +153,27 @@ inline LLVector2::LLVector2(const LLSD &sd) // Clear and Assignment Functions -inline void LLVector2::clear(void) +inline void LLVector2::clear() { mV[VX] = 0.f; mV[VY] = 0.f; } -inline void LLVector2::setZero(void) +inline void LLVector2::setZero() { mV[VX] = 0.f; mV[VY] = 0.f; } // deprecated -inline void LLVector2::clearVec(void) +inline void LLVector2::clearVec() { mV[VX] = 0.f; mV[VY] = 0.f; } // deprecated -inline void LLVector2::zeroVec(void) +inline void LLVector2::zeroVec() { mV[VX] = 0.f; mV[VY] = 0.f; @@ -222,31 +222,31 @@ inline void LLVector2::setVec(const F32 *vec) // LLVector2 Magnitude and Normalization Functions -inline F32 LLVector2::length(void) const +inline F32 LLVector2::length() const { - return (F32) sqrt(mV[0]*mV[0] + mV[1]*mV[1]); + return sqrt(mV[VX]*mV[VX] + mV[VY]*mV[VY]); } -inline F32 LLVector2::lengthSquared(void) const +inline F32 LLVector2::lengthSquared() const { - return mV[0]*mV[0] + mV[1]*mV[1]; + return mV[VX]*mV[VX] + mV[VY]*mV[VY]; } -inline F32 LLVector2::normalize(void) +inline F32 LLVector2::normalize() { - F32 mag = (F32) sqrt(mV[0]*mV[0] + mV[1]*mV[1]); + F32 mag = sqrt(mV[VX]*mV[VX] + mV[VY]*mV[VY]); F32 oomag; if (mag > FP_MAG_THRESHOLD) { oomag = 1.f/mag; - mV[0] *= oomag; - mV[1] *= oomag; + mV[VX] *= oomag; + mV[VY] *= oomag; } else { - mV[0] = 0.f; - mV[1] = 0.f; + mV[VX] = 0.f; + mV[VY] = 0.f; mag = 0; } return (mag); @@ -259,33 +259,33 @@ inline bool LLVector2::isFinite() const } // deprecated -inline F32 LLVector2::magVec(void) const +inline F32 LLVector2::magVec() const { - return (F32) sqrt(mV[0]*mV[0] + mV[1]*mV[1]); + return sqrt(mV[VX]*mV[VX] + mV[VY]*mV[VY]); } // deprecated -inline F32 LLVector2::magVecSquared(void) const +inline F32 LLVector2::magVecSquared() const { - return mV[0]*mV[0] + mV[1]*mV[1]; + return mV[VX]*mV[VX] + mV[VY]*mV[VY]; } // deprecated -inline F32 LLVector2::normVec(void) +inline F32 LLVector2::normVec() { - F32 mag = (F32) sqrt(mV[0]*mV[0] + mV[1]*mV[1]); + F32 mag = sqrt(mV[VX]*mV[VX] + mV[VY]*mV[VY]); F32 oomag; if (mag > FP_MAG_THRESHOLD) { oomag = 1.f/mag; - mV[0] *= oomag; - mV[1] *= oomag; + mV[VX] *= oomag; + mV[VY] *= oomag; } else { - mV[0] = 0.f; - mV[1] = 0.f; + mV[VX] = 0.f; + mV[VY] = 0.f; mag = 0; } return (mag); @@ -299,7 +299,7 @@ inline const LLVector2& LLVector2::scaleVec(const LLVector2& vec) return *this; } -inline bool LLVector2::isNull() +inline bool LLVector2::isNull() const { if ( F_APPROXIMATELY_ZERO > mV[VX]*mV[VX] + mV[VY]*mV[VY] ) { @@ -312,7 +312,7 @@ inline bool LLVector2::isNull() // LLVector2 Operators // For sorting. By convention, x is "more significant" than y. -inline bool operator<(const LLVector2 &a, const LLVector2 &b) +inline bool operator<(const LLVector2& a, const LLVector2& b) { if( a.mV[VX] == b.mV[VX] ) { @@ -325,95 +325,95 @@ inline bool operator<(const LLVector2 &a, const LLVector2 &b) } -inline LLVector2 operator+(const LLVector2 &a, const LLVector2 &b) +inline LLVector2 operator+(const LLVector2& a, const LLVector2& b) { LLVector2 c(a); return c += b; } -inline LLVector2 operator-(const LLVector2 &a, const LLVector2 &b) +inline LLVector2 operator-(const LLVector2& a, const LLVector2& b) { LLVector2 c(a); return c -= b; } -inline F32 operator*(const LLVector2 &a, const LLVector2 &b) +inline F32 operator*(const LLVector2& a, const LLVector2& b) { - return (a.mV[0]*b.mV[0] + a.mV[1]*b.mV[1]); + return (a.mV[VX]*b.mV[VX] + a.mV[VY]*b.mV[VY]); } -inline LLVector2 operator%(const LLVector2 &a, const LLVector2 &b) +inline LLVector2 operator%(const LLVector2& a, const LLVector2& b) { - return LLVector2(a.mV[0]*b.mV[1] - b.mV[0]*a.mV[1], a.mV[1]*b.mV[0] - b.mV[1]*a.mV[0]); + return LLVector2(a.mV[VX]*b.mV[VY] - b.mV[VX]*a.mV[VY], a.mV[VY]*b.mV[VX] - b.mV[VY]*a.mV[VX]); } -inline LLVector2 operator/(const LLVector2 &a, F32 k) +inline LLVector2 operator/(const LLVector2& a, F32 k) { F32 t = 1.f / k; - return LLVector2( a.mV[0] * t, a.mV[1] * t ); + return LLVector2( a.mV[VX] * t, a.mV[VY] * t ); } -inline LLVector2 operator*(const LLVector2 &a, F32 k) +inline LLVector2 operator*(const LLVector2& a, F32 k) { - return LLVector2( a.mV[0] * k, a.mV[1] * k ); + return LLVector2( a.mV[VX] * k, a.mV[VY] * k ); } -inline LLVector2 operator*(F32 k, const LLVector2 &a) +inline LLVector2 operator*(F32 k, const LLVector2& a) { - return LLVector2( a.mV[0] * k, a.mV[1] * k ); + return LLVector2( a.mV[VX] * k, a.mV[VY] * k ); } -inline bool operator==(const LLVector2 &a, const LLVector2 &b) +inline bool operator==(const LLVector2& a, const LLVector2& b) { - return ( (a.mV[0] == b.mV[0]) - &&(a.mV[1] == b.mV[1])); + return ( (a.mV[VX] == b.mV[VX]) + &&(a.mV[VY] == b.mV[VY])); } -inline bool operator!=(const LLVector2 &a, const LLVector2 &b) +inline bool operator!=(const LLVector2& a, const LLVector2& b) { - return ( (a.mV[0] != b.mV[0]) - ||(a.mV[1] != b.mV[1])); + return ( (a.mV[VX] != b.mV[VX]) + ||(a.mV[VY] != b.mV[VY])); } -inline const LLVector2& operator+=(LLVector2 &a, const LLVector2 &b) +inline const LLVector2& operator+=(LLVector2& a, const LLVector2& b) { - a.mV[0] += b.mV[0]; - a.mV[1] += b.mV[1]; + a.mV[VX] += b.mV[VX]; + a.mV[VY] += b.mV[VY]; return a; } -inline const LLVector2& operator-=(LLVector2 &a, const LLVector2 &b) +inline const LLVector2& operator-=(LLVector2& a, const LLVector2& b) { - a.mV[0] -= b.mV[0]; - a.mV[1] -= b.mV[1]; + a.mV[VX] -= b.mV[VX]; + a.mV[VY] -= b.mV[VY]; return a; } -inline const LLVector2& operator%=(LLVector2 &a, const LLVector2 &b) +inline const LLVector2& operator%=(LLVector2& a, const LLVector2& b) { - LLVector2 ret(a.mV[0]*b.mV[1] - b.mV[0]*a.mV[1], a.mV[1]*b.mV[0] - b.mV[1]*a.mV[0]); + LLVector2 ret(a.mV[VX]*b.mV[VY] - b.mV[VX]*a.mV[VY], a.mV[VY]*b.mV[VX] - b.mV[VY]*a.mV[VX]); a = ret; return a; } -inline const LLVector2& operator*=(LLVector2 &a, F32 k) +inline const LLVector2& operator*=(LLVector2& a, F32 k) { - a.mV[0] *= k; - a.mV[1] *= k; + a.mV[VX] *= k; + a.mV[VY] *= k; return a; } -inline const LLVector2& operator/=(LLVector2 &a, F32 k) +inline const LLVector2& operator/=(LLVector2& a, F32 k) { F32 t = 1.f / k; - a.mV[0] *= t; - a.mV[1] *= t; + a.mV[VX] *= t; + a.mV[VY] *= t; return a; } -inline LLVector2 operator-(const LLVector2 &a) +inline LLVector2 operator-(const LLVector2& a) { - return LLVector2( -a.mV[0], -a.mV[1] ); + return LLVector2( -a.mV[VX], -a.mV[VY] ); } inline void update_min_max(LLVector2& min, LLVector2& max, const LLVector2& pos) @@ -431,7 +431,7 @@ inline void update_min_max(LLVector2& min, LLVector2& max, const LLVector2& pos) } } -inline std::ostream& operator<<(std::ostream& s, const LLVector2 &a) +inline std::ostream& operator<<(std::ostream& s, const LLVector2& a) { s << "{ " << a.mV[VX] << ", " << a.mV[VY] << " }"; return s; |