From 284c1c0514168e30338f2ad372b7e7f185dba0c4 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 1 Jul 2014 22:39:37 +0100 Subject: Vector clamping fixes Thank you, @madmaxoft. --- src/Vector3.h | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) (limited to 'src/Vector3.h') diff --git a/src/Vector3.h b/src/Vector3.h index b5ddc705a..faf7fe43c 100644 --- a/src/Vector3.h +++ b/src/Vector3.h @@ -135,19 +135,13 @@ public: } /** Runs each value of the vector through std::floor() */ - inline void Floor(void) + inline Vector3 Floor(void) const { - x = (T)floor(x); - y = (T)floor(y); - z = (T)floor(z); - } - - /** Clamps each value in the vector to within a specified range */ - inline void Clamp(T a_MinX, T a_MinY, T a_MinZ, T a_MaxX, T a_MaxY, T a_MaxZ) - { - x = Clamp(x, (T)copysign(a_MinX, x), (T)copysign(a_MaxX, x)); - y = Clamp(y, (T)copysign(a_MinY, y), (T)copysign(a_MaxY, y)); - z = Clamp(z, (T)copysign(a_MinZ, z), (T)copysign(a_MaxZ, z)); + return Vector3( + (T)floor(x), + (T)floor(y), + (T)floor(z) + ); } // tolua_end @@ -162,6 +156,16 @@ public: return Equals(a_Rhs); } + inline bool operator > (const Vector3 & a_Rhs) const + { + return (SqrLength() > a_Rhs.SqrLength()); + } + + inline bool operator < (const Vector3 & a_Rhs) const + { + return (SqrLength() < a_Rhs.SqrLength()); + } + inline void operator += (const Vector3 & a_Rhs) { x += a_Rhs.x; @@ -305,11 +309,6 @@ protected: return (a_Value < 0) ? -a_Value : a_Value; } - /** Clamp X to the specified range. */ - T Clamp(T a_Value, T a_Min, T a_Max) - { - return (a_Value < a_Min) ? a_Min : ((a_Value > a_Max) ? a_Max : a_Value); - } }; // tolua_end -- cgit v1.2.3