diff --git a/CMakeLists.txt b/CMakeLists.txt index f20bf3939bc..3788e92bbbc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,9 +20,24 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -Wall - -Weffc++ - -Werror + -Wno-sign-compare + -Wextra + -Wshadow + -Wfloat-equal + -Wpointer-arith + -Wmissing-declarations + -Wno-unused-parameter + -Werror=format-security + -Werror=array-bounds -Wfatal-errors + -Werror=unused-variable + -Werror=reorder + -Werror=uninitialized + -Werror=init-self + -Wcast-qual + -Wconversion + -Wcast-align + -Werror ) if (COVERALLS) diff --git a/matrix/Dcm.hpp b/matrix/Dcm.hpp index cbee44f8102..89d08f0dd3c 100644 --- a/matrix/Dcm.hpp +++ b/matrix/Dcm.hpp @@ -31,7 +31,7 @@ public: Matrix::setIdentity(); } - Dcm(const Type *data) : Matrix(data) + Dcm(const Type *data_) : Matrix(data_) { } diff --git a/matrix/Euler.hpp b/matrix/Euler.hpp index 2924994f068..a309f1f3c90 100644 --- a/matrix/Euler.hpp +++ b/matrix/Euler.hpp @@ -30,33 +30,28 @@ public: { } - Euler(Type phi, Type theta, Type psi) : Vector() + Euler(Type phi_, Type theta_, Type psi_) : Vector() { - this->phi() = phi; - this->theta() = theta; - this->psi() = psi; + phi() = phi_; + theta() = theta_; + psi() = psi_; } Euler(const Dcm & dcm) { - Type theta = asin(-dcm(2, 0)); - Type phi = 0; - Type psi = 0; + theta() = Type(asin(-dcm(2, 0))); - if (fabs(theta - M_PI_2) < 1.0e-3) { - psi = atan2(dcm(1, 2) - dcm(0, 1), - dcm(0, 2) + dcm(1, 1)); + if (fabs(theta() - M_PI_2) < 1.0e-3) { + psi() = Type(atan2(dcm(1, 2) - dcm(0, 1), + dcm(0, 2) + dcm(1, 1))); - } else if (fabs(theta + M_PI_2) < 1.0e-3) { - psi = atan2(dcm(1, 2) - dcm(0, 1), - dcm(0, 2) + dcm(1, 1)); + } else if (fabs(theta() + M_PI_2) < 1.0e-3) { + psi() = Type(atan2(dcm(1, 2) - dcm(0, 1), + dcm(0, 2) + dcm(1, 1))); } else { - phi = atan2f(dcm(2, 1), dcm(2, 2)); - psi = atan2f(dcm(1, 0), dcm(0, 0)); + phi() = Type(atan2f(dcm(2, 1), dcm(2, 2))); + psi() = Type(atan2f(dcm(1, 0), dcm(0, 0))); } - this->phi() = phi; - this->theta() = theta; - this->psi() = psi; } Euler(const Quaternion & q) { diff --git a/matrix/Matrix.hpp b/matrix/Matrix.hpp index b73dece8b3e..31cb1dbfe4b 100644 --- a/matrix/Matrix.hpp +++ b/matrix/Matrix.hpp @@ -38,10 +38,10 @@ public: { } - Matrix(const Type *data) : + Matrix(const Type *data_) : _data() { - memcpy(_data, data, sizeof(_data)); + memcpy(_data, data_, sizeof(_data)); } Matrix(const Matrix &other) : @@ -113,10 +113,11 @@ public: { Matrix res; const Matrix &self = *this; + static const Type eps = Type(1e-7); for (size_t i = 0; i < M; i++) { for (size_t j = 0; j < N; j++) { - if (self(i , j) != other(i, j)) { + if (fabs(self(i , j) - other(i, j)) > eps) { return false; } } @@ -298,7 +299,7 @@ public: Matrix r; for (int i=0; i max) { - max = val; + if (val > max_val) { + max_val = val; } } } - return max; + return max_val; } Type min() { - Type min = (*this)(0,0); + Type min_val = (*this)(0,0); for (int i=0; i() { Quaternion &q = *this; - q(0) = 0.5 * sqrt(1 + dcm(0, 0) + - dcm(1, 1) + dcm(2, 2)); - q(1) = (dcm(2, 1) - dcm(1, 2)) / - (4 * q(0)); - q(2) = (dcm(0, 2) - dcm(2, 0)) / - (4 * q(0)); - q(3) = (dcm(1, 0) - dcm(0, 1)) / - (4 * q(0)); + q(0) = Type(0.5 * sqrt(1 + dcm(0, 0) + + dcm(1, 1) + dcm(2, 2))); + q(1) = Type((dcm(2, 1) - dcm(1, 2)) / + (4 * q(0))); + q(2) = Type((dcm(0, 2) - dcm(2, 0)) / + (4 * q(0))); + q(3) = Type((dcm(1, 0) - dcm(0, 1)) / + (4 * q(0))); } Quaternion(const Euler & euler) { Quaternion &q = *this; - Type cosPhi_2 = cos(euler.phi() / 2.0); - Type cosTheta_2 = cos(euler.theta() / 2.0); - Type cosPsi_2 = cos(euler.psi() / 2.0); - Type sinPhi_2 = sin(euler.phi() / 2.0); - Type sinTheta_2 = sin(euler.theta() / 2.0); - Type sinPsi_2 = sin(euler.psi() / 2.0); + Type cosPhi_2 = Type(cos(euler.phi() / 2.0)); + Type cosTheta_2 = Type(cos(euler.theta() / 2.0)); + Type cosPsi_2 = Type(cos(euler.psi() / 2.0)); + Type sinPhi_2 = Type(sin(euler.phi() / 2.0)); + Type sinTheta_2 = Type(sin(euler.theta() / 2.0)); + Type sinPsi_2 = Type(sin(euler.psi() / 2.0)); q(0) = cosPhi_2 * cosTheta_2 * cosPsi_2 + sinPhi_2 * sinTheta_2 * sinPsi_2; q(1) = sinPhi_2 * cosTheta_2 * cosPsi_2 - @@ -102,7 +102,7 @@ public: v(1) = w(0); v(2) = w(1); v(3) = w(2); - return Q * v * 0.5; + return Q * v * Type(0.5); } }; diff --git a/matrix/SquareMatrix.hpp b/matrix/SquareMatrix.hpp index 56bd5d37ccd..931bbb94a8c 100644 --- a/matrix/SquareMatrix.hpp +++ b/matrix/SquareMatrix.hpp @@ -31,8 +31,8 @@ public: { } - SquareMatrix(const Type *data) : - Matrix(data) + SquareMatrix(const Type *data_) : + Matrix(data_) { } @@ -181,7 +181,7 @@ public: SquareMatrix res; res.setIdentity(); SquareMatrix A_pow = *this; - float k_fact = 1; + size_t k_fact = 1; size_t k = 1; while (k < n) { diff --git a/matrix/Vector.hpp b/matrix/Vector.hpp index 671b26c614a..381a8571174 100644 --- a/matrix/Vector.hpp +++ b/matrix/Vector.hpp @@ -58,7 +58,7 @@ public: Type norm() const { const Vector &a(*this); - return sqrt(a.dot(a)); + return Type(sqrt(a.dot(a))); } inline void normalize() { @@ -81,20 +81,6 @@ public: return res; } - bool operator==(const Vector &other) const - { - Vector res; - const Vector &self = *this; - - for (size_t i = 0; i < M; i++) { - if (self(i) != other(i)) { - return false; - } - } - - return true; - } - Vector operator-(const Vector &other) const { Vector res; diff --git a/test/attitude.cpp b/test/attitude.cpp index 173f1de2c81..38e2476bb27 100644 --- a/test/attitude.cpp +++ b/test/attitude.cpp @@ -16,31 +16,31 @@ int main() double eps = 1e-6; // check data - Eulerf euler_check(0.1, 0.2, 0.3); - Quatf q_check(0.98334744, 0.0342708, 0.10602051, .14357218); + Eulerf euler_check(0.1f, 0.2f, 0.3f); + Quatf q_check(0.98334744f, 0.0342708f, 0.10602051f, .14357218f); float dcm_data[] = { - 0.93629336, -0.27509585, 0.21835066, - 0.28962948, 0.95642509, -0.03695701, - -0.19866933, 0.0978434 , 0.97517033 + 0.93629336f, -0.27509585f, 0.21835066f, + 0.28962948f, 0.95642509f, -0.03695701f, + -0.19866933f, 0.0978434f, 0.97517033f }; Dcmf dcm_check(dcm_data); // euler ctor euler_check.T().print(); - assert((euler_check - Vector3f(0.1, 0.2, 0.3)).norm() < eps); + assert((euler_check - Vector3f(0.1f, 0.2f, 0.3f)).norm() < eps); // quaternion ctor Quatf q(1, 2, 3, 4); - assert(q(0) == 1); - assert(q(1) == 2); - assert(q(2) == 3); - assert(q(3) == 4); + assert(fabs(q(0) - 1) < eps); + assert(fabs(q(1) - 2) < eps); + assert(fabs(q(2) - 3) < eps); + assert(fabs(q(3) - 4) < eps); q.T().print(); q.normalize(); q.T().print(); assert((q - Quatf( - 0.18257419, 0.36514837, 0.54772256, 0.73029674) + 0.18257419f, 0.36514837f, 0.54772256f, 0.73029674f) ).norm() < eps); // euler to quaternion diff --git a/test/setIdentity.cpp b/test/setIdentity.cpp index e3b4a2e7dc0..75e1c8e69a9 100644 --- a/test/setIdentity.cpp +++ b/test/setIdentity.cpp @@ -13,10 +13,10 @@ int main() for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (i == j) { - assert(A(i, j) == 1); + assert( fabs(A(i, j) - 1) < 1e-7); } else { - assert(A(i, j) == 0); + assert( fabs(A(i, j) - 0) < 1e-7); } } } diff --git a/test/vectorAssignment.cpp b/test/vectorAssignment.cpp index 9295fc1936f..258616f3389 100644 --- a/test/vectorAssignment.cpp +++ b/test/vectorAssignment.cpp @@ -14,17 +14,19 @@ int main() v.print(); - assert(v(0) == 1); - assert(v(1) == 2); - assert(v(2) == 3); + static const float eps = 1e-7f; + + assert(fabs(v(0) - 1) < eps); + assert(fabs(v(1) - 2) < eps); + assert(fabs(v(2) - 3) < eps); Vector3f v2(4, 5, 6); v2.print(); - assert(v2(0) == 4); - assert(v2(1) == 5); - assert(v2(2) == 6); + assert(fabs(v2(0) - 4) < eps); + assert(fabs(v2(1) - 5) < eps); + assert(fabs(v2(2) - 6) < eps); return 0; }