diff --git a/glm/ext/matrix_relational.hpp b/glm/ext/matrix_relational.hpp index beddec2e..20023ad8 100644 --- a/glm/ext/matrix_relational.hpp +++ b/glm/ext/matrix_relational.hpp @@ -36,15 +36,15 @@ namespace glm template GLM_FUNC_DECL GLM_CONSTEXPR vec equal(mat const& x, mat const& y); - /// Returns the component-wise comparison of |x - y| < epsilon. - /// True if this expression is satisfied. + /// Perform a component-wise not-equal-to comparison of two matrices. + /// Return a boolean vector which components value is True if this expression is satisfied per column of the matrices. /// /// @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 template - GLM_FUNC_DECL GLM_CONSTEXPR vec equal(mat const& x, mat const& y, T epsilon); + GLM_FUNC_DECL GLM_CONSTEXPR vec notEqual(mat const& x, mat const& y); /// Returns the component-wise comparison of |x - y| < epsilon. /// True if this expression is satisfied. @@ -54,17 +54,17 @@ namespace glm /// @tparam T Floating-point or integer scalar types /// @tparam Q Value from qualifier enum template - GLM_FUNC_DECL GLM_CONSTEXPR vec equal(mat const& x, mat const& y, vec const& epsilon); + GLM_FUNC_DECL GLM_CONSTEXPR vec equal(mat const& x, mat const& y, T epsilon); - /// Perform a component-wise not-equal-to comparison of two matrices. - /// Return a boolean vector which components value is True if this expression is satisfied per column of the matrices. + /// Returns the component-wise comparison of |x - y| < epsilon. + /// 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 template - GLM_FUNC_DECL GLM_CONSTEXPR vec notEqual(mat const& x, mat const& y); + GLM_FUNC_DECL GLM_CONSTEXPR 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 not satisfied. @@ -86,6 +86,46 @@ namespace glm template GLM_FUNC_DECL GLM_CONSTEXPR vec notEqual(mat const& x, mat const& y, vec const& epsilon); + /// Returns the component-wise comparison between two vectors in term of ULPs. + /// 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 + /// @tparam Q Value from qualifier enum + template + GLM_FUNC_DECL GLM_CONSTEXPR vec equal(mat const& x, mat const& y, int ULPs); + + /// Returns the component-wise comparison between two vectors in term of ULPs. + /// 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 + /// @tparam Q Value from qualifier enum + template + GLM_FUNC_DECL GLM_CONSTEXPR vec equal(mat const& x, mat const& y, vec const& ULPs); + + /// Returns the component-wise comparison between two vectors in term of ULPs. + /// 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 + /// @tparam Q Value from qualifier enum + template + GLM_FUNC_DECL GLM_CONSTEXPR vec notEqual(mat const& x, mat const& y, int ULPs); + + /// Returns the component-wise comparison between two vectors in term of ULPs. + /// 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 + /// @tparam Q Value from qualifier enum + template + GLM_FUNC_DECL GLM_CONSTEXPR vec notEqual(mat const& x, mat const& y, vec const& ULPs); + /// @} }//namespace glm diff --git a/glm/ext/matrix_relational.inl b/glm/ext/matrix_relational.inl index f7a82dda..b2b87530 100644 --- a/glm/ext/matrix_relational.inl +++ b/glm/ext/matrix_relational.inl @@ -48,4 +48,35 @@ namespace glm Result[i] = any(notEqual(a[i], b[i], Epsilon[i])); return Result; } + + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec equal(mat const& a, mat const& b, int MaxULPs) + { + return equal(a, b, vec(MaxULPs)); + } + + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec equal(mat const& a, mat const& b, vec const& MaxULPs) + { + vec Result(true); + for(length_t i = 0; i < C; ++i) + Result[i] = all(equal(a[i], b[i], MaxULPs[i])); + return Result; + } + + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec notEqual(mat const& x, mat const& y, int MaxULPs) + { + return notEqual(x, y, vec(MaxULPs)); + } + + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec notEqual(mat const& a, mat const& b, vec const& MaxULPs) + { + vec Result(true); + for(length_t i = 0; i < C; ++i) + Result[i] = any(notEqual(a[i], b[i], MaxULPs[i])); + return Result; + } + }//namespace glm diff --git a/test/ext/ext_matrix_relational.cpp b/test/ext/ext_matrix_relational.cpp index dfb95435..beadc44a 100644 --- a/test/ext/ext_matrix_relational.cpp +++ b/test/ext/ext_matrix_relational.cpp @@ -23,6 +23,7 @@ #include #include #include +#include template static int test_equal() @@ -58,10 +59,66 @@ static int test_notEqual() return Error; } + +template +static int test_equal_ulps() +{ + typedef glm::mat<4, 4, T, glm::defaultp> mat4; + + T const One(1); + mat4 const Ones(1); + + int Error = 0; + + T const ULP1Plus = glm::next_float(One); + Error += glm::all(glm::equal(Ones, mat4(ULP1Plus), 1)) ? 0 : 1; + + T const ULP2Plus = glm::next_float(ULP1Plus); + Error += !glm::all(glm::equal(Ones, mat4(ULP2Plus), 1)) ? 0 : 1; + + T const ULP1Minus = glm::prev_float(One); + Error += glm::all(glm::equal(Ones, mat4(ULP1Minus), 1)) ? 0 : 1; + + T const ULP2Minus = glm::prev_float(ULP1Minus); + Error += !glm::all(glm::equal(Ones, mat4(ULP2Minus), 1)) ? 0 : 1; + + return Error; +} + +template +static int test_notEqual_ulps() +{ + typedef glm::mat<4, 4, T, glm::defaultp> mat4; + + T const One(1); + mat4 const Ones(1); + + int Error = 0; + + T const ULP1Plus = glm::next_float(One); + Error += !glm::all(glm::notEqual(Ones, mat4(ULP1Plus), 1)) ? 0 : 1; + + T const ULP2Plus = glm::next_float(ULP1Plus); + Error += glm::all(glm::notEqual(Ones, mat4(ULP2Plus), 1)) ? 0 : 1; + + T const ULP1Minus = glm::prev_float(One); + Error += !glm::all(glm::notEqual(Ones, mat4(ULP1Minus), 1)) ? 0 : 1; + + T const ULP2Minus = glm::prev_float(ULP1Minus); + Error += glm::all(glm::notEqual(Ones, mat4(ULP2Minus), 1)) ? 0 : 1; + + return Error; +} + int main() { int Error = 0; + Error += test_equal_ulps(); + Error += test_equal_ulps(); + Error += test_notEqual_ulps(); + Error += test_notEqual_ulps(); + Error += test_equal(); Error += test_equal(); Error += test_equal();