Fixed matrixCompMult function for none square matrix

This commit is contained in:
Christophe Riccio 2012-05-02 13:06:00 +01:00
parent 6920963069
commit 34dc3a6ef6
2 changed files with 57 additions and 3 deletions

View File

@ -41,7 +41,7 @@ namespace glm
GLM_STATIC_ASSERT(detail::type<typename matType::value_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;
}

View File

@ -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()