From c74bfc35d61022c1d1e660935601d461b39b8b88 Mon Sep 17 00:00:00 2001 From: Woazboat Date: Tue, 28 Apr 2015 02:47:36 +0200 Subject: Check for zero length vector in Trace Added hasNonZeroLength member function to Vector3 --- src/Vector3.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/Vector3.h') diff --git a/src/Vector3.h b/src/Vector3.h index 36f277ba4..a42003aae 100644 --- a/src/Vector3.h +++ b/src/Vector3.h @@ -78,6 +78,11 @@ public: ); } + inline bool HasNonZeroLength(void) const + { + return ((x != 0) || (y != 0) || (z != 0)); + } + inline double Length(void) const { return sqrt(static_cast(x * x + y * y + z * z)); -- cgit v1.2.3 From 689fe6041c746d608330700160d3a71fb182be0b Mon Sep 17 00:00:00 2001 From: Woazboat Date: Tue, 28 Apr 2015 02:54:45 +0200 Subject: Changed Vector3 Equals function to avoid using memcmp --- src/Vector3.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'src/Vector3.h') diff --git a/src/Vector3.h b/src/Vector3.h index a42003aae..6164721da 100644 --- a/src/Vector3.h +++ b/src/Vector3.h @@ -126,11 +126,7 @@ public: { // 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) - ); + return !((x != a_Rhs.x) || (y != a_Rhs.y) || (z != a_Rhs.z)); } inline bool EqualsEps(const Vector3 & a_Rhs, T a_Eps) const -- cgit v1.2.3 From ed404bc2f6488a59da280697ad6c3a8ffcbab0fd Mon Sep 17 00:00:00 2001 From: Woazboat Date: Tue, 5 May 2015 22:21:07 +0200 Subject: Ignoring Clang warnings for strict float comparison in Vector::Equals() --- src/Vector3.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/Vector3.h') diff --git a/src/Vector3.h b/src/Vector3.h index 6164721da..d454fda06 100644 --- a/src/Vector3.h +++ b/src/Vector3.h @@ -124,9 +124,19 @@ public: inline bool Equals(const Vector3 & a_Rhs) const { - // Perform a bitwise comparison of the contents - we want to know whether this object is exactly equal + // Perform a strict comparison of the contents - we want to know whether this object is exactly equal // To perform EPS-based comparison, use the EqualsEps() function + +#ifndef __GNUC__ +#pragma clang diagnostics push +#pragma clang diagnostics ignored "-Wfloat-equal" +#endif + return !((x != a_Rhs.x) || (y != a_Rhs.y) || (z != a_Rhs.z)); + +#ifndef __GNUC__ +#pragma clang diagnostics pop +#endif } inline bool EqualsEps(const Vector3 & a_Rhs, T a_Eps) const -- cgit v1.2.3 From eb84ffe5a6eb4a79b91e58c263bf222496ad5afb Mon Sep 17 00:00:00 2001 From: Woazboat Date: Wed, 6 May 2015 01:53:28 +0200 Subject: Added float comparison warning overrides to Vector3::hasNonZeroLength --- src/Vector3.h | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'src/Vector3.h') diff --git a/src/Vector3.h b/src/Vector3.h index d454fda06..f116c07f6 100644 --- a/src/Vector3.h +++ b/src/Vector3.h @@ -80,7 +80,16 @@ public: inline bool HasNonZeroLength(void) const { + #ifndef __GNUC__ + #pragma clang diagnostics push + #pragma clang diagnostics ignored "-Wfloat-equal" + #endif + return ((x != 0) || (y != 0) || (z != 0)); + + #ifndef __GNUC__ + #pragma clang diagnostics pop + #endif } inline double Length(void) const @@ -127,16 +136,16 @@ public: // Perform a strict comparison of the contents - we want to know whether this object is exactly equal // To perform EPS-based comparison, use the EqualsEps() function -#ifndef __GNUC__ -#pragma clang diagnostics push -#pragma clang diagnostics ignored "-Wfloat-equal" -#endif + #ifndef __GNUC__ + #pragma clang diagnostics push + #pragma clang diagnostics ignored "-Wfloat-equal" + #endif return !((x != a_Rhs.x) || (y != a_Rhs.y) || (z != a_Rhs.z)); -#ifndef __GNUC__ -#pragma clang diagnostics pop -#endif + #ifndef __GNUC__ + #pragma clang diagnostics pop + #endif } inline bool EqualsEps(const Vector3 & a_Rhs, T a_Eps) const -- cgit v1.2.3