Browse Source

clang-tidy trivial cleanup

master
Daniel Agar 8 years ago
parent
commit
cfa68c2196
  1. 9
      .clang-tidy
  2. 16
      CMakeLists.txt
  3. 2
      matrix/AxisAngle.hpp
  4. 2
      matrix/Dcm.hpp
  5. 26
      matrix/Matrix.hpp
  6. 6
      matrix/Scalar.hpp
  7. 6
      matrix/SquareMatrix.hpp
  8. 2
      matrix/Vector.hpp
  9. 7
      matrix/helper_functions.hpp
  10. 45
      test/attitude.cpp
  11. 10
      test/filter.cpp
  12. 9
      test/hatvee.cpp
  13. 10
      test/helper.cpp
  14. 12
      test/integration.cpp
  15. 10
      test/inverse.cpp
  16. 24
      test/matrixAssignment.cpp
  17. 7
      test/matrixMult.cpp
  18. 5
      test/matrixScalarMult.cpp
  19. 15
      test/setIdentity.cpp
  20. 7
      test/slice.cpp
  21. 6
      test/squareMatrix.cpp
  22. 9
      test/transpose.cpp
  23. 8
      test/vector.cpp
  24. 25
      test/vector2.cpp
  25. 31
      test/vector3.cpp
  26. 23
      test/vectorAssignment.cpp

9
.clang-tidy

@ -0,0 +1,9 @@ @@ -0,0 +1,9 @@
Checks: 'clang-diagnostic-*,clang-analyzer-*,*,
,-cppcoreguidelines-pro-type-vararg
,-cppcoreguidelines-pro-bounds-array-to-pointer-decay
,-cppcoreguidelines-pro-bounds-constant-array-index
,-cppcoreguidelines-pro-bounds-pointer-arithmetic
'
WarningsAsErrors: '*'
HeaderFilterRegex: '*.h, *.hpp, *.hh, *.hxx'

16
CMakeLists.txt

