From 88102d82db970a6ca878a32aa78812e7ae67fc5d Mon Sep 17 00:00:00 2001 From: Matthias Grob Date: Thu, 21 Dec 2023 16:56:30 +0100 Subject: [PATCH] matrix: return value simplifications --- src/lib/matrix/matrix/Dcm.hpp | 10 ++-------- src/lib/matrix/matrix/Dcm2.hpp | 6 +++--- src/lib/matrix/matrix/Matrix.hpp | 4 ++-- src/lib/matrix/matrix/SquareMatrix.hpp | 4 ++-- src/lib/matrix/matrix/Vector3.hpp | 18 ++---------------- 5 files changed, 11 insertions(+), 31 deletions(-) diff --git a/src/lib/matrix/matrix/Dcm.hpp b/src/lib/matrix/matrix/Dcm.hpp index a96ad85068..e05da5cbf3 100644 --- a/src/lib/matrix/matrix/Dcm.hpp +++ b/src/lib/matrix/matrix/Dcm.hpp @@ -40,8 +40,6 @@ template class Dcm : public SquareMatrix { public: - using Vector3 = Matrix; - /** * Standard constructor * @@ -159,14 +157,10 @@ public: dcm = Quaternion(aa); } - Vector vee() const // inverse to Vector.hat() operation + Vector3 vee() const // inverse to Vector.hat() operation { const Dcm &A(*this); - Vector v; - v(0) = -A(1, 2); - v(1) = A(0, 2); - v(2) = -A(0, 1); - return v; + return {-A(1, 2), A(0, 2), -A(0, 1)}; } void renormalize() diff --git a/src/lib/matrix/matrix/Dcm2.hpp b/src/lib/matrix/matrix/Dcm2.hpp index d1682643ee..e74ea48b3e 100644 --- a/src/lib/matrix/matrix/Dcm2.hpp +++ b/src/lib/matrix/matrix/Dcm2.hpp @@ -114,10 +114,10 @@ public: void renormalize() { - /* renormalize rows */ + // renormalize rows for (size_t r = 0; r < 2; r++) { - matrix::Vector2 rvec(Matrix(this->Matrix::row(r)).transpose()); - this->Matrix::row(r) = rvec.normalized(); + Vector2 rvec(Matrix(this->row(r)).transpose()); + this->row(r) = rvec.normalized(); } } }; diff --git a/src/lib/matrix/matrix/Matrix.hpp b/src/lib/matrix/matrix/Matrix.hpp index b56c96c379..d3b97765d6 100644 --- a/src/lib/matrix/matrix/Matrix.hpp +++ b/src/lib/matrix/matrix/Matrix.hpp @@ -440,13 +440,13 @@ public: template const Slice slice(size_t x0, size_t y0) const { - return Slice(x0, y0, this); + return {x0, y0, this}; } template Slice slice(size_t x0, size_t y0) { - return Slice(x0, y0, this); + return {x0, y0, this}; } const Slice row(size_t i) const diff --git a/src/lib/matrix/matrix/SquareMatrix.hpp b/src/lib/matrix/matrix/SquareMatrix.hpp index e2e2084ae3..07ccd8cd67 100644 --- a/src/lib/matrix/matrix/SquareMatrix.hpp +++ b/src/lib/matrix/matrix/SquareMatrix.hpp @@ -57,13 +57,13 @@ public: template const Slice slice(size_t x0, size_t y0) const { - return Slice(x0, y0, this); + return {x0, y0, this}; } template Slice slice(size_t x0, size_t y0) { - return Slice(x0, y0, this); + return {x0, y0, this}; } // inverse alias diff --git a/src/lib/matrix/matrix/Vector3.hpp b/src/lib/matrix/matrix/Vector3.hpp index b7247145c9..c901219bef 100644 --- a/src/lib/matrix/matrix/Vector3.hpp +++ b/src/lib/matrix/matrix/Vector3.hpp @@ -103,30 +103,16 @@ public: return (*this).cross(b); } - /** - * Override vector ops so Vector3 type is returned - */ - inline Vector3 unit() const - { - return Vector3(Vector::unit()); - } - - inline Vector3 normalized() const - { - return unit(); - } - const Slice xy() const { - return Slice(0, 0, this); + return {0, 0, this}; } Slice xy() { - return Slice(0, 0, this); + return {0, 0, this}; } - Dcm hat() const // inverse to Dcm.vee() operation { const Vector3 &v(*this);