From 8957b217190f1eb0c05d6e15ebeb8367cd869e57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 23 Dec 2010 23:04:21 +0100 Subject: [PATCH] Fixed Matrix multiplication & test, documentation updates. --- src/Matrix.h | 14 +++++++------- src/Test/MatrixTest.cpp | 43 +++++++++++++++++++++-------------------- 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/src/Matrix.h b/src/Matrix.h index 8faf51195..00285762f 100644 --- a/src/Matrix.h +++ b/src/Matrix.h @@ -39,7 +39,7 @@ template class Matrix { /** * @brief Constructor - * @param data One-dimensional array of size*size length in column-major order. + * @param data One-dimensional array of @c size*size length in column-major order. */ inline Matrix(const T* data) { setData(data); } @@ -56,13 +56,13 @@ template class Matrix { /** * @brief Raw data - * @return One-dimensional array of size*size length in column-major order. + * @return One-dimensional array of @c size*size length in column-major order. */ inline const T* data() const { return _data; } /** * @brief Set raw data - * @param data One-dimensional array of size*size length in column-major order. + * @param data One-dimensional array of @c size*size length in column-major order. */ inline void setData(const T* data) { memcpy(_data, data, size*size*sizeof(T)); @@ -93,14 +93,14 @@ template class Matrix { return !operator==(other); } - /** @brief Multiply operator */ + /** @brief Multiply matrix operator */ Matrix operator*(const Matrix& other) const { Matrix out(false); - for(size_t col = 0; col != size; ++col) { - for(size_t row = 0; row != size; ++row) { + for(size_t row = 0; row != size; ++row) { + for(size_t col = 0; col != size; ++col) { for(size_t pos = 0; pos != size; ++pos) - out.add(col, row, at(col, pos)*other.at(pos, row)); + out.add(col, row, at(pos, row)*other.at(col, pos)); } } diff --git a/src/Test/MatrixTest.cpp b/src/Test/MatrixTest.cpp index 25acbba7c..f19c3e303 100644 --- a/src/Test/MatrixTest.cpp +++ b/src/Test/MatrixTest.cpp @@ -79,7 +79,7 @@ void MatrixTest::copy() { /* Copy */ Matrix4 m2(m1); Matrix4 m3; - m3.set(0, 0, 1.0f); + m3.set(0, 0, 1.0f); /* this line is here so it's not optimized to Matrix4 m3(m1) */ m3 = m1; /* Change original */ @@ -89,7 +89,8 @@ void MatrixTest::copy() { Matrix4 original(false); original.set(2, 3, 1.0f); - QVERIFY(m2 == original && m3 == original); + QVERIFY(m2 == original); + QVERIFY(m3 == original); } void MatrixTest::multiplyIdentity() { @@ -105,31 +106,31 @@ void MatrixTest::multiplyIdentity() { } void MatrixTest::multiply() { - float left[] = { - -3, -1, -1, -5, 1, - -3, -3, -4, -5, 3, - -1, -5, 3, -1, -3, - 3, 2, -1, -4, -4, - -5, 3, -2, -1, -1 + int left[] = { + -3, -3, -1, 3, -5, + -1, -3, -5, 2, 3, + -1, -4, 3, -1, -2, + -5, -5, -1, -4, -1, + 1, 3, -3, -4, -1 }; - float right[] = { - 0, 5, 3, -3, 0, - 5, 5, 2, 0, -1, - 3, 0, -4, -1, -4, - 4, 0, -3, 2, 4, - 4, -2, 0, -1, 3 + int right[] = { + 0, 5, 3, 4, 4, + 5, 5, 0, 0, -2, + 3, 2, -4, -3, 0, + -3, 0, -1, 2, -1, + 0, -1, -4, 4, 3 }; - float expected[] = { - -24, -22, 8, -1, -12, - -35, -36, 16, 0, 8, - -32, -24, -22, 1, -20, - -25, 33, 29, -12, -26, - 1, -8, 2, 16, -2 + int expected[] = { + -24, -35, -32, -25, 1, + -22, -36, -24, 33, -8, + 8, 16, -22, 29, 2, + -1, 0, 1, -12, 16, + -12, 8, -20, -26, -2 }; - bool is = Matrix(left)*Matrix(right) == Matrix(expected); + bool is = (Matrix(left)*Matrix(right) == Matrix(expected)); QVERIFY(is); }