mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-24 01:31:46 +00:00
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:
@@ -70,19 +70,8 @@ class WPILIB_DLLEXPORT Pose2d {
|
||||
|
||||
/**
|
||||
* Checks equality between this Pose2d and another object.
|
||||
*
|
||||
* @param other The other object.
|
||||
* @return Whether the two objects are equal.
|
||||
*/
|
||||
bool operator==(const Pose2d& other) const;
|
||||
|
||||
/**
|
||||
* Checks inequality between this Pose2d and another object.
|
||||
*
|
||||
* @param other The other object.
|
||||
* @return Whether the two objects are not equal.
|
||||
*/
|
||||
bool operator!=(const Pose2d& other) const;
|
||||
bool operator==(const Pose2d&) const = default;
|
||||
|
||||
/**
|
||||
* Returns the underlying translation.
|
||||
|
||||
@@ -74,19 +74,8 @@ class WPILIB_DLLEXPORT Pose3d {
|
||||
|
||||
/**
|
||||
* Checks equality between this Pose3d and another object.
|
||||
*
|
||||
* @param other The other object.
|
||||
* @return Whether the two objects are equal.
|
||||
*/
|
||||
bool operator==(const Pose3d& other) const;
|
||||
|
||||
/**
|
||||
* Checks inequality between this Pose3d and another object.
|
||||
*
|
||||
* @param other The other object.
|
||||
* @return Whether the two objects are not equal.
|
||||
*/
|
||||
bool operator!=(const Pose3d& other) const;
|
||||
bool operator==(const Pose3d&) const = default;
|
||||
|
||||
/**
|
||||
* Returns the underlying translation.
|
||||
|
||||
@@ -46,14 +46,6 @@ class WPILIB_DLLEXPORT Quaternion {
|
||||
*/
|
||||
bool operator==(const Quaternion& other) const;
|
||||
|
||||
/**
|
||||
* Checks inequality between this Quaternion and another object.
|
||||
*
|
||||
* @param other The other object.
|
||||
* @return Whether the two objects are not equal.
|
||||
*/
|
||||
bool operator!=(const Quaternion& other) const;
|
||||
|
||||
/**
|
||||
* Returns the inverse of the quaternion.
|
||||
*/
|
||||
|
||||
@@ -108,14 +108,6 @@ class WPILIB_DLLEXPORT Rotation2d {
|
||||
*/
|
||||
constexpr bool operator==(const Rotation2d& other) const;
|
||||
|
||||
/**
|
||||
* Checks inequality between this Rotation2d and another object.
|
||||
*
|
||||
* @param other The other object.
|
||||
* @return Whether the two objects are not equal.
|
||||
*/
|
||||
constexpr bool operator!=(const Rotation2d& other) const;
|
||||
|
||||
/**
|
||||
* Adds the new rotation to the current rotation using a rotation matrix.
|
||||
*
|
||||
|
||||
@@ -58,10 +58,6 @@ constexpr bool Rotation2d::operator==(const Rotation2d& other) const {
|
||||
: std::hypot(Cos() - other.Cos(), Sin() - other.Sin())) < 1E-9;
|
||||
}
|
||||
|
||||
constexpr bool Rotation2d::operator!=(const Rotation2d& other) const {
|
||||
return !operator==(other);
|
||||
}
|
||||
|
||||
constexpr Rotation2d Rotation2d::RotateBy(const Rotation2d& other) const {
|
||||
return {Cos() * other.Cos() - Sin() * other.Sin(),
|
||||
Cos() * other.Sin() + Sin() * other.Cos()};
|
||||
|
||||
@@ -125,19 +125,8 @@ class WPILIB_DLLEXPORT Rotation3d {
|
||||
|
||||
/**
|
||||
* Checks equality between this Rotation3d and another object.
|
||||
*
|
||||
* @param other The other object.
|
||||
* @return Whether the two objects are equal.
|
||||
*/
|
||||
bool operator==(const Rotation3d& other) const;
|
||||
|
||||
/**
|
||||
* Checks inequality between this Rotation3d and another object.
|
||||
*
|
||||
* @param other The other object.
|
||||
* @return Whether the two objects are not equal.
|
||||
*/
|
||||
bool operator!=(const Rotation3d& other) const;
|
||||
bool operator==(const Rotation3d&) const = default;
|
||||
|
||||
/**
|
||||
* Adds the new rotation to the current rotation.
|
||||
|
||||
@@ -103,19 +103,8 @@ class WPILIB_DLLEXPORT Transform2d {
|
||||
|
||||
/**
|
||||
* Checks equality between this Transform2d and another object.
|
||||
*
|
||||
* @param other The other object.
|
||||
* @return Whether the two objects are equal.
|
||||
*/
|
||||
bool operator==(const Transform2d& other) const;
|
||||
|
||||
/**
|
||||
* Checks inequality between this Transform2d and another object.
|
||||
*
|
||||
* @param other The other object.
|
||||
* @return Whether the two objects are not equal.
|
||||
*/
|
||||
bool operator!=(const Transform2d& other) const;
|
||||
bool operator==(const Transform2d&) const = default;
|
||||
|
||||
private:
|
||||
Translation2d m_translation;
|
||||
|
||||
@@ -108,19 +108,8 @@ class WPILIB_DLLEXPORT Transform3d {
|
||||
|
||||
/**
|
||||
* Checks equality between this Transform3d and another object.
|
||||
*
|
||||
* @param other The other object.
|
||||
* @return Whether the two objects are equal.
|
||||
*/
|
||||
bool operator==(const Transform3d& other) const;
|
||||
|
||||
/**
|
||||
* Checks inequality between this Transform3d and another object.
|
||||
*
|
||||
* @param other The other object.
|
||||
* @return Whether the two objects are not equal.
|
||||
*/
|
||||
bool operator!=(const Transform3d& other) const;
|
||||
bool operator==(const Transform3d&) const = default;
|
||||
|
||||
private:
|
||||
Translation3d m_translation;
|
||||
|
||||
@@ -170,14 +170,6 @@ class WPILIB_DLLEXPORT Translation2d {
|
||||
*/
|
||||
bool operator==(const Translation2d& other) const;
|
||||
|
||||
/**
|
||||
* Checks inequality between this Translation2d and another object.
|
||||
*
|
||||
* @param other The other object.
|
||||
* @return Whether the two objects are not equal.
|
||||
*/
|
||||
bool operator!=(const Translation2d& other) const;
|
||||
|
||||
private:
|
||||
units::meter_t m_x = 0_m;
|
||||
units::meter_t m_y = 0_m;
|
||||
|
||||
@@ -172,14 +172,6 @@ class WPILIB_DLLEXPORT Translation3d {
|
||||
*/
|
||||
bool operator==(const Translation3d& other) const;
|
||||
|
||||
/**
|
||||
* Checks inequality between this Translation3d and another object.
|
||||
*
|
||||
* @param other The other object.
|
||||
* @return Whether the two objects are not equal.
|
||||
*/
|
||||
bool operator!=(const Translation3d& other) const;
|
||||
|
||||
private:
|
||||
units::meter_t m_x = 0_m;
|
||||
units::meter_t m_y = 0_m;
|
||||
|
||||
@@ -46,14 +46,6 @@ struct WPILIB_DLLEXPORT Twist2d {
|
||||
units::math::abs(dtheta - other.dtheta) < 1E-9_rad;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks inequality between this Twist2d and another object.
|
||||
*
|
||||
* @param other The other object.
|
||||
* @return Whether the two objects are not equal.
|
||||
*/
|
||||
bool operator!=(const Twist2d& other) const { return !operator==(other); }
|
||||
|
||||
/**
|
||||
* Scale this by a given factor.
|
||||
*
|
||||
|
||||
@@ -65,14 +65,6 @@ struct WPILIB_DLLEXPORT Twist3d {
|
||||
units::math::abs(rz - other.rz) < 1E-9_rad;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks inequality between this Twist3d and another object.
|
||||
*
|
||||
* @param other The other object.
|
||||
* @return Whether the two objects are not equal.
|
||||
*/
|
||||
bool operator!=(const Twist3d& other) const { return !operator==(other); }
|
||||
|
||||
/**
|
||||
* Scale this by a given factor.
|
||||
*
|
||||
|
||||
@@ -48,19 +48,8 @@ class WPILIB_DLLEXPORT Trajectory {
|
||||
|
||||
/**
|
||||
* Checks equality between this State and another object.
|
||||
*
|
||||
* @param other The other object.
|
||||
* @return Whether the two objects are equal.
|
||||
*/
|
||||
bool operator==(const State& other) const;
|
||||
|
||||
/**
|
||||
* Checks inequality between this State and another object.
|
||||
*
|
||||
* @param other The other object.
|
||||
* @return Whether the two objects are not equal.
|
||||
*/
|
||||
bool operator!=(const State& other) const;
|
||||
bool operator==(const State&) const = default;
|
||||
|
||||
/**
|
||||
* Interpolates between two States.
|
||||
@@ -140,19 +129,8 @@ class WPILIB_DLLEXPORT Trajectory {
|
||||
|
||||
/**
|
||||
* Checks equality between this Trajectory and another object.
|
||||
*
|
||||
* @param other The other object.
|
||||
* @return Whether the two objects are equal.
|
||||
*/
|
||||
bool operator==(const Trajectory& other) const;
|
||||
|
||||
/**
|
||||
* Checks inequality between this Trajectory and another object.
|
||||
*
|
||||
* @param other The other object.
|
||||
* @return Whether the two objects are inequal.
|
||||
*/
|
||||
bool operator!=(const Trajectory& other) const;
|
||||
bool operator==(const Trajectory&) const = default;
|
||||
|
||||
private:
|
||||
std::vector<State> m_states;
|
||||
|
||||
@@ -68,10 +68,7 @@ class TrapezoidProfile {
|
||||
public:
|
||||
Distance_t position{0};
|
||||
Velocity_t velocity{0};
|
||||
bool operator==(const State& rhs) const {
|
||||
return position == rhs.position && velocity == rhs.velocity;
|
||||
}
|
||||
bool operator!=(const State& rhs) const { return !(*this == rhs); }
|
||||
bool operator==(const State&) const = default;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user