mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-23 01:21:42 +00:00
[wpimath] Make Rotation2d implicitly convert from any angle unit (#6316)
Add unit category concepts to support this.
This commit is contained in:
@@ -28,18 +28,11 @@ class WPILIB_DLLEXPORT Rotation2d {
|
||||
constexpr Rotation2d() = default;
|
||||
|
||||
/**
|
||||
* Constructs a Rotation2d with the given radian value.
|
||||
* Constructs a Rotation2d with the given angle.
|
||||
*
|
||||
* @param value The value of the angle in radians.
|
||||
* @param value The value of the angle.
|
||||
*/
|
||||
constexpr Rotation2d(units::radian_t value); // NOLINT
|
||||
|
||||
/**
|
||||
* Constructs a Rotation2d with the given degree value.
|
||||
*
|
||||
* @param value The value of the angle in degrees.
|
||||
*/
|
||||
constexpr Rotation2d(units::degree_t value); // NOLINT
|
||||
constexpr Rotation2d(units::angle_unit auto value); // NOLINT
|
||||
|
||||
/**
|
||||
* Constructs a Rotation2d with the given x and y (cosine and sine)
|
||||
|
||||
@@ -11,13 +11,10 @@
|
||||
|
||||
namespace frc {
|
||||
|
||||
constexpr Rotation2d::Rotation2d(units::radian_t value)
|
||||
constexpr Rotation2d::Rotation2d(units::angle_unit auto value)
|
||||
: m_value(value),
|
||||
m_cos(gcem::cos(value.to<double>())),
|
||||
m_sin(gcem::sin(value.to<double>())) {}
|
||||
|
||||
constexpr Rotation2d::Rotation2d(units::degree_t value)
|
||||
: Rotation2d(units::radian_t{value}) {}
|
||||
m_cos(gcem::cos(value.template convert<units::radian>().value())),
|
||||
m_sin(gcem::sin(value.template convert<units::radian>().value())) {}
|
||||
|
||||
constexpr Rotation2d::Rotation2d(double x, double y) {
|
||||
double magnitude = gcem::hypot(x, y);
|
||||
|
||||
Reference in New Issue
Block a user