mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-05-18 07:47:35 +08:00
use default constructors and skip unnecessary initialization
This commit is contained in:
+6
-14
@@ -46,10 +46,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Standard constructor
|
* Standard constructor
|
||||||
*/
|
*/
|
||||||
AxisAngle() :
|
AxisAngle() = default;
|
||||||
Vector<Type, 3>()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor from Matrix31
|
* Constructor from Matrix31
|
||||||
@@ -70,8 +67,7 @@ public:
|
|||||||
*
|
*
|
||||||
* @param q quaternion
|
* @param q quaternion
|
||||||
*/
|
*/
|
||||||
AxisAngle(const Quaternion<Type> &q) :
|
AxisAngle(const Quaternion<Type> &q)
|
||||||
Vector<Type, 3>()
|
|
||||||
{
|
{
|
||||||
AxisAngle &v = *this;
|
AxisAngle &v = *this;
|
||||||
Type ang = Type(2.0f)*acos(q(0));
|
Type ang = Type(2.0f)*acos(q(0));
|
||||||
@@ -95,8 +91,7 @@ public:
|
|||||||
*
|
*
|
||||||
* @param dcm dcm to set quaternion to
|
* @param dcm dcm to set quaternion to
|
||||||
*/
|
*/
|
||||||
AxisAngle(const Dcm<Type> &dcm) :
|
AxisAngle(const Dcm<Type> &dcm)
|
||||||
Vector<Type, 3>()
|
|
||||||
{
|
{
|
||||||
AxisAngle &v = *this;
|
AxisAngle &v = *this;
|
||||||
v = Quaternion<Type>(dcm);
|
v = Quaternion<Type>(dcm);
|
||||||
@@ -111,8 +106,7 @@ public:
|
|||||||
*
|
*
|
||||||
* @param euler euler angle instance
|
* @param euler euler angle instance
|
||||||
*/
|
*/
|
||||||
AxisAngle(const Euler<Type> &euler) :
|
AxisAngle(const Euler<Type> &euler)
|
||||||
Vector<Type, 3>()
|
|
||||||
{
|
{
|
||||||
AxisAngle &v = *this;
|
AxisAngle &v = *this;
|
||||||
v = Quaternion<Type>(euler);
|
v = Quaternion<Type>(euler);
|
||||||
@@ -125,8 +119,7 @@ public:
|
|||||||
* @param y r_y*angle
|
* @param y r_y*angle
|
||||||
* @param z r_z*angle
|
* @param z r_z*angle
|
||||||
*/
|
*/
|
||||||
AxisAngle(Type x, Type y, Type z) :
|
AxisAngle(Type x, Type y, Type z)
|
||||||
Vector<Type, 3>()
|
|
||||||
{
|
{
|
||||||
AxisAngle &v = *this;
|
AxisAngle &v = *this;
|
||||||
v(0) = x;
|
v(0) = x;
|
||||||
@@ -140,8 +133,7 @@ public:
|
|||||||
* @param axis An axis of rotation, normalized if not unit length
|
* @param axis An axis of rotation, normalized if not unit length
|
||||||
* @param angle The amount to rotate
|
* @param angle The amount to rotate
|
||||||
*/
|
*/
|
||||||
AxisAngle(const Matrix31 & axis_, Type angle_) :
|
AxisAngle(const Matrix31 & axis_, Type angle_)
|
||||||
Vector<Type, 3>()
|
|
||||||
{
|
{
|
||||||
AxisAngle &v = *this;
|
AxisAngle &v = *this;
|
||||||
// make sure axis is a unit vector
|
// make sure axis is a unit vector
|
||||||
|
|||||||
+1
-1
@@ -46,7 +46,7 @@ public:
|
|||||||
*
|
*
|
||||||
* Initializes to identity
|
* Initializes to identity
|
||||||
*/
|
*/
|
||||||
Dcm() : SquareMatrix<Type, 3>()
|
Dcm()
|
||||||
{
|
{
|
||||||
(*this) = eye<Type, 3>();
|
(*this) = eye<Type, 3>();
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-6
@@ -43,9 +43,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Standard constructor
|
* Standard constructor
|
||||||
*/
|
*/
|
||||||
Euler() : Vector<Type, 3>()
|
Euler() = default;
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copy constructor
|
* Copy constructor
|
||||||
@@ -95,7 +93,7 @@ public:
|
|||||||
*
|
*
|
||||||
* @param dcm Direction cosine matrix
|
* @param dcm Direction cosine matrix
|
||||||
*/
|
*/
|
||||||
Euler(const Dcm<Type> &dcm) : Vector<Type, 3>()
|
Euler(const Dcm<Type> &dcm)
|
||||||
{
|
{
|
||||||
Type phi_val = Type(atan2(dcm(2, 1), dcm(2, 2)));
|
Type phi_val = Type(atan2(dcm(2, 1), dcm(2, 2)));
|
||||||
Type theta_val = Type(asin(-dcm(2, 0)));
|
Type theta_val = Type(asin(-dcm(2, 0)));
|
||||||
@@ -126,8 +124,7 @@ public:
|
|||||||
*
|
*
|
||||||
* @param q quaternion
|
* @param q quaternion
|
||||||
*/
|
*/
|
||||||
Euler(const Quaternion<Type> &q) :
|
Euler(const Quaternion<Type> &q)
|
||||||
Vector<Type, 3>()
|
|
||||||
{
|
{
|
||||||
*this = Euler(Dcm<Type>(q));
|
*this = Euler(Dcm<Type>(q));
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-5
@@ -30,22 +30,22 @@ class Matrix
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Type _data[M][N];
|
Type _data[M][N] {};
|
||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
Matrix() : _data() {}
|
Matrix() = default;
|
||||||
|
|
||||||
Matrix(const Type data_[][N]) : _data()
|
Matrix(const Type data_[][N])
|
||||||
{
|
{
|
||||||
memcpy(_data, data_, sizeof(_data));
|
memcpy(_data, data_, sizeof(_data));
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix(const Type *data_) : _data()
|
Matrix(const Type *data_)
|
||||||
{
|
{
|
||||||
memcpy(_data, data_, sizeof(_data));
|
memcpy(_data, data_, sizeof(_data));
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix(const Matrix &other) : _data()
|
Matrix(const Matrix &other)
|
||||||
{
|
{
|
||||||
memcpy(_data, other._data, sizeof(_data));
|
memcpy(_data, other._data, sizeof(_data));
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-12
@@ -70,8 +70,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Standard constructor
|
* Standard constructor
|
||||||
*/
|
*/
|
||||||
Quaternion() :
|
Quaternion()
|
||||||
Vector<Type, 4>()
|
|
||||||
{
|
{
|
||||||
Quaternion &q = *this;
|
Quaternion &q = *this;
|
||||||
q(0) = 1;
|
q(0) = 1;
|
||||||
@@ -98,8 +97,7 @@ public:
|
|||||||
*
|
*
|
||||||
* @param dcm dcm to set quaternion to
|
* @param dcm dcm to set quaternion to
|
||||||
*/
|
*/
|
||||||
Quaternion(const Dcm<Type> &R) :
|
Quaternion(const Dcm<Type> &R)
|
||||||
Vector<Type, 4>()
|
|
||||||
{
|
{
|
||||||
Quaternion &q = *this;
|
Quaternion &q = *this;
|
||||||
Type t = R.trace();
|
Type t = R.trace();
|
||||||
@@ -143,8 +141,7 @@ public:
|
|||||||
*
|
*
|
||||||
* @param euler euler angle instance
|
* @param euler euler angle instance
|
||||||
*/
|
*/
|
||||||
Quaternion(const Euler<Type> &euler) :
|
Quaternion(const Euler<Type> &euler)
|
||||||
Vector<Type, 4>()
|
|
||||||
{
|
{
|
||||||
Quaternion &q = *this;
|
Quaternion &q = *this;
|
||||||
Type cosPhi_2 = Type(cos(euler.phi() / Type(2.0)));
|
Type cosPhi_2 = Type(cos(euler.phi() / Type(2.0)));
|
||||||
@@ -168,8 +165,7 @@ public:
|
|||||||
*
|
*
|
||||||
* @param aa axis-angle vector
|
* @param aa axis-angle vector
|
||||||
*/
|
*/
|
||||||
Quaternion(const AxisAngle<Type> &aa) :
|
Quaternion(const AxisAngle<Type> &aa)
|
||||||
Vector<Type, 4>()
|
|
||||||
{
|
{
|
||||||
Quaternion &q = *this;
|
Quaternion &q = *this;
|
||||||
Type angle = aa.norm();
|
Type angle = aa.norm();
|
||||||
@@ -194,8 +190,7 @@ public:
|
|||||||
* @param src source vector (no need to normalize)
|
* @param src source vector (no need to normalize)
|
||||||
* @param eps epsilon threshold which decides if a value is considered zero
|
* @param eps epsilon threshold which decides if a value is considered zero
|
||||||
*/
|
*/
|
||||||
Quaternion(const Vector3<Type> &src, const Vector3<Type> &dst, const Type eps = Type(1e-5)) :
|
Quaternion(const Vector3<Type> &src, const Vector3<Type> &dst, const Type eps = Type(1e-5))
|
||||||
Vector<Type, 4>()
|
|
||||||
{
|
{
|
||||||
Quaternion &q = *this;
|
Quaternion &q = *this;
|
||||||
Vector3<Type> cr = src.cross(dst);
|
Vector3<Type> cr = src.cross(dst);
|
||||||
@@ -242,8 +237,7 @@ public:
|
|||||||
* @param c set quaternion value 2
|
* @param c set quaternion value 2
|
||||||
* @param d set quaternion value 3
|
* @param d set quaternion value 3
|
||||||
*/
|
*/
|
||||||
Quaternion(Type a, Type b, Type c, Type d) :
|
Quaternion(Type a, Type b, Type c, Type d)
|
||||||
Vector<Type, 4>()
|
|
||||||
{
|
{
|
||||||
Quaternion &q = *this;
|
Quaternion &q = *this;
|
||||||
q(0) = a;
|
q(0) = a;
|
||||||
|
|||||||
+7
-10
@@ -17,21 +17,18 @@ template<typename Type>
|
|||||||
class Scalar
|
class Scalar
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Scalar() : _value()
|
Scalar() = delete;
|
||||||
|
|
||||||
|
Scalar(const Matrix<Type, 1, 1> & other) :
|
||||||
|
_value{other(0,0)}
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Scalar(const Matrix<Type, 1, 1> & other)
|
Scalar(Type other) : _value(other)
|
||||||
{
|
{
|
||||||
_value = other(0,0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Scalar(Type other)
|
operator const Type &()
|
||||||
{
|
|
||||||
_value = other;
|
|
||||||
}
|
|
||||||
|
|
||||||
operator Type &()
|
|
||||||
{
|
{
|
||||||
return _value;
|
return _value;
|
||||||
}
|
}
|
||||||
@@ -49,7 +46,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Type _value;
|
const Type _value;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -24,10 +24,7 @@ template<typename Type, size_t M>
|
|||||||
class SquareMatrix : public Matrix<Type, M, M>
|
class SquareMatrix : public Matrix<Type, M, M>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SquareMatrix() :
|
SquareMatrix() = default;
|
||||||
Matrix<Type, M, M>()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
SquareMatrix(const Type *data_) :
|
SquareMatrix(const Type *data_) :
|
||||||
Matrix<Type, M, M>(data_)
|
Matrix<Type, M, M>(data_)
|
||||||
|
|||||||
+1
-3
@@ -22,9 +22,7 @@ class Vector : public Matrix<Type, M, 1>
|
|||||||
public:
|
public:
|
||||||
typedef Matrix<Type, M, 1> MatrixM1;
|
typedef Matrix<Type, M, 1> MatrixM1;
|
||||||
|
|
||||||
Vector() : MatrixM1()
|
Vector() = default;
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector(const MatrixM1 & other) :
|
Vector(const MatrixM1 & other) :
|
||||||
MatrixM1(other)
|
MatrixM1(other)
|
||||||
|
|||||||
+3
-6
@@ -23,10 +23,7 @@ public:
|
|||||||
|
|
||||||
typedef Matrix<Type, 2, 1> Matrix21;
|
typedef Matrix<Type, 2, 1> Matrix21;
|
||||||
|
|
||||||
Vector2() :
|
Vector2() = default;
|
||||||
Vector<Type, 2>()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector2(const Matrix21 & other) :
|
Vector2(const Matrix21 & other) :
|
||||||
Vector<Type, 2>(other)
|
Vector<Type, 2>(other)
|
||||||
@@ -38,14 +35,14 @@ public:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2(Type x, Type y) : Vector<Type, 2>()
|
Vector2(Type x, Type y)
|
||||||
{
|
{
|
||||||
Vector2 &v(*this);
|
Vector2 &v(*this);
|
||||||
v(0) = x;
|
v(0) = x;
|
||||||
v(1) = y;
|
v(1) = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
Type cross(const Matrix21 & b) const {
|
Type cross(const Matrix21 & b) const {
|
||||||
const Vector2 &a(*this);
|
const Vector2 &a(*this);
|
||||||
return a(0)*b(1, 0) - a(1)*b(0, 0);
|
return a(0)*b(1, 0) - a(1)*b(0, 0);
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-7
@@ -29,10 +29,7 @@ public:
|
|||||||
|
|
||||||
typedef Matrix<Type, 3, 1> Matrix31;
|
typedef Matrix<Type, 3, 1> Matrix31;
|
||||||
|
|
||||||
Vector3() :
|
Vector3() = default;
|
||||||
Vector<Type, 3>()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector3(const Matrix31 & other) :
|
Vector3(const Matrix31 & other) :
|
||||||
Vector<Type, 3>(other)
|
Vector<Type, 3>(other)
|
||||||
@@ -44,15 +41,14 @@ public:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3(Type x, Type y, Type z) : Vector<Type, 3>()
|
Vector3(Type x, Type y, Type z) {
|
||||||
{
|
|
||||||
Vector3 &v(*this);
|
Vector3 &v(*this);
|
||||||
v(0) = x;
|
v(0) = x;
|
||||||
v(1) = y;
|
v(1) = y;
|
||||||
v(2) = z;
|
v(2) = z;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 cross(const Matrix31 & b) const {
|
Vector3 cross(const Matrix31 & b) const {
|
||||||
const Vector3 &a(*this);
|
const Vector3 &a(*this);
|
||||||
Vector3 c;
|
Vector3 c;
|
||||||
c(0) = a(1)*b(2,0) - a(2)*b(1,0);
|
c(0) = a(1)*b(2,0) - a(2)*b(1,0);
|
||||||
|
|||||||
@@ -97,8 +97,7 @@ int main()
|
|||||||
TEST(fabs(m4.min() - 1) < 1e-5);
|
TEST(fabs(m4.min() - 1) < 1e-5);
|
||||||
TEST(fabs((-m4).min() + 9) < 1e-5);
|
TEST(fabs((-m4).min() + 9) < 1e-5);
|
||||||
|
|
||||||
Scalar<float> s;
|
Scalar<float> s = 1;
|
||||||
s = 1;
|
|
||||||
const Vector<float, 1> & s_vect = s;
|
const Vector<float, 1> & s_vect = s;
|
||||||
TEST(fabs(s - 1) < 1e-5);
|
TEST(fabs(s - 1) < 1e-5);
|
||||||
TEST(fabs(s_vect(0) - 1.0f) < 1e-5);
|
TEST(fabs(s_vect(0) - 1.0f) < 1e-5);
|
||||||
|
|||||||
Reference in New Issue
Block a user