Use defaulted comparison operators in C++ (#4723)

Comparison operators which compared against every class member variable
now use C++20's default comparison operators.

Also remove operator!= that in C++20 is now auto-generated from operator==.
This commit is contained in:
Tyler Veness
2022-11-27 21:01:01 -08:00
committed by GitHub
parent 135c13958f
commit 42b6d4e3f7
39 changed files with 25 additions and 367 deletions

View File

@@ -15,14 +15,6 @@ Transform2d Pose2d::operator-(const Pose2d& other) const {
return Transform2d{pose.Translation(), pose.Rotation()};
}
bool Pose2d::operator==(const Pose2d& other) const {
return m_translation == other.m_translation && m_rotation == other.m_rotation;
}
bool Pose2d::operator!=(const Pose2d& other) const {
return !operator==(other);
}
Pose2d Pose2d::RelativeTo(const Pose2d& other) const {
const Transform2d transform{other, *this};
return {transform.Translation(), transform.Rotation()};

View File

@@ -52,14 +52,6 @@ Transform3d Pose3d::operator-(const Pose3d& other) const {
return Transform3d{pose.Translation(), pose.Rotation()};
}
bool Pose3d::operator==(const Pose3d& other) const {
return m_translation == other.m_translation && m_rotation == other.m_rotation;
}
bool Pose3d::operator!=(const Pose3d& other) const {
return !operator==(other);
}
Pose3d Pose3d::operator*(double scalar) const {
return Pose3d{m_translation * scalar, m_rotation * scalar};
}

View File

@@ -33,10 +33,6 @@ bool Quaternion::operator==(const Quaternion& other) const {
return std::abs(m_r * other.m_r + m_v.dot(other.m_v)) > 1.0 - 1E-9;
}
bool Quaternion::operator!=(const Quaternion& other) const {
return !operator==(other);
}
Quaternion Quaternion::Inverse() const {
return Quaternion{m_r, -m_v(0), -m_v(1), -m_v(2)};
}

View File

@@ -170,14 +170,6 @@ Rotation3d Rotation3d::operator/(double scalar) const {
return *this * (1.0 / scalar);
}
bool Rotation3d::operator==(const Rotation3d& other) const {
return m_q == other.m_q;
}
bool Rotation3d::operator!=(const Rotation3d& other) const {
return !operator==(other);
}
Rotation3d Rotation3d::RotateBy(const Rotation3d& other) const {
return Rotation3d{other.m_q * m_q};
}

View File

@@ -21,11 +21,3 @@ Transform2d::Transform2d(Pose2d initial, Pose2d final) {
Transform2d Transform2d::operator+(const Transform2d& other) const {
return Transform2d{Pose2d{}, Pose2d{}.TransformBy(*this).TransformBy(other)};
}
bool Transform2d::operator==(const Transform2d& other) const {
return m_translation == other.m_translation && m_rotation == other.m_rotation;
}
bool Transform2d::operator!=(const Transform2d& other) const {
return !operator==(other);
}

View File

@@ -31,11 +31,3 @@ Transform3d Transform3d::Inverse() const {
Transform3d Transform3d::operator+(const Transform3d& other) const {
return Transform3d{Pose3d{}, Pose3d{}.TransformBy(*this).TransformBy(other)};
}
bool Transform3d::operator==(const Transform3d& other) const {
return m_translation == other.m_translation && m_rotation == other.m_rotation;
}
bool Transform3d::operator!=(const Transform3d& other) const {
return !operator==(other);
}

View File

@@ -23,10 +23,6 @@ bool Translation2d::operator==(const Translation2d& other) const {
units::math::abs(m_y - other.m_y) < 1E-9_m;
}
bool Translation2d::operator!=(const Translation2d& other) const {
return !operator==(other);
}
void frc::to_json(wpi::json& json, const Translation2d& translation) {
json =
wpi::json{{"x", translation.X().value()}, {"y", translation.Y().value()}};

View File

@@ -41,10 +41,6 @@ bool Translation3d::operator==(const Translation3d& other) const {
units::math::abs(m_z - other.m_z) < 1E-9_m;
}
bool Translation3d::operator!=(const Translation3d& other) const {
return !operator==(other);
}
void frc::to_json(wpi::json& json, const Translation3d& translation) {
json = wpi::json{{"x", translation.X().value()},
{"y", translation.Y().value()},

View File

@@ -13,16 +13,6 @@
using namespace frc;
bool Trajectory::State::operator==(const Trajectory::State& other) const {
return t == other.t && velocity == other.velocity &&
acceleration == other.acceleration && pose == other.pose &&
curvature == other.curvature;
}
bool Trajectory::State::operator!=(const Trajectory::State& other) const {
return !operator==(other);
}
Trajectory::State Trajectory::State::Interpolate(State endValue,
double i) const {
// Find the new [t] value.
@@ -163,11 +153,3 @@ void frc::from_json(const wpi::json& json, Trajectory::State& state) {
units::meters_per_second_squared_t{json.at("acceleration").get<double>()};
state.curvature = units::curvature_t{json.at("curvature").get<double>()};
}
bool Trajectory::operator==(const Trajectory& other) const {
return m_states == other.States();
}
bool Trajectory::operator!=(const Trajectory& other) const {
return !operator==(other);
}