fix formatting for (non-generated) internal source files - Change formatting standard to Cpp11. Main difference is not having the space between two closing >> for nested templates. We don't choose c++14, because older versions of clang-format (version 9 and earlier) don't know this value yet, and it doesn't make a difference in the formatting. - Apply clang-format to all (non generated) internal source files. - Manually fix some code sections (clang-format on/off) and c-strings - Exclude some embedded external files with very different formatting (gtest/gmock) - Add script to format all source files Change-Id: Ic6cea41575ad6e37c9e136dbce176b0d505dc44d
diff --git a/internal/ceres/cubic_interpolation_test.cc b/internal/ceres/cubic_interpolation_test.cc index 4cf27ff..3907d22 100644 --- a/internal/ceres/cubic_interpolation_test.cc +++ b/internal/ceres/cubic_interpolation_test.cc
@@ -31,6 +31,7 @@ #include "ceres/cubic_interpolation.h" #include <memory> + #include "ceres/jet.h" #include "glog/logging.h" #include "gtest/gtest.h" @@ -65,9 +66,11 @@ } TEST(Grid1D, TwoDataDimensionIntegerDataInterleaved) { + // clang-format off int x[] = {1, 5, 2, 6, 3, 7}; + // clang-format on Grid1D<int, 2, true> grid(x, 0, 3); for (int i = 0; i < 3; ++i) { @@ -78,10 +81,11 @@ } } - TEST(Grid1D, TwoDataDimensionIntegerDataStacked) { + // clang-format off int x[] = {1, 2, 3, 5, 6, 7}; + // clang-format on Grid1D<int, 2, false> grid(x, 0, 3); for (int i = 0; i < 3; ++i) { @@ -93,8 +97,10 @@ } TEST(Grid2D, OneDataDimensionRowMajor) { + // clang-format off int x[] = {1, 2, 3, 2, 3, 4}; + // clang-format on Grid2D<int, 1, true, true> grid(x, 0, 2, 0, 3); for (int r = 0; r < 2; ++r) { for (int c = 0; c < 3; ++c) { @@ -106,8 +112,10 @@ } TEST(Grid2D, OneDataDimensionRowMajorOutOfBounds) { + // clang-format off int x[] = {1, 2, 3, 2, 3, 4}; + // clang-format on Grid2D<int, 1, true, true> grid(x, 0, 2, 0, 3); double value; grid.GetValue(-1, -1, &value); @@ -141,64 +149,72 @@ } TEST(Grid2D, TwoDataDimensionRowMajorInterleaved) { + // clang-format off int x[] = {1, 4, 2, 8, 3, 12, 2, 8, 3, 12, 4, 16}; + // clang-format on Grid2D<int, 2, true, true> grid(x, 0, 2, 0, 3); for (int r = 0; r < 2; ++r) { for (int c = 0; c < 3; ++c) { double value[2]; grid.GetValue(r, c, value); EXPECT_EQ(value[0], static_cast<double>(r + c + 1)); - EXPECT_EQ(value[1], static_cast<double>(4 *(r + c + 1))); + EXPECT_EQ(value[1], static_cast<double>(4 * (r + c + 1))); } } } TEST(Grid2D, TwoDataDimensionRowMajorStacked) { + // clang-format off int x[] = {1, 2, 3, 2, 3, 4, 4, 8, 12, 8, 12, 16}; + // clang-format on Grid2D<int, 2, true, false> grid(x, 0, 2, 0, 3); for (int r = 0; r < 2; ++r) { for (int c = 0; c < 3; ++c) { double value[2]; grid.GetValue(r, c, value); EXPECT_EQ(value[0], static_cast<double>(r + c + 1)); - EXPECT_EQ(value[1], static_cast<double>(4 *(r + c + 1))); + EXPECT_EQ(value[1], static_cast<double>(4 * (r + c + 1))); } } } TEST(Grid2D, TwoDataDimensionColMajorInterleaved) { + // clang-format off int x[] = { 1, 4, 2, 8, 2, 8, 3, 12, 3, 12, 4, 16}; + // clang-format on Grid2D<int, 2, false, true> grid(x, 0, 2, 0, 3); for (int r = 0; r < 2; ++r) { for (int c = 0; c < 3; ++c) { double value[2]; grid.GetValue(r, c, value); EXPECT_EQ(value[0], static_cast<double>(r + c + 1)); - EXPECT_EQ(value[1], static_cast<double>(4 *(r + c + 1))); + EXPECT_EQ(value[1], static_cast<double>(4 * (r + c + 1))); } } } TEST(Grid2D, TwoDataDimensionColMajorStacked) { + // clang-format off int x[] = {1, 2, 2, 3, 3, 4, 4, 8, 8, 12, 12, 16}; + // clang-format on Grid2D<int, 2, false, false> grid(x, 0, 2, 0, 3); for (int r = 0; r < 2; ++r) { for (int c = 0; c < 3; ++c) { double value[2]; grid.GetValue(r, c, value); EXPECT_EQ(value[0], static_cast<double>(r + c + 1)); - EXPECT_EQ(value[1], static_cast<double>(4 *(r + c + 1))); + EXPECT_EQ(value[1], static_cast<double>(4 * (r + c + 1))); } } } @@ -214,8 +230,8 @@ for (int x = 0; x < kNumSamples; ++x) { for (int dim = 0; dim < kDataDimension; ++dim) { - values_[x * kDataDimension + dim] = - (dim * dim + 1) * (a * x * x * x + b * x * x + c * x + d); + values_[x * kDataDimension + dim] = + (dim * dim + 1) * (a * x * x * x + b * x * x + c * x + d); } } @@ -236,8 +252,9 @@ for (int dim = 0; dim < kDataDimension; ++dim) { expected_f[dim] = - (dim * dim + 1) * (a * x * x * x + b * x * x + c * x + d); - expected_dfdx[dim] = (dim * dim + 1) * (3.0 * a * x * x + 2.0 * b * x + c); + (dim * dim + 1) * (a * x * x * x + b * x * x + c * x + d); + expected_dfdx[dim] = + (dim * dim + 1) * (3.0 * a * x * x + 2.0 * b * x + c); } interpolator.Evaluate(x, f, dfdx); @@ -278,7 +295,6 @@ RunPolynomialInterpolationTest<3>(0.0, 0.4, 1.0, 0.5); } - TEST(CubicInterpolator, JetEvaluation) { const double values[] = {1.0, 2.0, 2.0, 5.0, 3.0, 9.0, 2.0, 7.0}; @@ -330,7 +346,8 @@ } } - Grid2D<double, kDataDimension> grid(values_.get(), 0, kNumRows, 0, kNumCols); + Grid2D<double, kDataDimension> grid( + values_.get(), 0, kNumRows, 0, kNumCols); BiCubicInterpolator<Grid2D<double, kDataDimension>> interpolator(grid); for (int j = 0; j < kNumRowSamples; ++j) { @@ -341,8 +358,10 @@ interpolator.Evaluate(r, c, f, dfdr, dfdc); for (int dim = 0; dim < kDataDimension; ++dim) { EXPECT_NEAR(f[dim], (dim * dim + 1) * EvaluateF(r, c), kTolerance); - EXPECT_NEAR(dfdr[dim], (dim * dim + 1) * EvaluatedFdr(r, c), kTolerance); - EXPECT_NEAR(dfdc[dim], (dim * dim + 1) * EvaluatedFdc(r, c), kTolerance); + EXPECT_NEAR( + dfdr[dim], (dim * dim + 1) * EvaluatedFdr(r, c), kTolerance); + EXPECT_NEAR( + dfdc[dim], (dim * dim + 1) * EvaluatedFdc(r, c), kTolerance); } } } @@ -373,7 +392,6 @@ return (coeff_.row(1) + coeff_.col(1).transpose()) * x; } - Eigen::Matrix3d coeff_; static constexpr int kNumRows = 10; static constexpr int kNumCols = 10; @@ -471,8 +489,10 @@ } TEST(BiCubicInterpolator, JetEvaluation) { + // clang-format off const double values[] = {1.0, 5.0, 2.0, 10.0, 2.0, 6.0, 3.0, 5.0, 1.0, 2.0, 2.0, 2.0, 2.0, 2.0, 3.0, 1.0}; + // clang-format on Grid2D<double, 2> grid(values, 0, 2, 0, 4); BiCubicInterpolator<Grid2D<double, 2>> interpolator(grid);