From cbf4a17e0594ebd408d207bb689fedd70f1419e2 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 2 May 2014 23:50:22 +0200 Subject: [PATCH 1/5] Attempted fix for CLang warnings in Vector3.h. C++11 seems to have deprecated classes that have custom copy-constructor but not a custom assignment operator. --- src/Vector3.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Vector3.h b/src/Vector3.h index 2c79f9ff1..4a1440b32 100644 --- a/src/Vector3.h +++ b/src/Vector3.h @@ -163,8 +163,16 @@ public: z *= a_v; } - // tolua_begin + template inline Vector3 & operator =(const Vector3 & a_Rhs) + { + x = (T)a_Rhs.x; + y = (T)a_Rhs.y; + z = (T)a_Rhs.z; + return *this; + } + // tolua_begin + inline Vector3 operator + (const Vector3& a_Rhs) const { return Vector3( From ee79bd10c2b6e38ca5bc850d6fd06a1b22170619 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 3 May 2014 19:34:46 +0200 Subject: [PATCH 2/5] Implemented a true assignment operator for Vector3. --- src/Vector3.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Vector3.h b/src/Vector3.h index 4a1440b32..32c26026a 100644 --- a/src/Vector3.h +++ b/src/Vector3.h @@ -163,7 +163,15 @@ public: z *= a_v; } - template inline Vector3 & operator =(const Vector3 & a_Rhs) + inline Vector3 & operator = (const Vector3 & a_Rhs) + { + x = a_Rhs.x; + y = a_Rhs.y; + z = a_Rhs.z; + return *this; + } + + template inline Vector3 & operator = (const Vector3 & a_Rhs) { x = (T)a_Rhs.x; y = (T)a_Rhs.y; From d4ae00434c9087f2597f335250bd063d874dd349 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 3 May 2014 19:57:34 +0200 Subject: [PATCH 3/5] Fixed float comparison warnings in Vector3. There's a bitwise comparison (Equals), and there's Eps-based comparison (EqualsEps). --- src/Vector3.h | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/Vector3.h b/src/Vector3.h index 32c26026a..30b8e748a 100644 --- a/src/Vector3.h +++ b/src/Vector3.h @@ -40,7 +40,6 @@ public: Vector3(const Vector3<_T> * a_Rhs) : x(a_Rhs->x), y(a_Rhs->y), z(a_Rhs->z) {} // tolua_begin - inline void Set(T a_x, T a_y, T a_z) { x = a_x; @@ -105,7 +104,18 @@ public: inline bool Equals(const Vector3 & a_Rhs) const { - return x == a_Rhs.x && y == a_Rhs.y && z == a_Rhs.z; + // Perform a bitwise comparison of the contents - we want to know whether this object is exactly equal + // To perform EPS-based comparison, use the EqualsEps() function + return ( + (memcmp(&x, &a_Rhs.x, sizeof(x)) == 0) && + (memcmp(&y, &a_Rhs.y, sizeof(y)) == 0) && + (memcmp(&z, &a_Rhs.z, sizeof(z)) == 0) + ); + } + + inline bool EqualsEps(const Vector3 & a_Rhs, T a_Eps) const + { + return (Abs(x - a_Rhs.x) < a_Eps) && (Abs(y - a_Rhs.y) < a_Eps) && (Abs(z - a_Rhs.z) < a_Eps); } inline bool operator == (const Vector3 & a_Rhs) const @@ -233,7 +243,7 @@ public: */ inline double LineCoeffToXYPlane(const Vector3 & a_OtherEnd, T a_Z) const { - if (abs(z - a_OtherEnd.z) < EPS) + if (Abs(z - a_OtherEnd.z) < EPS) { return NO_INTERSECTION; } @@ -248,7 +258,7 @@ public: */ inline double LineCoeffToXZPlane(const Vector3 & a_OtherEnd, T a_Y) const { - if (abs(y - a_OtherEnd.y) < EPS) + if (Abs(y - a_OtherEnd.y) < EPS) { return NO_INTERSECTION; } @@ -263,7 +273,7 @@ public: */ inline double LineCoeffToYZPlane(const Vector3 & a_OtherEnd, T a_X) const { - if (abs(x - a_OtherEnd.x) < EPS) + if (Abs(x - a_OtherEnd.x) < EPS) { return NO_INTERSECTION; } @@ -276,7 +286,15 @@ public: /** Return value of LineCoeffToPlane() if the line is parallel to the plane. */ static const double NO_INTERSECTION; + +protected: + /** Returns the absolute value of the given argument. + Templatized because the standard library differentiates between abs() and fabs(). */ + static T Abs(T a_Value) + { + return (a_Value < 0) ? -a_Value : a_Value; + } }; // tolua_end From b4496278a583747a82736d69b62684a1544d814e Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 3 May 2014 20:17:47 +0200 Subject: [PATCH 4/5] Removed the controversial Vector3::operator <. It hasn't been used in any C++ code and Lua doesn't need it. --- src/Vector3.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/Vector3.h b/src/Vector3.h index 30b8e748a..20f9b4ca7 100644 --- a/src/Vector3.h +++ b/src/Vector3.h @@ -123,12 +123,6 @@ public: return Equals(a_Rhs); } - inline bool operator < (const Vector3 & a_Rhs) - { - // return (x < a_Rhs.x) && (y < a_Rhs.y) && (z < a_Rhs.z); ? - return (x < a_Rhs.x) || (x == a_Rhs.x && y < a_Rhs.y) || (x == a_Rhs.x && y == a_Rhs.y && z < a_Rhs.z); - } - inline void Move(T a_X, T a_Y, T a_Z) { x += a_X; From 136aeb1f643d10561e975f9c5539043c9a9b647c Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 4 May 2014 13:29:32 +0200 Subject: [PATCH 5/5] Removed convert-assign operator. We want all conversions to be explicit, not hidden. --- src/Vector3.h | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/Vector3.h b/src/Vector3.h index 20f9b4ca7..276bf67c9 100644 --- a/src/Vector3.h +++ b/src/Vector3.h @@ -175,14 +175,6 @@ public: return *this; } - template inline Vector3 & operator = (const Vector3 & a_Rhs) - { - x = (T)a_Rhs.x; - y = (T)a_Rhs.y; - z = (T)a_Rhs.z; - return *this; - } - // tolua_begin inline Vector3 operator + (const Vector3& a_Rhs) const