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/examples/bal_problem.h b/examples/bal_problem.h
index 81e8844..e6d4ace 100644
--- a/examples/bal_problem.h
+++ b/examples/bal_problem.h
@@ -65,18 +65,20 @@
const double translation_sigma,
const double point_sigma);
- int camera_block_size() const { return use_quaternions_ ? 10 : 9; }
- int point_block_size() const { return 3; }
- int num_cameras() const { return num_cameras_; }
- int num_points() const { return num_points_; }
- int num_observations() const { return num_observations_; }
- int num_parameters() const { return num_parameters_; }
- const int* point_index() const { return point_index_; }
- const int* camera_index() const { return camera_index_; }
- const double* observations() const { return observations_; }
- const double* parameters() const { return parameters_; }
- const double* cameras() const { return parameters_; }
- double* mutable_cameras() { return parameters_; }
+ // clang-format off
+ int camera_block_size() const { return use_quaternions_ ? 10 : 9; }
+ int point_block_size() const { return 3; }
+ int num_cameras() const { return num_cameras_; }
+ int num_points() const { return num_points_; }
+ int num_observations() const { return num_observations_; }
+ int num_parameters() const { return num_parameters_; }
+ const int* point_index() const { return point_index_; }
+ const int* camera_index() const { return camera_index_; }
+ const double* observations() const { return observations_; }
+ const double* parameters() const { return parameters_; }
+ const double* cameras() const { return parameters_; }
+ double* mutable_cameras() { return parameters_; }
+ // clang-format on
double* mutable_points() {
return parameters_ + camera_block_size() * num_cameras_;
}
diff --git a/examples/fields_of_experts.h b/examples/fields_of_experts.h
index d7f1a4a..429881d 100644
--- a/examples/fields_of_experts.h
+++ b/examples/fields_of_experts.h
@@ -125,7 +125,7 @@
// The coefficients in front of each term.
std::vector<double> alpha_;
// The filters used for the dot product with image patches.
- std::vector<std::vector<double> > filters_;
+ std::vector<std::vector<double>> filters_;
};
} // namespace examples
diff --git a/examples/nist.cc b/examples/nist.cc
index 937d6bd..977b69d 100644
--- a/examples/nist.cc
+++ b/examples/nist.cc
@@ -167,7 +167,7 @@
void SplitStringUsingChar(const string& full,
const char delim,
vector<string>* result) {
- std::back_insert_iterator<vector<string> > it(*result);
+ std::back_insert_iterator<vector<string>> it(*result);
const char* p = full.data();
const char* end = p + full.size();
@@ -606,7 +606,7 @@
ceres::TinySolverCostFunctionAdapter<Eigen::Dynamic, num_parameters> cfa(
*cost_function);
typedef ceres::TinySolver<
- ceres::TinySolverCostFunctionAdapter<Eigen::Dynamic, num_parameters> >
+ ceres::TinySolverCostFunctionAdapter<Eigen::Dynamic, num_parameters>>
Solver;
Solver solver;
solver.options.max_num_iterations = FLAGS_num_iterations;
diff --git a/examples/sampled_function/sampled_function.cc b/examples/sampled_function/sampled_function.cc
index 7dec42b..e96018d 100644
--- a/examples/sampled_function/sampled_function.cc
+++ b/examples/sampled_function/sampled_function.cc
@@ -47,7 +47,7 @@
// values with automatic differentiation.
struct InterpolatedCostFunctor {
explicit InterpolatedCostFunctor(
- const CubicInterpolator<Grid1D<double> >& interpolator)
+ const CubicInterpolator<Grid1D<double>>& interpolator)
: interpolator_(interpolator) {}
template <typename T>
@@ -57,13 +57,13 @@
}
static CostFunction* Create(
- const CubicInterpolator<Grid1D<double> >& interpolator) {
+ const CubicInterpolator<Grid1D<double>>& interpolator) {
return new AutoDiffCostFunction<InterpolatedCostFunctor, 1, 1>(
new InterpolatedCostFunctor(interpolator));
}
private:
- const CubicInterpolator<Grid1D<double> >& interpolator_;
+ const CubicInterpolator<Grid1D<double>>& interpolator_;
};
int main(int argc, char** argv) {
@@ -77,7 +77,7 @@
}
Grid1D<double> array(values, 0, kNumSamples);
- CubicInterpolator<Grid1D<double> > interpolator(array);
+ CubicInterpolator<Grid1D<double>> interpolator(array);
double x = 1.0;
Problem problem;
diff --git a/examples/slam/pose_graph_2d/pose_graph_2d_error_term.h b/examples/slam/pose_graph_2d/pose_graph_2d_error_term.h
index 5d404e3..2df31f6 100644
--- a/examples/slam/pose_graph_2d/pose_graph_2d_error_term.h
+++ b/examples/slam/pose_graph_2d/pose_graph_2d_error_term.h
@@ -78,7 +78,7 @@
const Eigen::Matrix<T, 2, 1> p_a(*x_a, *y_a);
const Eigen::Matrix<T, 2, 1> p_b(*x_b, *y_b);
- Eigen::Map<Eigen::Matrix<T, 3, 1> > residuals_map(residuals_ptr);
+ Eigen::Map<Eigen::Matrix<T, 3, 1>> residuals_map(residuals_ptr);
residuals_map.template head<2>() =
RotationMatrix2D(*yaw_a).transpose() * (p_b - p_a) - p_ab_.cast<T>();
diff --git a/examples/slam/pose_graph_3d/pose_graph_3d.cc b/examples/slam/pose_graph_3d/pose_graph_3d.cc
index c54412d..2f8d6a4 100644
--- a/examples/slam/pose_graph_3d/pose_graph_3d.cc
+++ b/examples/slam/pose_graph_3d/pose_graph_3d.cc
@@ -133,14 +133,14 @@
for (std::map<int,
Pose3d,
std::less<int>,
- Eigen::aligned_allocator<std::pair<const int, Pose3d> > >::
+ Eigen::aligned_allocator<std::pair<const int, Pose3d>>>::
const_iterator poses_iter = poses.begin();
poses_iter != poses.end();
++poses_iter) {
const std::map<int,
Pose3d,
std::less<int>,
- Eigen::aligned_allocator<std::pair<const int, Pose3d> > >::
+ Eigen::aligned_allocator<std::pair<const int, Pose3d>>>::
value_type& pair = *poses_iter;
outfile << pair.first << " " << pair.second.p.transpose() << " "
<< pair.second.q.x() << " " << pair.second.q.y() << " "
diff --git a/examples/slam/pose_graph_3d/pose_graph_3d_error_term.h b/examples/slam/pose_graph_3d/pose_graph_3d_error_term.h
index c8def17..1f3e8de 100644
--- a/examples/slam/pose_graph_3d/pose_graph_3d_error_term.h
+++ b/examples/slam/pose_graph_3d/pose_graph_3d_error_term.h
@@ -79,11 +79,11 @@
const T* const p_b_ptr,
const T* const q_b_ptr,
T* residuals_ptr) const {
- Eigen::Map<const Eigen::Matrix<T, 3, 1> > p_a(p_a_ptr);
- Eigen::Map<const Eigen::Quaternion<T> > q_a(q_a_ptr);
+ Eigen::Map<const Eigen::Matrix<T, 3, 1>> p_a(p_a_ptr);
+ Eigen::Map<const Eigen::Quaternion<T>> q_a(q_a_ptr);
- Eigen::Map<const Eigen::Matrix<T, 3, 1> > p_b(p_b_ptr);
- Eigen::Map<const Eigen::Quaternion<T> > q_b(q_b_ptr);
+ Eigen::Map<const Eigen::Matrix<T, 3, 1>> p_b(p_b_ptr);
+ Eigen::Map<const Eigen::Quaternion<T>> q_b(q_b_ptr);
// Compute the relative transformation between the two frames.
Eigen::Quaternion<T> q_a_inverse = q_a.conjugate();
@@ -99,7 +99,7 @@
// Compute the residuals.
// [ position ] [ delta_p ]
// [ orientation (3x1)] = [ 2 * delta_q(0:2) ]
- Eigen::Map<Eigen::Matrix<T, 6, 1> > residuals(residuals_ptr);
+ Eigen::Map<Eigen::Matrix<T, 6, 1>> residuals(residuals_ptr);
residuals.template block<3, 1>(0, 0) =
p_ab_estimated - t_ab_measured_.p.template cast<T>();
residuals.template block<3, 1>(3, 0) = T(2.0) * delta_q.vec();
diff --git a/examples/slam/pose_graph_3d/types.h b/examples/slam/pose_graph_3d/types.h
index 25f7ba2..d3f19ed 100644
--- a/examples/slam/pose_graph_3d/types.h
+++ b/examples/slam/pose_graph_3d/types.h
@@ -64,7 +64,7 @@
typedef std::map<int,
Pose3d,
std::less<int>,
- Eigen::aligned_allocator<std::pair<const int, Pose3d> > >
+ Eigen::aligned_allocator<std::pair<const int, Pose3d>>>
MapOfPoses;
// The constraint between two vertices in the pose graph. The constraint is the
@@ -103,7 +103,7 @@
return input;
}
-typedef std::vector<Constraint3d, Eigen::aligned_allocator<Constraint3d> >
+typedef std::vector<Constraint3d, Eigen::aligned_allocator<Constraint3d>>
VectorOfConstraints;
} // namespace examples