matrix: return value simplifications

This commit is contained in:
Matthias Grob 2023-12-21 16:56:30 +01:00 committed by Daniel Agar
parent 44a8c553fb
commit 88102d82db
5 changed files with 11 additions and 31 deletions

View File

@ -40,8 +40,6 @@ template<typename Type>
class Dcm : public SquareMatrix<Type, 3>
{
public:
using Vector3 = Matrix<Type, 3, 1>;
/**
* Standard constructor
*
@ -159,14 +157,10 @@ public:
dcm = Quaternion<Type>(aa);
}
Vector<Type, 3> vee() const // inverse to Vector.hat() operation
Vector3<Type> vee() const // inverse to Vector.hat() operation
{
const Dcm &A(*this);
Vector<Type, 3> 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()

View File

@ -114,10 +114,10 @@ public:
void renormalize()
{
/* renormalize rows */
// renormalize rows
for (size_t r = 0; r < 2; r++) {
matrix::Vector2<Type> rvec(Matrix<Type, 1, 2>(this->Matrix<Type, 2, 2>::row(r)).transpose());
this->Matrix<Type, 2, 2>::row(r) = rvec.normalized();
Vector2<Type> rvec(Matrix<Type, 1, 2>(this->row(r)).transpose());
this->row(r) = rvec.normalized();
}
}
};

View File

@ -440,13 +440,13 @@ public:
template<size_t P, size_t Q>
const Slice<Type, P, Q, M, N> slice(size_t x0, size_t y0) const
{
return Slice<Type, P, Q, M, N>(x0, y0, this);
return {x0, y0, this};
}
template<size_t P, size_t Q>
Slice<Type, P, Q, M, N> slice(size_t x0, size_t y0)
{
return Slice<Type, P, Q, M, N>(x0, y0, this);
return {x0, y0, this};
}
const Slice<Type, 1, N, M, N> row(size_t i) const

View File

@ -57,13 +57,13 @@ public:
template<size_t P, size_t Q>
const Slice<Type, P, Q, M, M> slice(size_t x0, size_t y0) const
{
return Slice<Type, P, Q, M, M>(x0, y0, this);
return {x0, y0, this};
}
template<size_t P, size_t Q>
Slice<Type, P, Q, M, M> slice(size_t x0, size_t y0)
{
return Slice<Type, P, Q, M, M>(x0, y0, this);
return {x0, y0, this};
}
// inverse alias

View File

@ -103,30 +103,16 @@ public:
return (*this).cross(b);
}
/**
* Override vector ops so Vector3 type is returned
*/
inline Vector3 unit() const
{
return Vector3(Vector<Type, 3>::unit());
}
inline Vector3 normalized() const
{
return unit();
}
const Slice<Type, 2, 1, 3, 1> xy() const
{
return Slice<Type, 2, 1, 3, 1>(0, 0, this);
return {0, 0, this};
}
Slice<Type, 2, 1, 3, 1> xy()
{
return Slice<Type, 2, 1, 3, 1>(0, 0, this);
return {0, 0, this};
}
Dcm<Type> hat() const // inverse to Dcm.vee() operation
{
const Vector3 &v(*this);