mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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};
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user