diff options
author | Thomas Gubler <thomasgubler@gmail.com> | 2015-01-05 10:25:39 +0100 |
---|---|---|
committer | Thomas Gubler <thomasgubler@gmail.com> | 2015-01-05 10:25:39 +0100 |
commit | ef485177acb123483fe42d49b3ab23671ee3aa31 (patch) | |
tree | 85b6e9ee59c96f99d3bc1eba0c8b93e2ada75996 /src/lib/mathlib/math/Matrix.hpp | |
parent | 16b9f666e790a2b939f7890b39cc6e4cf2552165 (diff) | |
download | px4-firmware-ef485177acb123483fe42d49b3ab23671ee3aa31.tar.gz px4-firmware-ef485177acb123483fe42d49b3ab23671ee3aa31.tar.bz2 px4-firmware-ef485177acb123483fe42d49b3ab23671ee3aa31.zip |
make Matrix.hpp more consistent with upstream
Diffstat (limited to 'src/lib/mathlib/math/Matrix.hpp')
-rw-r--r-- | src/lib/mathlib/math/Matrix.hpp | 29 |
1 files changed, 8 insertions, 21 deletions
diff --git a/src/lib/mathlib/math/Matrix.hpp b/src/lib/mathlib/math/Matrix.hpp index fc57d7964..43ba6b9d9 100644 --- a/src/lib/mathlib/math/Matrix.hpp +++ b/src/lib/mathlib/math/Matrix.hpp @@ -178,9 +178,8 @@ public: bool operator !=(const Matrix<M, N> &m) const { for (unsigned int i = 0; i < M; i++) for (unsigned int j = 0; j < N; j++) - if (data[i][j] != m.data[i][j]) { + if (data[i][j] != m.data[i][j]) return true; - } return false; } @@ -202,7 +201,6 @@ public: for (unsigned int i = 0; i < M; i++) for (unsigned int j = 0; j < N; j++) res.data[i][j] = -data[i][j]; - } return res; } @@ -216,7 +214,6 @@ public: for (unsigned int i = 0; i < M; i++) for (unsigned int j = 0; j < N; j++) res.data[i][j] = data[i][j] + m.data[i][j]; - } return res; } @@ -225,7 +222,6 @@ public: for (unsigned int i = 0; i < M; i++) for (unsigned int j = 0; j < N; j++) data[i][j] += m.data[i][j]; - } return *static_cast<Matrix<M, N>*>(this); } @@ -237,9 +233,8 @@ public: Matrix<M, N> res; for (unsigned int i = 0; i < M; i++) - for (unsigned int j = 0; j < N; j++) { + for (unsigned int j = 0; j < N; j++) res.data[i][j] = data[i][j] - m.data[i][j]; - } return res; } @@ -248,7 +243,6 @@ public: for (unsigned int i = 0; i < M; i++) for (unsigned int j = 0; j < N; j++) data[i][j] -= m.data[i][j]; - } return *static_cast<Matrix<M, N>*>(this); } @@ -260,19 +254,16 @@ public: Matrix<M, N> res; for (unsigned int i = 0; i < M; i++) - for (unsigned int j = 0; j < N; j++) { + for (unsigned int j = 0; j < N; j++) res.data[i][j] = data[i][j] * num; - } return res; - } Matrix<M, N> &operator *=(const float num) { for (unsigned int i = 0; i < M; i++) - for (unsigned int j = 0; j < N; j++) { + for (unsigned int j = 0; j < N; j++) data[i][j] *= num; - } return *static_cast<Matrix<M, N>*>(this); } @@ -281,18 +272,16 @@ public: Matrix<M, N> res; for (unsigned int i = 0; i < M; i++) - for (unsigned int j = 0; j < N; j++) { + for (unsigned int j = 0; j < N; j++) res[i][j] = data[i][j] / num; - } return res; } Matrix<M, N> &operator /=(const float num) { for (unsigned int i = 0; i < M; i++) - for (unsigned int j = 0; j < N; j++) { + for (unsigned int j = 0; j < N; j++) data[i][j] /= num; - } return *static_cast<Matrix<M, N>*>(this); } @@ -365,18 +354,16 @@ public: memset(data, 0, sizeof(data)); unsigned int n = (M < N) ? M : N; - for (unsigned int i = 0; i < n; i++) { + for (unsigned int i = 0; i < n; i++) data[i][i] = 1; - } } void print(void) { for (unsigned int i = 0; i < M; i++) { printf("[ "); - for (unsigned int j = 0; j < N; j++) { + for (unsigned int j = 0; j < N; j++) printf("%.3f\t", data[i][j]); - } printf(" ]\n"); } |