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

@@ -125,13 +125,17 @@ void RobotDrive::Drive(double outputMagnitude, double curve) {
if (curve < 0) {
double value = std::log(-curve);
double ratio = (value - m_sensitivity) / (value + m_sensitivity);
if (ratio == 0) ratio = 0.0000000001;
if (ratio == 0) {
ratio = 0.0000000001;
}
leftOutput = outputMagnitude / ratio;
rightOutput = outputMagnitude;
} else if (curve > 0) {
double value = std::log(curve);
double ratio = (value - m_sensitivity) / (value + m_sensitivity);
if (ratio == 0) ratio = 0.0000000001;
if (ratio == 0) {
ratio = 0.0000000001;
}
leftOutput = outputMagnitude;
rightOutput = outputMagnitude / ratio;
} else {
@@ -339,12 +343,14 @@ void RobotDrive::SetLeftRightMotorOutputs(double leftOutput,
double rightOutput) {
wpi_assert(m_rearLeftMotor != nullptr && m_rearRightMotor != nullptr);
if (m_frontLeftMotor != nullptr)
if (m_frontLeftMotor != nullptr) {
m_frontLeftMotor->Set(Limit(leftOutput) * m_maxOutput);
}
m_rearLeftMotor->Set(Limit(leftOutput) * m_maxOutput);
if (m_frontRightMotor != nullptr)
if (m_frontRightMotor != nullptr) {
m_frontRightMotor->Set(-Limit(rightOutput) * m_maxOutput);
}
m_rearRightMotor->Set(-Limit(rightOutput) * m_maxOutput);
Feed();
@@ -375,21 +381,33 @@ void RobotDrive::SetSensitivity(double sensitivity) {
m_sensitivity = sensitivity;
}
void RobotDrive::SetMaxOutput(double maxOutput) { m_maxOutput = maxOutput; }
void RobotDrive::SetMaxOutput(double maxOutput) {
m_maxOutput = maxOutput;
}
void RobotDrive::GetDescription(wpi::raw_ostream& desc) const {
desc << "RobotDrive";
}
void RobotDrive::StopMotor() {
if (m_frontLeftMotor != nullptr) m_frontLeftMotor->StopMotor();
if (m_frontRightMotor != nullptr) m_frontRightMotor->StopMotor();
if (m_rearLeftMotor != nullptr) m_rearLeftMotor->StopMotor();
if (m_rearRightMotor != nullptr) m_rearRightMotor->StopMotor();
if (m_frontLeftMotor != nullptr) {
m_frontLeftMotor->StopMotor();
}
if (m_frontRightMotor != nullptr) {
m_frontRightMotor->StopMotor();
}
if (m_rearLeftMotor != nullptr) {
m_rearLeftMotor->StopMotor();
}
if (m_rearRightMotor != nullptr) {
m_rearRightMotor->StopMotor();
}
Feed();
}
void RobotDrive::InitRobotDrive() { SetSafetyEnabled(true); }
void RobotDrive::InitRobotDrive() {
SetSafetyEnabled(true);
}
double RobotDrive::Limit(double number) {
if (number > 1.0) {
@@ -405,7 +423,9 @@ void RobotDrive::Normalize(double* wheelSpeeds) {
double maxMagnitude = std::fabs(wheelSpeeds[0]);
for (int i = 1; i < kMaxNumberOfMotors; i++) {
double temp = std::fabs(wheelSpeeds[i]);
if (maxMagnitude < temp) maxMagnitude = temp;
if (maxMagnitude < temp) {
maxMagnitude = temp;
}
}
if (maxMagnitude > 1.0) {
for (int i = 0; i < kMaxNumberOfMotors; i++) {