From 56bd959f9e5ce37ff1578127eb64e9274031371d Mon Sep 17 00:00:00 2001 From: Janis Born Date: Thu, 19 Dec 2013 16:16:28 +0100 Subject: [PATCH 1/6] fix vector angle functions possibly returning NaN --- glm/gtx/vector_angle.inl | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/glm/gtx/vector_angle.inl b/glm/gtx/vector_angle.inl index 39e04f22..737e1cef 100644 --- a/glm/gtx/vector_angle.inl +++ b/glm/gtx/vector_angle.inl @@ -18,10 +18,12 @@ namespace glm { GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'angle' only accept floating-point inputs"); + genType Dot = clamp(dot(x, y), genType(0), genType(1)); + #ifdef GLM_FORCE_RADIANS - return acos(dot(x, y)); + return acos(Dot); #else - return degrees(acos(dot(x, y))); + return degrees(acos(Dot)); #endif } @@ -34,10 +36,12 @@ namespace glm { GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'angle' only accept floating-point inputs"); + T Dot = clamp(dot(x, y), T(0), T(1)); + #ifdef GLM_FORCE_RADIANS - return acos(dot(x, y)); + return acos(Dot); #else - return degrees(acos(dot(x, y))); + return degrees(acos(Dot)); #endif } @@ -51,10 +55,12 @@ namespace glm { GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'orientedAngle' only accept floating-point inputs"); + T Dot = clamp(dot(x, y), T(0), T(1)); + #ifdef GLM_FORCE_RADIANS - T const Angle(acos(dot(x, y))); + T const Angle(acos(Dot)); #else - T const Angle(degrees(acos(dot(x, y)))); + T const Angle(degrees(acos(Dot))); #endif detail::tvec2 const TransformedVector(glm::rotate(x, Angle)); if(all(epsilonEqual(y, TransformedVector, T(0.01)))) @@ -73,10 +79,12 @@ namespace glm { GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'orientedAngle' only accept floating-point inputs"); + T Dot = clamp(dot(x, y), T(0), T(1)); + #ifdef GLM_FORCE_RADIANS - T const Angle(acos(dot(x, y))); + T const Angle(acos(Dot)); #else - T const Angle(degrees(acos(dot(x, y)))); + T const Angle(degrees(acos(Dot))); #endif if(dot(ref, cross(x, y)) < T(0)) From 0de006a82cdfef82ab278c97b3e04a9aff9799f1 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Thu, 26 Dec 2013 00:20:08 +0100 Subject: [PATCH 2/6] Updated version for next release --- glm/detail/setup.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glm/detail/setup.hpp b/glm/detail/setup.hpp index 2647d5e3..8579d825 100644 --- a/glm/detail/setup.hpp +++ b/glm/detail/setup.hpp @@ -38,7 +38,7 @@ #define GLM_VERSION_MAJOR 0 #define GLM_VERSION_MINOR 9 #define GLM_VERSION_PATCH 5 -#define GLM_VERSION_REVISION 0 +#define GLM_VERSION_REVISION 1 /////////////////////////////////////////////////////////////////////////////////////////////////// // Platform From d68fd2d97eba7e8138b63082dadf699773e76fec Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Thu, 26 Dec 2013 00:32:09 +0100 Subject: [PATCH 3/6] Fixed space characters --- glm/gtx/vector_angle.inl | 24 ++++++++++++------------ readme.txt | 7 ++++++- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/glm/gtx/vector_angle.inl b/glm/gtx/vector_angle.inl index 737e1cef..c51dfb4c 100644 --- a/glm/gtx/vector_angle.inl +++ b/glm/gtx/vector_angle.inl @@ -18,12 +18,12 @@ namespace glm { GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'angle' only accept floating-point inputs"); - genType Dot = clamp(dot(x, y), genType(0), genType(1)); + genType const Angle(acos(clamp(dot(x, y), genType(0), genType(1)))); #ifdef GLM_FORCE_RADIANS - return acos(Dot); + return Angle; #else - return degrees(acos(Dot)); + return degrees(Angle); #endif } @@ -36,12 +36,12 @@ namespace glm { GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'angle' only accept floating-point inputs"); - T Dot = clamp(dot(x, y), T(0), T(1)); + genType const Angle(acos(clamp(dot(x, y), T(0), T(1))); #ifdef GLM_FORCE_RADIANS - return acos(Dot); + return Angle; #else - return degrees(acos(Dot)); + return degrees(Angle); #endif } @@ -55,12 +55,12 @@ namespace glm { GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'orientedAngle' only accept floating-point inputs"); - T Dot = clamp(dot(x, y), T(0), T(1)); + T const Dot = clamp(dot(x, y), T(0), T(1)); #ifdef GLM_FORCE_RADIANS - T const Angle(acos(Dot)); + T const Angle(acos(Dot)); #else - T const Angle(degrees(acos(Dot))); + T const Angle(degrees(acos(Dot))); #endif detail::tvec2 const TransformedVector(glm::rotate(x, Angle)); if(all(epsilonEqual(y, TransformedVector, T(0.01)))) @@ -79,12 +79,12 @@ namespace glm { GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'orientedAngle' only accept floating-point inputs"); - T Dot = clamp(dot(x, y), T(0), T(1)); + T const Dot = clamp(dot(x, y), T(0), T(1)); #ifdef GLM_FORCE_RADIANS - T const Angle(acos(Dot)); + T const Angle(acos(Dot)); #else - T const Angle(degrees(acos(Dot))); + T const Angle(degrees(acos(Dot))); #endif if(dot(ref, cross(x, y)) < T(0)) diff --git a/readme.txt b/readme.txt index 30a5b16e..ea6fc64a 100644 --- a/readme.txt +++ b/readme.txt @@ -36,7 +36,12 @@ GLM is a header only library, there is nothing to build, just include it. More informations in GLM manual: http://glm.g-truc.net/glm.pdf -================================================================================s +================================================================================ +GLM 0.9.5.1: 2014-XX-XX +-------------------------------------------------------------------------------- +- Fixed angle and orientedAngle that sometimes return NaN values (#145) + +================================================================================ GLM 0.9.5.0: 2013-12-25 -------------------------------------------------------------------------------- - Added forward declarations (glm/fwd.hpp) for faster compilations From 7fc5d21bbf6ad5fd7396fc63222b577b6aa5a131 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Thu, 26 Dec 2013 01:24:04 +0100 Subject: [PATCH 4/6] Fixed build --- glm/gtx/vector_angle.inl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glm/gtx/vector_angle.inl b/glm/gtx/vector_angle.inl index c51dfb4c..c361314b 100644 --- a/glm/gtx/vector_angle.inl +++ b/glm/gtx/vector_angle.inl @@ -36,7 +36,7 @@ namespace glm { GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'angle' only accept floating-point inputs"); - genType const Angle(acos(clamp(dot(x, y), T(0), T(1))); + T const Angle(acos(clamp(dot(x, y), T(0), T(1)))); #ifdef GLM_FORCE_RADIANS return Angle; From 6b2ecaaf42573323702da6048e4bdea02c1dd7c2 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Thu, 26 Dec 2013 02:46:34 +0100 Subject: [PATCH 5/6] Clean up --- glm/detail/func_common.inl | 12 ++++++------ test/core/core_func_common.cpp | 14 +++++++------- test/core/core_type_mat4x4.cpp | 2 ++ test/core/core_type_vec4.cpp | 16 ++++++++++++++++ 4 files changed, 31 insertions(+), 13 deletions(-) diff --git a/glm/detail/func_common.inl b/glm/detail/func_common.inl index c7c15bc7..02e68b78 100644 --- a/glm/detail/func_common.inl +++ b/glm/detail/func_common.inl @@ -37,13 +37,13 @@ namespace glm{ namespace detail { template - struct Abs_ + struct compute_abs {}; template - struct Abs_ + struct compute_abs { - GLM_FUNC_QUALIFIER static genFIType get(genFIType const & x) + GLM_FUNC_QUALIFIER static genFIType call(genFIType const & x) { GLM_STATIC_ASSERT( std::numeric_limits::is_iec559 || std::numeric_limits::is_signed, @@ -54,9 +54,9 @@ namespace detail }; template - struct Abs_ + struct compute_abs { - GLM_FUNC_QUALIFIER static genFIType get(genFIType const & x) + GLM_FUNC_QUALIFIER static genFIType call(genFIType const & x) { GLM_STATIC_ASSERT( !std::numeric_limits::is_signed && std::numeric_limits::is_integer, @@ -73,7 +73,7 @@ namespace detail genFIType const & x ) { - return detail::Abs_::is_signed>::get(x); + return detail::compute_abs::is_signed>::call(x); } VECTORIZE_VEC(abs) diff --git a/test/core/core_func_common.cpp b/test/core/core_func_common.cpp index 43d02378..916633c8 100644 --- a/test/core/core_func_common.cpp +++ b/test/core/core_func_common.cpp @@ -391,19 +391,19 @@ int test_round() Error += G == 2.0f ? 0 : 1; #if GLM_LANG >= GLM_LANG_CXX11 - float A1 = std::round(0.0f); + float A1 = glm::round(0.0f); Error += A1 == A ? 0 : 1; - float B1 = std::round(0.5f); + float B1 = glm::round(0.5f); Error += B1 == B ? 0 : 1; - float C1 = std::round(1.0f); + float C1 = glm::round(1.0f); Error += C1 == C ? 0 : 1; - float D1 = std::round(0.1f); + float D1 = glm::round(0.1f); Error += D1 == D ? 0 : 1; - float E1 = std::round(0.9f); + float E1 = glm::round(0.9f); Error += E1 == E ? 0 : 1; - float F1 = std::round(1.5f); + float F1 = glm::round(1.5f); Error += F == F ? 0 : 1; - float G1 = std::round(1.9f); + float G1 = glm::round(1.9f); Error += G1 == G ? 0 : 1; #endif // GLM_LANG >= GLM_CXX0X } diff --git a/test/core/core_type_mat4x4.cpp b/test/core/core_type_mat4x4.cpp index e9f6b31e..20a0552a 100644 --- a/test/core/core_type_mat4x4.cpp +++ b/test/core/core_type_mat4x4.cpp @@ -135,6 +135,8 @@ int test_ctr() glm::vec4(8, 9, 10, 11), glm::vec4(12, 13, 14, 15)); + assert(sizeof(m0) == 4 * 4 * 4); + glm::mat4 m1{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; glm::mat4 m2{ diff --git a/test/core/core_type_vec4.cpp b/test/core/core_type_vec4.cpp index 0fa2b4ec..d79e3af5 100644 --- a/test/core/core_type_vec4.cpp +++ b/test/core/core_type_vec4.cpp @@ -362,12 +362,28 @@ int test_vec4_perf_SoA(std::size_t Size) return Error; } +/* +struct simd_vec4 +{ + union + { + __m128 data; + union { float x, r, s; }; + union { float y, g, t; }; + union { float z, b, p; }; + union { float w, a, q; }; + }; +}; +*/ + int main() { //__m128 DataA = swizzle(glm::vec4(1.0f, 2.0f, 3.0f, 4.0f)); //__m128 DataB = swizzle(glm::vec4(1.0f, 2.0f, 3.0f, 4.0f)); int Error(0); + + glm::vec4 v(1.0, 0.5, 0.0, 1.0); std::size_t const Size(1000000); From 36de7ea9e98a19df2c7617895936171c411ff359 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Thu, 26 Dec 2013 13:14:50 +0100 Subject: [PATCH 6/6] Clean up --- test/core/core_type_vec4.cpp | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/test/core/core_type_vec4.cpp b/test/core/core_type_vec4.cpp index d79e3af5..f63b689b 100644 --- a/test/core/core_type_vec4.cpp +++ b/test/core/core_type_vec4.cpp @@ -357,34 +357,15 @@ int test_vec4_perf_SoA(std::size_t Size) std::clock_t EndTime = std::clock(); - std::printf("SoA: %d\n", EndTime - StartTime); + std::printf("SoA: %d\n", EndTime - StartTime); return Error; } -/* -struct simd_vec4 -{ - union - { - __m128 data; - union { float x, r, s; }; - union { float y, g, t; }; - union { float z, b, p; }; - union { float w, a, q; }; - }; -}; -*/ - int main() { - //__m128 DataA = swizzle(glm::vec4(1.0f, 2.0f, 3.0f, 4.0f)); - //__m128 DataB = swizzle(glm::vec4(1.0f, 2.0f, 3.0f, 4.0f)); - int Error(0); - glm::vec4 v(1.0, 0.5, 0.0, 1.0); - std::size_t const Size(1000000); Error += test_vec4_perf_AoS(Size);