From 05426e7398f28abc3254aef2d50029863ec4464c Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Wed, 2 May 2012 13:06:00 +0100 Subject: [PATCH] Fixed matrixCompMult function for none square matrix --- glm/core/func_matrix.inl | 2 +- test/core/core_func_matrix.cpp | 58 ++++++++++++++++++++++++++++++++-- 2 files changed, 57 insertions(+), 3 deletions(-) diff --git a/glm/core/func_matrix.inl b/glm/core/func_matrix.inl index 78f26cf8..3d8ab4f8 100644 --- a/glm/core/func_matrix.inl +++ b/glm/core/func_matrix.inl @@ -41,7 +41,7 @@ namespace glm GLM_STATIC_ASSERT(detail::type::is_float, "'matrixCompMult' only accept floating-point inputs"); matType result(matType::null); - for(typename matType::size_type i = 0; i < matType::col_size(); ++i) + for(typename matType::size_type i = 0; i < matType::row_size(); ++i) result[i] = x[i] * y[i]; return result; } diff --git a/test/core/core_func_matrix.cpp b/test/core/core_func_matrix.cpp index 047a4956..ad804ab7 100644 --- a/test/core/core_func_matrix.cpp +++ b/test/core/core_func_matrix.cpp @@ -11,9 +11,63 @@ int test_matrixCompMult() { + int Error(0); + + { + glm::mat2 m(0, 1, 2, 3); + glm::mat2 n = glm::matrixCompMult(m, m); + Error += n == glm::mat2(0, 1, 4, 9) ? 0 : 1; + } - - return 0; + { + glm::mat2x3 m(0, 1, 2, 3, 4, 5); + glm::mat2x3 n = glm::matrixCompMult(m, m); + Error += n == glm::mat2x3(0, 1, 4, 9, 16, 25) ? 0 : 1; + } + + { + glm::mat2x4 m(0, 1, 2, 3, 4, 5, 6, 7); + glm::mat2x4 n = glm::matrixCompMult(m, m); + Error += n == glm::mat2x4(0, 1, 4, 9, 16, 25, 36, 49) ? 0 : 1; + } + + { + glm::mat3 m(0, 1, 2, 3, 4, 5, 6, 7, 8); + glm::mat3 n = glm::matrixCompMult(m, m); + Error += n == glm::mat3(0, 1, 4, 9, 16, 25, 36, 49, 64) ? 0 : 1; + } + + { + glm::mat3x2 m(0, 1, 2, 3, 4, 5); + glm::mat3x2 n = glm::matrixCompMult(m, m); + Error += n == glm::mat3x2(0, 1, 4, 9, 16, 25) ? 0 : 1; + } + + { + glm::mat3x4 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11); + glm::mat3x4 n = glm::matrixCompMult(m, m); + Error += n == glm::mat3x4(0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121) ? 0 : 1; + } + + { + glm::mat4 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15); + glm::mat4 n = glm::matrixCompMult(m, m); + Error += n == glm::mat4(0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225) ? 0 : 1; + } + + { + glm::mat4x2 m(0, 1, 2, 3, 4, 5, 6, 7); + glm::mat4x2 n = glm::matrixCompMult(m, m); + Error += n == glm::mat4x2(0, 1, 4, 9, 16, 25, 36, 49) ? 0 : 1; + } + + { + glm::mat4x3 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11); + glm::mat4x3 n = glm::matrixCompMult(m, m); + Error += n == glm::mat4x3(0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121) ? 0 : 1; + } + + return Error; } int test_outerProduct()