Skip to content

Commit

Permalink
[math] fix matrix vector multiplication & add unittest
Browse files Browse the repository at this point in the history
  • Loading branch information
se-bi committed Mar 26, 2019
1 parent 502c162 commit 5dd598c
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/modm/math/geometry/vector3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ namespace modm
template<typename T, typename U>
static inline Vector<U, 3> operator * (const Matrix<T, 3, 3> &lhs, const Vector<U, 3> &rhs)
{
return lhs * rhs.asTMatrix();
return lhs * rhs.asMatrix();
}


Expand Down
51 changes: 51 additions & 0 deletions test/modm/math/matrix_vector_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (c) 2011, Fabian Greif
* Copyright (c) 2012, Niklas Hauser
* Copyright (c) 2017, Marten
* Copyright (c) 2019, Markus Schmidt
* Copyright (c) 2019, Sebastan Birke
*
* This file is part of the modm project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
// ----------------------------------------------------------------------------

#include <modm/math/matrix.hpp>
#include <modm/math/geometry/vector.hpp>

#include "matrix_vector_test.hpp"

void
MatrixVectorTest::testMatrixVectorMultiplication()
{
const float_t m[] = {
5.,
8.,
-4.,
6.,
9.,
-5.,
4.,
7.,
-2.
};

const float_t v[] = {
2.,
-3.,
1.
};

const modm::Matrix<float_t, 3, 3> a(m);
const modm::Vector3f b(v);

modm::Vector3f c = a * b;

TEST_ASSERT_EQUALS(c[0], -18);
TEST_ASSERT_EQUALS(c[1], -20);
TEST_ASSERT_EQUALS(c[2], -15);

}
23 changes: 23 additions & 0 deletions test/modm/math/matrix_vector_test.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (c) 2009, Martin Rosekeit
* Copyright (c) 2009-2011, Fabian Greif
* Copyright (c) 2012, Niklas Hauser
* Copyright (c) 2019, Markus Schmidt
* Copyright (c) 2019, Sebastan Birke
*
* This file is part of the modm project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
// ----------------------------------------------------------------------------

#include <unittest/testsuite.hpp>

class MatrixVectorTest : public unittest::TestSuite
{
public:
void
testMatrixVectorMultiplication();
};

0 comments on commit 5dd598c

Please sign in to comment.