From cf6bf16d6220edc123b71e76af7444c57198de12 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Tue, 7 Aug 2018 01:22:19 +0200 Subject: [PATCH] Make matrix relational constexpr --- glm/ext/matrix_relational.hpp | 12 +++--- glm/ext/matrix_relational.inl | 74 +++++++++++++++++++++++++++++------ 2 files changed, 69 insertions(+), 17 deletions(-) diff --git a/glm/ext/matrix_relational.hpp b/glm/ext/matrix_relational.hpp index c9976f71..426422f3 100644 --- a/glm/ext/matrix_relational.hpp +++ b/glm/ext/matrix_relational.hpp @@ -35,7 +35,7 @@ namespace glm /// /// @see ext_matrix_relational template - GLM_FUNC_DECL vec equal(mat const& x, mat const& y); + 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. @@ -47,7 +47,7 @@ namespace glm /// /// @see ext_matrix_relational template - GLM_FUNC_DECL vec equal(mat const& x, mat const& y, T epsilon); + GLM_FUNC_DECL GLM_CONSTEXPR 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. @@ -59,7 +59,7 @@ namespace glm /// /// @see ext_matrix_relational template - GLM_FUNC_DECL vec equal(mat const& x, mat const& y, vec const& epsilon); + GLM_FUNC_DECL GLM_CONSTEXPR vec equal(mat const& x, mat const& y, vec const& 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. @@ -71,7 +71,7 @@ namespace glm /// /// @see ext_matrix_relational template - GLM_FUNC_DECL vec notEqual(mat const& x, mat const& y); + 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 not satisfied. @@ -83,7 +83,7 @@ namespace glm /// /// @see ext_matrix_relational template - GLM_FUNC_DECL vec notEqual(mat const& x, mat const& y, T epsilon); + GLM_FUNC_DECL GLM_CONSTEXPR vec notEqual(mat const& x, mat const& y, T epsilon); /// Returns the component-wise comparison of |x - y| >= epsilon. /// True if this expression is not satisfied. @@ -95,7 +95,7 @@ namespace glm /// /// @see ext_vector_relational template - GLM_FUNC_DECL vec notEqual(mat const& x, mat const& y, vec const& epsilon); + GLM_FUNC_DECL GLM_CONSTEXPR vec notEqual(mat const& x, mat const& y, vec const& epsilon); /// @} }//namespace glm diff --git a/glm/ext/matrix_relational.inl b/glm/ext/matrix_relational.inl index efc2d6c5..ca3383e2 100644 --- a/glm/ext/matrix_relational.inl +++ b/glm/ext/matrix_relational.inl @@ -5,47 +5,99 @@ #include "../ext/vector_relational.hpp" #include "../common.hpp" -namespace glm +namespace glm{ +namespace detail { + enum matrix_relational_type + { + MAT_EQUAL, + MAT_NOT_EQUAL + }; + + template + struct matrix_relational + { + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR static bool call(vecType const& Src0, vecType const& Src1, T Epsilon); + }; + + template <> + struct matrix_relational + { + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR static bool call(vecType const& Src0, vecType const& Src1, T Epsilon) + { + return all(equal(Src0, Src1, Epsilon)); + } + }; + + template <> + struct matrix_relational + { + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR static bool call(vecType const& Src0, vecType const& Src1, T Epsilon) + { + return any(notEqual(Src0, Src1, Epsilon)); + } + }; + + template + struct loop_matrix_relational + { + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR static void call(vecBType& Dst, matType const& Src0, matType const& Src1, vecType const& Epsilon) + { + Dst[I] = matrix_relational::call(Src0[I], Src1[I], Epsilon[I]); + loop_matrix_relational::call(Dst, Src0, Src1, Epsilon); + } + }; + + template + struct loop_matrix_relational + { + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR static void call(vecBType&, matType const&, matType const&, vecType const&) + {} + }; +}//namespace detail + template - GLM_FUNC_QUALIFIER vec equal(mat const& a, mat const& b) + GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec equal(mat const& a, mat const& b) { return equal(a, b, static_cast(0)); } template - GLM_FUNC_QUALIFIER vec equal(mat const& a, mat const& b, T epsilon) + GLM_FUNC_QUALIFIER GLM_CONSTEXPR 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) + GLM_FUNC_QUALIFIER GLM_CONSTEXPR 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])); + detail::loop_matrix_relational<0, C, detail::EQUAL>::call(Result, a, b, epsilon); return Result; } template - GLM_FUNC_QUALIFIER vec notEqual(mat const& x, mat const& y) + GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec notEqual(mat const& x, mat const& y) { return notEqual(x, y, static_cast(0)); } template - GLM_FUNC_QUALIFIER vec notEqual(mat const& x, mat const& y, T epsilon) + GLM_FUNC_QUALIFIER GLM_CONSTEXPR 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) + GLM_FUNC_QUALIFIER GLM_CONSTEXPR 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])); + detail::loop_matrix_relational<0, C, detail::NOT_EQUAL>::call(Result, a, b, epsilon); return Result; } }//namespace glm