From 6afce5da27615bca18e72ca387b1ae7904a075b8 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Thu, 26 Jul 2018 11:54:04 +0200 Subject: [PATCH] Added missing equal and notEqual function for mat --- glm/ext/vector_relational.hpp | 24 ++++++++++++++++++++++++ glm/ext/vector_relational.inl | 20 ++++++++++++++++---- test/ext/ext_vector_relational.cpp | 2 ++ 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/glm/ext/vector_relational.hpp b/glm/ext/vector_relational.hpp index 0529baae..dfe3dbed 100644 --- a/glm/ext/vector_relational.hpp +++ b/glm/ext/vector_relational.hpp @@ -25,6 +25,18 @@ namespace glm /// @addtogroup ext_vector_relational /// @{ + /// Returns the component-wise comparison of |x - y| <= 0.0. + /// True if this expression is satisfied. + /// + /// @tparam C Integer between 1 and 4 included that qualify the number of columns of the matrix + /// @tparam R Integer between 1 and 4 included that qualify the number of rows of the matrix + /// @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); + /// Returns the component-wise comparison of |x - y| < epsilon. /// True if this expression is satisfied. /// @@ -80,6 +92,18 @@ namespace glm template GLM_FUNC_DECL bool equal(genType const& x, genType const& y, genType const& epsilon); + /// Returns the component-wise comparison of |x - y| <= 0.0. + /// True if this expression is not satisfied. + /// + /// @tparam C Integer between 1 and 4 included that qualify the number of columns of the matrix + /// @tparam R Integer between 1 and 4 included that qualify the number of rows of the matrix + /// @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); + /// Returns the component-wise comparison of |x - y| < epsilon. /// True if this expression is not satisfied. /// diff --git a/glm/ext/vector_relational.inl b/glm/ext/vector_relational.inl index 0cacb3ed..eec20274 100644 --- a/glm/ext/vector_relational.inl +++ b/glm/ext/vector_relational.inl @@ -11,7 +11,7 @@ namespace glm template GLM_FUNC_QUALIFIER bool equal(genType const& x, genType const& y, genType const& epsilon) { - return abs(x - y) < epsilon; + return abs(x - y) <= epsilon; } template @@ -23,7 +23,13 @@ namespace glm template GLM_FUNC_QUALIFIER vec equal(vec const& x, vec const& y, vec const& epsilon) { - return lessThan(abs(x - y), epsilon); + return lessThanEqual(abs(x - y), epsilon); + } + + template + GLM_FUNC_QUALIFIER vec equal(mat const& a, mat const& b) + { + return equal(a, b, static_cast(0)); } template @@ -44,7 +50,7 @@ namespace glm template GLM_FUNC_QUALIFIER bool notEqual(genType const& x, genType const& y, genType const& epsilon) { - return abs(x - y) >= epsilon; + return abs(x - y) > epsilon; } template @@ -56,7 +62,13 @@ namespace glm template GLM_FUNC_QUALIFIER vec notEqual(vec const& x, vec const& y, vec const& epsilon) { - return greaterThanEqual(abs(x - y), epsilon); + return greaterThan(abs(x - y), epsilon); + } + + template + GLM_FUNC_QUALIFIER vec notEqual(mat const& x, mat const& y) + { + return notEqual(x, y, static_cast(0)); } template diff --git a/test/ext/ext_vector_relational.cpp b/test/ext/ext_vector_relational.cpp index 2e605f9e..0599c570 100644 --- a/test/ext/ext_vector_relational.cpp +++ b/test/ext/ext_vector_relational.cpp @@ -16,6 +16,7 @@ int test_equal() 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; + Error += glm::all(glm::equal(glm::mat4x3(1), glm::mat4x3(1))) ? 0 : 1; return Error; } @@ -34,6 +35,7 @@ int test_notEqual() 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; + Error += !glm::any(glm::notEqual(glm::mat4x3(1), glm::mat4x3(1))) ? 0 : 1; return Error; }