From 751bc4f7f7a4270afb08624d58672adb072a20da Mon Sep 17 00:00:00 2001 From: Groove Date: Thu, 26 Jul 2018 00:03:31 +0200 Subject: [PATCH] - Added missing equal and notEqual with epsilon for matrix types in EXT_vector_relational --- glm/ext/vector_relational.hpp | 52 +++++++++++++++++++++++++++--- glm/ext/vector_relational.inl | 38 +++++++++++++++++++--- readme.md | 3 +- test/ext/ext_vector_relational.cpp | 7 ++++ 4 files changed, 91 insertions(+), 9 deletions(-) diff --git a/glm/ext/vector_relational.hpp b/glm/ext/vector_relational.hpp index 64d96912..834d9ef9 100644 --- a/glm/ext/vector_relational.hpp +++ b/glm/ext/vector_relational.hpp @@ -25,6 +25,28 @@ namespace glm /// @addtogroup ext_vector_relational /// @{ + /// Returns the component-wise comparison of |x - y| < epsilon. + /// True if this expression is satisfied. + /// + /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector + /// @tparam T Floating-point or integer scalar types + /// @tparam Q Value from qualifier enum + /// + /// @see ext_vector_relational + template + GLM_FUNC_DECL vec equal(mat const& x, mat const& y, T epsilon); + + /// Returns the component-wise comparison of |x - y| < epsilon. + /// True if this expression is satisfied. + /// + /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector + /// @tparam T Floating-point or integer scalar types + /// @tparam Q Value from qualifier enum + /// + /// @see ext_vector_relational + template + GLM_FUNC_DECL vec equal(mat const& x, mat const& y, vec const& epsilon); + /// Returns the component-wise comparison of |x - y| < epsilon. /// True if this expression is satisfied. /// @@ -34,7 +56,7 @@ namespace glm /// /// @see ext_vector_relational template - GLM_FUNC_DECL vec equal(vec const& x, vec const& y, T const& epsilon); + GLM_FUNC_DECL vec equal(vec const& x, vec const& y, T epsilon); /// Returns the component-wise comparison of |x - y| < epsilon. /// True if this expression is satisfied. @@ -64,10 +86,32 @@ namespace glm /// @tparam Q Value from qualifier enum /// /// @see ext_vector_relational - template - GLM_FUNC_DECL vec notEqual(vec const& x, vec const& y, T const& epsilon); + template + GLM_FUNC_DECL vec notEqual(mat const& x, mat const& y, T epsilon); - /// Returns the component-wise comparison of |x - y| < epsilon. + /// Returns the component-wise comparison of |x - y| >= epsilon. + /// True if this expression is not satisfied. + /// + /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector + /// @tparam T Floating-point or integer scalar types + /// @tparam Q Value from qualifier enum + /// + /// @see ext_vector_relational + template + GLM_FUNC_DECL vec notEqual(mat const& x, mat const& y, vec const& epsilon); + + /// Returns the component-wise comparison of |x - y| >= epsilon. + /// True if this expression is not satisfied. + /// + /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector + /// @tparam T Floating-point or integer scalar types + /// @tparam Q Value from qualifier enum + /// + /// @see ext_vector_relational + template + GLM_FUNC_DECL vec notEqual(vec const& x, vec const& y, T epsilon); + + /// Returns the component-wise comparison of |x - y| >= epsilon. /// True if this expression is not satisfied. /// /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector diff --git a/glm/ext/vector_relational.inl b/glm/ext/vector_relational.inl index 8532a022..0cacb3ed 100644 --- a/glm/ext/vector_relational.inl +++ b/glm/ext/vector_relational.inl @@ -15,9 +15,9 @@ namespace glm } template - GLM_FUNC_QUALIFIER vec equal(vec const& x, vec const& y, T const& epsilon) + GLM_FUNC_QUALIFIER vec equal(vec const& x, vec const& y, T epsilon) { - return lessThan(abs(x - y), vec(epsilon)); + return equal(x, y, vec(epsilon)); } template @@ -26,6 +26,21 @@ namespace glm return lessThan(abs(x - y), epsilon); } + template + GLM_FUNC_QUALIFIER vec equal(mat const& a, mat const& b, T epsilon) + { + return equal(a, b, vec(epsilon)); + } + + template + GLM_FUNC_QUALIFIER vec equal(mat const& a, mat const& b, vec const& epsilon) + { + vec Result; + for(length_t i = 0, n = C; i < n; ++i) + Result[i] = all(equal(a[i], b[i], epsilon[i])); + return Result; + } + template GLM_FUNC_QUALIFIER bool notEqual(genType const& x, genType const& y, genType const& epsilon) { @@ -33,9 +48,9 @@ namespace glm } template - GLM_FUNC_QUALIFIER vec notEqual(vec const& x, vec const& y, T const& epsilon) + GLM_FUNC_QUALIFIER vec notEqual(vec const& x, vec const& y, T epsilon) { - return greaterThanEqual(abs(x - y), vec(epsilon)); + return notEqual(x, y, vec(epsilon)); } template @@ -43,4 +58,19 @@ namespace glm { return greaterThanEqual(abs(x - y), epsilon); } + + template + GLM_FUNC_QUALIFIER vec notEqual(mat const& x, mat const& y, T epsilon) + { + return notEqual(x, y, vec(epsilon)); + } + + template + GLM_FUNC_QUALIFIER vec notEqual(mat const& a, mat const& b, vec const& epsilon) + { + vec Result; + for(length_t i = 0, n = C; i < n; ++i) + Result[i] = any(notEqual(a[i], b[i], epsilon[i])); + return Result; + } }//namespace glm diff --git a/readme.md b/readme.md index 94e8ff3b..ff5cc9b4 100644 --- a/readme.md +++ b/readme.md @@ -61,7 +61,8 @@ glm::mat4 camera(float Translate, glm::vec2 const& Rotate) - Added missing vec1 based constructors - Redesigned constexpr support which excludes both SIMD and constexpr #783 - Added detection of Visual C++ 2017 toolsets -- Added missing equal and notEqual with epsilon for quaternion types +- Added missing equal and notEqual with epsilon for quaternion types in EXT_vector_relational +- Added missing equal and notEqual with epsilon for matrix types in EXT_vector_relational #### Fixes: - Fixed build problems due to printf and std::clock_t #778 diff --git a/test/ext/ext_vector_relational.cpp b/test/ext/ext_vector_relational.cpp index d8b19ba6..2e605f9e 100644 --- a/test/ext/ext_vector_relational.cpp +++ b/test/ext/ext_vector_relational.cpp @@ -1,5 +1,6 @@ #include #include +#include int test_equal() { @@ -13,6 +14,9 @@ int test_equal() Error += !glm::any(glm::equal(glm::vec2(1.01f), glm::vec2(1.02f), 0.001f)) ? 0 : 1; Error += !glm::any(glm::equal(glm::vec2(1.01f), glm::vec2(1.02f), glm::vec2(0.001f))) ? 0 : 1; + Error += glm::all(glm::equal(glm::mat4x3(1), glm::mat4x3(1), 0.001f)) ? 0 : 1; + Error += glm::all(glm::equal(glm::mat4x3(1), glm::mat4x3(2), glm::vec4(0.001f))) ? 1 : 0; + return Error; } @@ -28,6 +32,9 @@ int test_notEqual() Error += !glm::any(glm::notEqual(glm::vec2(1.01f), glm::vec2(1.02f), 0.1f)) ? 0 : 1; Error += !glm::any(glm::notEqual(glm::vec2(1.01f), glm::vec2(1.02f), glm::vec2(0.1f))) ? 0 : 1; + Error += !glm::any(glm::notEqual(glm::mat4x3(1), glm::mat4x3(1), 0.001f)) ? 0 : 1; + Error += !glm::any(glm::notEqual(glm::mat4x3(1), glm::mat4x3(2), glm::vec4(0.001f))) ? 1 : 0; + return Error; }