Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[math] fix matrix vector multiplication & add unittest #187

Merged
merged 1 commit into from
Mar 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
};