Add braces to C++ single-line loops and conditionals (NFC) (#2973)

This makes code easier to read and more consistent between C++ and Java.
Also update clang-format settings to always add a line break (even if no braces are used).
This commit is contained in:
Peter Johnson
2020-12-28 12:58:06 -08:00
committed by GitHub
parent 0291a3ff56
commit 2aed432b4b
634 changed files with 10716 additions and 3938 deletions

View File

@@ -21,7 +21,9 @@ static wpi::mutex setLock;
MathShared& MathSharedStore::GetMathShared() {
std::scoped_lock lock(setLock);
if (!mathShared) mathShared = std::make_unique<DefaultMathShared>();
if (!mathShared) {
mathShared = std::make_unique<DefaultMathShared>();
}
return *mathShared;
}

View File

@@ -56,7 +56,9 @@ Rotation2d& Rotation2d::operator-=(const Rotation2d& other) {
return *this;
}
Rotation2d Rotation2d::operator-() const { return Rotation2d(-m_value); }
Rotation2d Rotation2d::operator-() const {
return Rotation2d(-m_value);
}
Rotation2d Rotation2d::operator*(double scalar) const {
return Rotation2d(m_value * scalar);

View File

@@ -48,7 +48,9 @@ Translation2d& Translation2d::operator-=(const Translation2d& other) {
return *this;
}
Translation2d Translation2d::operator-() const { return {-m_x, -m_y}; }
Translation2d Translation2d::operator-() const {
return {-m_x, -m_y};
}
Translation2d Translation2d::operator*(double scalar) const {
return {scalar * m_x, scalar * m_y};

View File

@@ -26,8 +26,9 @@ bool check_stabilizable(const Eigen::Ref<const Eigen::MatrixXd>& A,
for (int i = 0; i < n; i++) {
if (es.eigenvalues()[i].real() * es.eigenvalues()[i].real() +
es.eigenvalues()[i].imag() * es.eigenvalues()[i].imag() <
1)
1) {
continue;
}
Eigen::MatrixXcd E(n, n + m);
E << es.eigenvalues()[i] * Eigen::MatrixXcd::Identity(n, n) - A, B;

View File

@@ -31,7 +31,9 @@ Trajectory::State Trajectory::State::Interpolate(State endValue,
const auto deltaT = newT - t;
// If delta time is negative, flip the order of interpolation.
if (deltaT < 0_s) return endValue.Interpolate(*this, 1.0 - i);
if (deltaT < 0_s) {
return endValue.Interpolate(*this, 1.0 - i);
}
// Check whether the robot is reversing at this stage.
const auto reversing =
@@ -65,8 +67,12 @@ Trajectory::Trajectory(const std::vector<State>& states) : m_states(states) {
}
Trajectory::State Trajectory::Sample(units::second_t t) const {
if (t <= m_states.front().t) return m_states.front();
if (t >= m_totalTime) return m_states.back();
if (t <= m_states.front().t) {
return m_states.front();
}
if (t >= m_totalTime) {
return m_states.back();
}
// Use binary search to get the element with a timestamp no less than the
// requested timestamp. This starts at 1 because we use the previous state

View File

@@ -19,10 +19,11 @@ const Trajectory TrajectoryGenerator::kDoNothingTrajectory(
std::function<void(const char*)> TrajectoryGenerator::s_errorFunc;
void TrajectoryGenerator::ReportError(const char* error) {
if (s_errorFunc)
if (s_errorFunc) {
s_errorFunc(error);
else
} else {
wpi::errs() << "TrajectoryGenerator error: " << error << "\n";
}
}
Trajectory TrajectoryGenerator::GenerateTrajectory(
@@ -112,8 +113,11 @@ Trajectory TrajectoryGenerator::GenerateTrajectory(
const std::vector<Pose2d>& waypoints, const TrajectoryConfig& config) {
auto newWaypoints = waypoints;
const Transform2d flip{Translation2d(), Rotation2d(180_deg)};
if (config.IsReversed())
for (auto& waypoint : newWaypoints) waypoint += flip;
if (config.IsReversed()) {
for (auto& waypoint : newWaypoints) {
waypoint += flip;
}
}
std::vector<SplineParameterizer::PoseWithCurvature> points;
try {

View File

@@ -85,7 +85,9 @@ Trajectory TrajectoryParameterizer::TimeParameterizeTrajectory(
// Now enforce all acceleration limits.
EnforceAccelerationLimits(reversed, constraints, &constrainedState);
if (ds.to<double>() < kEpsilon) break;
if (ds.to<double>() < kEpsilon) {
break;
}
// If the actual acceleration for this state is higher than the max
// acceleration that we applied, then we need to reduce the max
@@ -130,14 +132,18 @@ Trajectory TrajectoryParameterizer::TimeParameterizeTrajectory(
successor.minAcceleration * ds * 2.0);
// No more limits to impose! This state can be finalized.
if (newMaxVelocity >= constrainedState.maxVelocity) break;
if (newMaxVelocity >= constrainedState.maxVelocity) {
break;
}
constrainedState.maxVelocity = newMaxVelocity;
// Check all acceleration constraints with the new max velocity.
EnforceAccelerationLimits(reversed, constraints, &constrainedState);
if (ds.to<double>() > -kEpsilon) break;
if (ds.to<double>() > -kEpsilon) {
break;
}
// If the actual acceleration for this state is lower than the min
// acceleration, then we need to lower the min acceleration of the