[wpimath] Make C++ geometry classes immutable (#3249)

This commit is contained in:
Prateek Machiraju
2021-03-19 16:38:54 -04:00
committed by GitHub
parent da96707dca
commit d3e45c297c
8 changed files with 2 additions and 126 deletions

View File

@@ -20,12 +20,6 @@ Pose2d Pose2d::operator+(const Transform2d& other) const {
return TransformBy(other);
}
Pose2d& Pose2d::operator+=(const Transform2d& other) {
m_translation += other.Translation().RotateBy(m_rotation);
m_rotation += other.Rotation();
return *this;
}
Transform2d Pose2d::operator-(const Pose2d& other) const {
const auto pose = this->RelativeTo(other);
return Transform2d(pose.Translation(), pose.Rotation());

View File

@@ -38,24 +38,10 @@ Rotation2d Rotation2d::operator+(const Rotation2d& other) const {
return RotateBy(other);
}
Rotation2d& Rotation2d::operator+=(const Rotation2d& other) {
double cos = Cos() * other.Cos() - Sin() * other.Sin();
double sin = Cos() * other.Sin() + Sin() * other.Cos();
m_cos = cos;
m_sin = sin;
m_value = units::radian_t(std::atan2(m_sin, m_cos));
return *this;
}
Rotation2d Rotation2d::operator-(const Rotation2d& other) const {
return *this + -other;
}
Rotation2d& Rotation2d::operator-=(const Rotation2d& other) {
*this += -other;
return *this;
}
Rotation2d Rotation2d::operator-() const {
return Rotation2d(-m_value);
}

View File

@@ -33,21 +33,10 @@ Translation2d Translation2d::operator+(const Translation2d& other) const {
return {X() + other.X(), Y() + other.Y()};
}
Translation2d& Translation2d::operator+=(const Translation2d& other) {
m_x += other.m_x;
m_y += other.m_y;
return *this;
}
Translation2d Translation2d::operator-(const Translation2d& other) const {
return *this + -other;
}
Translation2d& Translation2d::operator-=(const Translation2d& other) {
*this += -other;
return *this;
}
Translation2d Translation2d::operator-() const {
return {-m_x, -m_y};
}
@@ -56,12 +45,6 @@ Translation2d Translation2d::operator*(double scalar) const {
return {scalar * m_x, scalar * m_y};
}
Translation2d& Translation2d::operator*=(double scalar) {
m_x *= scalar;
m_y *= scalar;
return *this;
}
Translation2d Translation2d::operator/(double scalar) const {
return *this * (1.0 / scalar);
}
@@ -75,11 +58,6 @@ bool Translation2d::operator!=(const Translation2d& other) const {
return !operator==(other);
}
Translation2d& Translation2d::operator/=(double scalar) {
*this *= (1.0 / scalar);
return *this;
}
void frc::to_json(wpi::json& json, const Translation2d& translation) {
json = wpi::json{{"x", translation.X().to<double>()},
{"y", translation.Y().to<double>()}};