@ -6,6 +6,9 @@ set(VERSION_PATCH "2") @@ -6,6 +6,9 @@ set(VERSION_PATCH "2")
project(matrix CXX)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Build type" FORCE)
message(STATUS "set build type to ${CMAKE_BUILD_TYPE}")
@ -65,7 +68,6 @@ add_compile_options( @@ -65,7 +68,6 @@ add_compile_options(
-Wsign-conversion
-Wsign-promo
-Wstrict-null-sentinel
-Wstrict-overflow=5
-Wswitch-default
-Wundef
-Wuninitialized
@ -74,7 +76,14 @@ add_compile_options( @@ -74,7 +76,14 @@ add_compile_options(
# clang tolerate unknown gcc options
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
add_compile_options(-Wno-error=unused-command-line-argument-hard-error-in-future -Wno-unknown-warning-option)
add_compile_options(
-Wno-error=unused-command-line-argument-hard-error-in-future
-Wno-unknown-warning-option
)
else()
add_compile_options(
-Wstrict-overflow=5
)
endif()
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure)
@ -83,6 +92,9 @@ if(TESTING) @@ -83,6 +92,9 @@ if(TESTING)
enable_testing()
add_subdirectory(test)
add_dependencies(check test_build)
add_custom_target(clang-tidy COMMAND clang-tidy -p . ${CMAKE_SOURCE_DIR}/test/*.cpp)
add_dependencies(clang-tidy test_build)
endif()
if(FORMAT)

2
matrix/AxisAngle.hpp

@ -31,7 +31,7 @@ template<typename Type> @@ -31,7 +31,7 @@ template<typename Type>
class AxisAngle : public Vector<Type, 3>
{
public:
virtual ~AxisAngle() {};
~AxisAngle() override = default;
typedef Matrix<Type, 3, 1> Matrix31;

2
matrix/Dcm.hpp

@ -17,7 +17,6 @@ @@ -17,7 +17,6 @@
#include "math.hpp"
namespace matrix
{
@ -30,7 +29,6 @@ class Euler; @@ -30,7 +29,6 @@ class Euler;
template<typename Type>
class AxisAngle;
/**
* Direction cosine matrix class
*

26
matrix/Matrix.hpp

@ -8,11 +8,10 @@ @@ -8,11 +8,10 @@
#pragma once
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <cmath>
#include <cstdio>
#include <cstring>
#if defined(SUPPORT_STDIOSTREAM)
#include <iostream>
#include <iomanip>
@ -36,25 +35,20 @@ public: @@ -36,25 +35,20 @@ public:
virtual ~Matrix() {};
Matrix() :
_data()
{
}
// Constructors
Matrix() : _data() {}
Matrix(const Type data_[][N]) :
_data()
Matrix(const Type data_[][N]) : _data()
{
memcpy(_data, data_, sizeof(_data));
}
Matrix(const Type *data_) :
_data()
Matrix(const Type *data_) : _data()
{
memcpy(_data, data_, sizeof(_data));
}
Matrix(const Matrix &other) :
_data()
Matrix(const Matrix &other) : _data()
{
memcpy(_data, other._data, sizeof(_data));
}
@ -519,7 +513,7 @@ bool isEqualF(Type x, @@ -519,7 +513,7 @@ bool isEqualF(Type x,
bool equal = true;
if (fabsf(x - y) > eps) {
if (fabs(x - y) > eps) {
equal = false;
}

6
matrix/Scalar.hpp

@ -8,12 +8,6 @@ @@ -8,12 +8,6 @@
#pragma once
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "math.hpp"
namespace matrix

6
matrix/SquareMatrix.hpp

@ -8,12 +8,6 @@ @@ -8,12 +8,6 @@
#pragma once
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "math.hpp"
#include "helper_functions.hpp"

2
matrix/Vector.hpp

@ -22,7 +22,7 @@ template<typename Type, size_t M> @@ -22,7 +22,7 @@ template<typename Type, size_t M>
class Vector : public Matrix<Type, M, 1>
{
public:
virtual ~Vector() {};
~Vector() override = default;
typedef Matrix<Type, M, 1> MatrixM1;

7
matrix/helper_functions.hpp

@ -1,14 +1,7 @@ @@ -1,14 +1,7 @@
#pragma once
#include "math.hpp"
// grody hack - this should go once C++11 is supported
// on all platforms.
#if defined (__PX4_NUTTX) || defined (__PX4_QURT)
#include <math.h>
#else
#include <cmath>
#endif
namespace matrix
{

45
test/attitude.cpp

@ -1,21 +1,20 @@ @@ -1,21 +1,20 @@
#include <cstdio>
#include <stdexcept>
#include <matrix/math.hpp>
#include "test_macros.hpp"
#include <matrix/math.hpp>
using namespace matrix;
// important to list all classes here for coverage
template class Quaternion<float>;
template class Euler<float>;
template class Dcm<float>;
template class AxisAngle<float>;
template class Scalar<float>;
template class SquareMatrix<float, 2>;
template class Vector<float, 3>;
template class Vector2<float>;
template class Vector3<float>;
using matrix::AxisAnglef;
using matrix::Dcm;
using matrix::Dcmf;
using matrix::Euler;
using matrix::Eulerf;
using matrix::eye;
using matrix::isEqualF;
using matrix::Matrix;
using matrix::Quaternion;
using matrix::Quatf;
using matrix::SquareMatrix;
using matrix::Vector3f;
using matrix::Vector;
using matrix::zeros;
int main()
{
@ -51,10 +50,10 @@ int main() @@ -51,10 +50,10 @@ int main()
// quaternion ctor
Quatf q0(1, 2, 3, 4);
Quatf q(q0);
TEST(fabs(q(0) - 1) < eps);
TEST(fabs(q(1) - 2) < eps);
TEST(fabs(q(2) - 3) < eps);
TEST(fabs(q(3) - 4) < eps);
TEST(fabsf(q(0) - 1) < eps);
TEST(fabsf(q(1) - 2) < eps);
TEST(fabsf(q(2) - 3) < eps);
TEST(fabsf(q(3) - 4) < eps);
// quat normalization
q.normalize();
@ -102,10 +101,12 @@ int main() @@ -102,10 +101,12 @@ int main()
for (size_t i = 0; i < 1000; i++) {
A = R * A;
}
A.renormalize();
float err = 0.0f;
for (size_t row = 0; row < 3; row++) {
matrix::Vector3f rvec(A._data[row]);
for (auto & row : A._data) {
Vector3f rvec(row);
err += fabsf(1.0f - rvec.length());
}
TEST(err < eps);

10
test/filter.cpp

@ -1,9 +1,11 @@ @@ -1,9 +1,11 @@
#include <stdio.h>
#include <matrix/filter.hpp>
#include "test_macros.hpp"
#include <matrix/filter.hpp>
using namespace matrix;
using matrix::Matrix;
using matrix::kalman_correct;
using matrix::eye;
using matrix::SquareMatrix;
using matrix::Vector;
int main()
{

9
test/hatvee.cpp

@ -1,11 +1,10 @@ @@ -1,11 +1,10 @@
#include <stdio.h>
#include "test_macros.hpp"
#include <matrix/math.hpp>
using namespace matrix;
template class SquareMatrix<float, 3>;
using matrix::Dcm;
using matrix::Euler;
using matrix::isEqual;
using matrix::Vector3;
int main()
{

10
test/helper.cpp

@ -1,10 +1,10 @@ @@ -1,10 +1,10 @@
#include <stdio.h>
#include <matrix/helper_functions.hpp>
#include "test_macros.hpp"
#include <matrix/helper_functions.hpp>
using namespace matrix;
using matrix::isEqual;
using matrix::isEqualF;
using matrix::Vector3f;
using matrix::wrap_pi;
int main()
{

12
test/integration.cpp

@ -1,13 +1,13 @@ @@ -1,13 +1,13 @@
#include <stdio.h>
#include <matrix/integration.hpp>
#include "test_macros.hpp"
#include <matrix/integration.hpp>
using namespace matrix;
using matrix::Matrix;
using matrix::ones;
using matrix::Vector;
Vector<float, 6> f(float t, const Matrix<float, 6, 1> & y, const Matrix<float, 3, 1> & u);
Vector<float, 6> f(float t, const Matrix<float, 6, 1> & /*y*/, const Matrix<float, 3, 1> & /*u*/);
Vector<float, 6> f(float t, const Matrix<float, 6, 1> & y, const Matrix<float, 3, 1> & u) {
Vector<float, 6> f(float t, const Matrix<float, 6, 1> & /*y*/, const Matrix<float, 3, 1> & /*u*/) {
float v = -sinf(t);
return v*ones<float, 6, 1>();
}

10
test/inverse.cpp

@ -1,15 +1,11 @@ @@ -1,15 +1,11 @@
#include <stdio.h>
#include <matrix/math.hpp>
#include "test_macros.hpp"
#include <matrix/math.hpp>
using namespace matrix;
using matrix::SquareMatrix;
using matrix::zeros;
static const size_t n_large = 50;
template class SquareMatrix<float, 3>;
template class SquareMatrix<float, n_large>;
int main()
{
float data[9] = {0, 2, 3,

24
test/matrixAssignment.cpp

@ -1,9 +1,11 @@ @@ -1,9 +1,11 @@
#include <matrix/math.hpp>
#include "test_macros.hpp"
#include <matrix/math.hpp>
using namespace matrix;
template class Matrix<float, 3, 3>;
using matrix::Matrix;
using matrix::Matrix3f;
using matrix::Scalar;
using matrix::Vector;
using matrix::Vector2f;
int main()
{
@ -24,7 +26,7 @@ int main() @@ -24,7 +26,7 @@ int main()
Matrix3f m2(data);
for(int i=0; i<9; i++) {
TEST(fabs(data[i] - m2.data()[i]) < 1e-6f);
TEST(fabsf(data[i] - m2.data()[i]) < 1e-6f);
}
float data2d[3][3] = {
@ -34,7 +36,7 @@ int main() @@ -34,7 +36,7 @@ int main()
};
m2 = Matrix3f(data2d);
for(int i=0; i<9; i++) {
TEST(fabs(data[i] - m2.data()[i]) < 1e-6f);
TEST(fabsf(data[i] - m2.data()[i]) < 1e-6f);
}
float data_times_2[9] = {2, 4, 6, 8, 10, 12, 14, 16, 18};
@ -96,17 +98,17 @@ int main() @@ -96,17 +98,17 @@ int main()
m4.swapCols(2, 2);
TEST(isEqual(m4, Matrix3f(data)));
TEST(fabs(m4.min() - 1) < 1e-5);
TEST(fabs((-m4).min() + 9) < 1e-5);
TEST(fabsf(m4.min() - 1) < 1e-5);
TEST(fabsf((-m4).min() + 9) < 1e-5);
Scalar<float> s;
s = 1;
const Vector<float, 1> & s_vect = s;
TEST(fabs(s - 1) < 1e-5);
TEST(fabs(s_vect(0) - 1.0f) < 1e-5);
TEST(fabsf(s - 1) < 1e-5);
TEST(fabsf(s_vect(0) - 1.0f) < 1e-5);
Matrix<float, 1, 1> m5 = s;
TEST(fabs(m5(0,0) - s) < 1e-5);
TEST(fabsf(m5(0,0) - s) < 1e-5);
Matrix<float, 2, 2> m6;
m6.setRow(0, Vector2f(1, 2));

7
test/matrixMult.cpp

@ -1,9 +1,8 @@ @@ -1,9 +1,8 @@
#include <stdio.h>
#include <matrix/math.hpp>
#include "test_macros.hpp"
#include <matrix/math.hpp>
using namespace matrix;
using matrix::Matrix3f;
using matrix::eye;
int main()
{

5
test/matrixScalarMult.cpp

@ -1,9 +1,8 @@ @@ -1,9 +1,8 @@
#include <stdio.h>
#include "test_macros.hpp"
#include <matrix/math.hpp>
#include "test_macros.hpp"
using namespace matrix;
using matrix::Matrix3f;
int main()
{

15
test/setIdentity.cpp

@ -1,9 +1,7 @@ @@ -1,9 +1,7 @@
#include <matrix/math.hpp>
#include "test_macros.hpp"
#include <matrix/math.hpp>
using namespace matrix;
template class Matrix<float, 3, 3>;
using matrix::Matrix3f;
int main()
{
@ -13,10 +11,10 @@ int main() @@ -13,10 +11,10 @@ int main()
for (size_t i = 0; i < 3; i++) {
for (size_t j = 0; j < 3; j++) {
if (i == j) {
TEST( fabs(A(i, j) - 1) < 1e-7);
TEST(fabsf(A(i, j) - 1) < 1e-7);
} else {
TEST( fabs(A(i, j) - 0) < 1e-7);
TEST(fabsf(A(i, j) - 0) < 1e-7);
}
}
}
@ -27,13 +25,14 @@ int main() @@ -27,13 +25,14 @@ int main()
for (size_t i = 0; i < 3; i++) {
for (size_t j = 0; j < 3; j++) {
if (i == j) {
TEST( fabs(B(i, j) - 1) < 1e-7);
TEST(fabsf(B(i, j) - 1) < 1e-7);
} else {
TEST( fabs(B(i, j) - 0) < 1e-7);
TEST(fabsf(B(i, j) - 0) < 1e-7);
}
}
}
return 0;
}

7
test/slice.cpp

@ -1,9 +1,8 @@ @@ -1,9 +1,8 @@
#include <stdio.h>
#include <matrix/math.hpp>
#include "test_macros.hpp"
#include <matrix/math.hpp>
using namespace matrix;
using matrix::Matrix;
using matrix::SquareMatrix;
int main()
{

6
test/squareMatrix.cpp

@ -1,11 +1,9 @@ @@ -1,11 +1,9 @@
#include <stdio.h>
#include "test_macros.hpp"
#include <matrix/math.hpp>
using namespace matrix;
template class SquareMatrix<float, 3>;
using matrix::SquareMatrix;
using matrix::Vector3;
int main()
{

9
test/transpose.cpp

@ -1,12 +1,8 @@ @@ -1,12 +1,8 @@
#include <stdio.h>
#include <matrix/math.hpp>
#include "test_macros.hpp"
using namespace matrix;
#include <matrix/math.hpp>
template class Matrix<float, 2, 3>;
template class Matrix<float, 3, 2>;
using matrix::Matrix;
int main()
{
@ -16,6 +12,7 @@ int main() @@ -16,6 +12,7 @@ int main()
float data_check[6] = {1, 4, 2, 5, 3, 6};
Matrix<float, 3, 2> A_T_check(data_check);
TEST(isEqual(A_T, A_T_check));
return 0;
}

8
test/vector.cpp

@ -1,11 +1,9 @@ @@ -1,11 +1,9 @@
#include <stdio.h>
#include <matrix/math.hpp>
#include "test_macros.hpp"
using namespace matrix;
#include <matrix/math.hpp>
template class Vector<float, 5>;
using matrix::Vector;
using matrix::isEqualF;
int main()
{

25
test/vector2.cpp

@ -1,35 +1,34 @@ @@ -1,35 +1,34 @@
#include <stdio.h>
#include <matrix/math.hpp>
#include "test_macros.hpp"
using namespace matrix;
template class Vector<float, 2>;
using matrix::Vector2f;
using matrix::Matrix;
int main()
{
Vector2f a(1, 0);
Vector2f b(0, 1);
TEST(fabs(a % b - 1.0f) < 1e-5);
TEST(fabsf(a % b - 1.0f) < 1e-5);
Vector2f c;
TEST(fabs(c(0) - 0) < 1e-5);
TEST(fabs(c(1) - 0) < 1e-5);
TEST(fabsf(c(0) - 0) < 1e-5);
TEST(fabsf(c(1) - 0) < 1e-5);
Matrix<float, 2, 1> d(a);
TEST(fabs(d(0,0) - 1) < 1e-5);
TEST(fabs(d(1,0) - 0) < 1e-5);
TEST(fabsf(d(0,0) - 1) < 1e-5);
TEST(fabsf(d(1,0) - 0) < 1e-5);
Vector2f e(d);
TEST(fabs(e(0) - 1) < 1e-5);
TEST(fabs(e(1) - 0) < 1e-5);
TEST(fabsf(e(0) - 1) < 1e-5);
TEST(fabsf(e(1) - 0) < 1e-5);
float data[] = {4,5};
Vector2f f(data);
TEST(fabs(f(0) - 4) < 1e-5);
TEST(fabs(f(1) - 5) < 1e-5);
TEST(fabsf(f(0) - 4) < 1e-5);
TEST(fabsf(f(1) - 5) < 1e-5);
return 0;
}

31
test/vector3.cpp

@ -1,34 +1,33 @@ @@ -1,34 +1,33 @@
#include <stdio.h>
#include <matrix/math.hpp>
#include "test_macros.hpp"
using namespace matrix;
#include <matrix/math.hpp>
template class Vector<float, 3>;
using matrix::Vector3f;
using matrix::Matrix;
int main()
{
Vector3f a(1, 0, 0);
Vector3f b(0, 1, 0);
Vector3f c = a.cross(b);
TEST(isEqual(c, Vector3f(0,0,1)));
TEST(matrix::isEqual(c, Vector3f(0,0,1)));
c = a % b;
TEST (isEqual(c, Vector3f(0,0,1)));
TEST(matrix::isEqual(c, Vector3f(0,0,1)));
Matrix<float, 3, 1> d(c);
Vector3f e(d);
TEST (isEqual(e, d));
TEST (matrix::isEqual(e, d));
float data[] = {4, 5, 6};
Vector3f f(data);
TEST(isEqual(f, Vector3f(4, 5, 6)));
TEST(matrix::isEqual(f, Vector3f(4, 5, 6)));
TEST(matrix::isEqual(a + b, Vector3f(1, 1, 0)));
TEST(matrix::isEqual(a - b, Vector3f(1, -1, 0)));
TEST(matrix::isEqualF(a * b, 0.0f));
TEST(matrix::isEqual(-a, Vector3f(-1, 0, 0)));
TEST(matrix::isEqual(a.unit(), a));
TEST(matrix::isEqual(a.unit(), a.normalized()));
TEST(matrix::isEqual(a*2.0, Vector3f(2, 0, 0)));
TEST(isEqual(a + b, Vector3f(1, 1, 0)));
TEST(isEqual(a - b, Vector3f(1, -1, 0)));
TEST(isEqualF(a * b, 0.0f));
TEST(isEqual(-a, Vector3f(-1, 0, 0)));
TEST(isEqual(a.unit(), a));
TEST(isEqual(a.unit(), a.normalized()));
TEST(isEqual(a*2.0, Vector3f(2, 0, 0)));
return 0;
}

23
test/vectorAssignment.cpp

@ -2,9 +2,8 @@ @@ -2,9 +2,8 @@
#include "test_macros.hpp"
using namespace matrix;
template class Vector<float, 3>;
using matrix::SquareMatrix;
using matrix::Vector3f;
int main()
{
@ -15,20 +14,20 @@ int main() @@ -15,20 +14,20 @@ int main()
static const float eps = 1e-7f;
TEST(fabs(v(0) - 1) < eps);
TEST(fabs(v(1) - 2) < eps);
TEST(fabs(v(2) - 3) < eps);
TEST(fabsf(v(0) - 1) < eps);
TEST(fabsf(v(1) - 2) < eps);
TEST(fabsf(v(2) - 3) < eps);
Vector3f v2(4, 5, 6);
TEST(fabs(v2(0) - 4) < eps);
TEST(fabs(v2(1) - 5) < eps);
TEST(fabs(v2(2) - 6) < eps);
TEST(fabsf(v2(0) - 4) < eps);
TEST(fabsf(v2(1) - 5) < eps);
TEST(fabsf(v2(2) - 6) < eps);
SquareMatrix<float, 3> m = diag(Vector3f(1,2,3));
TEST(fabs(m(0, 0) - 1) < eps);
TEST(fabs(m(1, 1) - 2) < eps);
TEST(fabs(m(2, 2) - 3) < eps);
TEST(fabsf(m(0, 0) - 1) < eps);
TEST(fabsf(m(1, 1) - 2) < eps);
TEST(fabsf(m(2, 2) - 3) < eps);
return 0;
}

Loading…
Cancel
Save