mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-25 01:41:43 +00:00
[wpimath] Remove Rotation2d value field (#7490)
It's not part of SO(2).
This commit is contained in:
@@ -19,11 +19,6 @@ namespace frc {
|
||||
/**
|
||||
* A rotation in a 2D coordinate frame represented by a point on the unit circle
|
||||
* (cosine and sine).
|
||||
*
|
||||
* The angle is continuous, that is if a Rotation2d is constructed with 361
|
||||
* degrees, it will return 361 degrees. This allows algorithms that wouldn't
|
||||
* want to see a discontinuity in the rotations as it sweeps past from 360 to 0
|
||||
* on the second time around.
|
||||
*/
|
||||
class WPILIB_DLLEXPORT Rotation2d {
|
||||
public:
|
||||
@@ -38,8 +33,7 @@ class WPILIB_DLLEXPORT Rotation2d {
|
||||
* @param value The value of the angle.
|
||||
*/
|
||||
constexpr Rotation2d(units::angle_unit auto value) // NOLINT
|
||||
: m_value{value},
|
||||
m_cos{gcem::cos(value.template convert<units::radian>().value())},
|
||||
: m_cos{gcem::cos(value.template convert<units::radian>().value())},
|
||||
m_sin{gcem::sin(value.template convert<units::radian>().value())} {}
|
||||
|
||||
/**
|
||||
@@ -63,7 +57,6 @@ class WPILIB_DLLEXPORT Rotation2d {
|
||||
wpi::GetStackTrace(1));
|
||||
}
|
||||
}
|
||||
m_value = units::radian_t{gcem::atan2(m_sin, m_cos)};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,7 +95,7 @@ class WPILIB_DLLEXPORT Rotation2d {
|
||||
*
|
||||
* @return The inverse of the current rotation.
|
||||
*/
|
||||
constexpr Rotation2d operator-() const { return Rotation2d{-m_value}; }
|
||||
constexpr Rotation2d operator-() const { return Rotation2d{m_cos, -m_sin}; }
|
||||
|
||||
/**
|
||||
* Multiplies the current rotation by a scalar.
|
||||
@@ -112,7 +105,7 @@ class WPILIB_DLLEXPORT Rotation2d {
|
||||
* @return The new scaled Rotation2d.
|
||||
*/
|
||||
constexpr Rotation2d operator*(double scalar) const {
|
||||
return Rotation2d{m_value * scalar};
|
||||
return Rotation2d{Radians() * scalar};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -155,20 +148,20 @@ class WPILIB_DLLEXPORT Rotation2d {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the radian value of the rotation.
|
||||
* Returns the radian value of the rotation constrained within [-π, π].
|
||||
*
|
||||
* @return The radian value of the rotation.
|
||||
* @see AngleModulus to constrain the angle within (-π, π]
|
||||
* @return The radian value of the rotation constrained within [-π, π].
|
||||
*/
|
||||
constexpr units::radian_t Radians() const { return m_value; }
|
||||
constexpr units::radian_t Radians() const {
|
||||
return units::radian_t{gcem::atan2(m_sin, m_cos)};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the degree value of the rotation.
|
||||
* Returns the degree value of the rotation constrained within [-180, 180].
|
||||
*
|
||||
* @return The degree value of the rotation.
|
||||
* @see InputModulus to constrain the angle within (-180, 180]
|
||||
* @return The degree value of the rotation constrained within [-180, 180].
|
||||
*/
|
||||
constexpr units::degree_t Degrees() const { return m_value; }
|
||||
constexpr units::degree_t Degrees() const { return Radians(); }
|
||||
|
||||
/**
|
||||
* Returns the cosine of the rotation.
|
||||
@@ -192,7 +185,6 @@ class WPILIB_DLLEXPORT Rotation2d {
|
||||
constexpr double Tan() const { return Sin() / Cos(); }
|
||||
|
||||
private:
|
||||
units::radian_t m_value = 0_rad;
|
||||
double m_cos = 1;
|
||||
double m_sin = 0;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user