[wpilibc] Add implicit conversion from degree_t to Rotation2d (#2564)

There's already an implicit conversion for radian_t, but there's no
implicit conversion from degree_t to radian_t.
This commit is contained in:
Tyler Veness
2020-07-03 21:58:19 -07:00
committed by GitHub
parent 6e4ee8da2b
commit a3881bb452
2 changed files with 13 additions and 1 deletions

View File

@@ -19,6 +19,11 @@ Rotation2d::Rotation2d(units::radian_t value)
m_cos(units::math::cos(value)),
m_sin(units::math::sin(value)) {}
Rotation2d::Rotation2d(units::degree_t value)
: m_value(value),
m_cos(units::math::cos(value)),
m_sin(units::math::sin(value)) {}
Rotation2d::Rotation2d(double x, double y) {
const auto magnitude = std::hypot(x, y);
if (magnitude > 1e-6) {

View File

@@ -33,6 +33,13 @@ class Rotation2d {
*/
Rotation2d(units::radian_t value); // NOLINT(runtime/explicit)
/**
* Constructs a Rotation2d with the given degree value.
*
* @param value The value of the angle in degrees.
*/
Rotation2d(units::degree_t value); // NOLINT(runtime/explicit)
/**
* Constructs a Rotation2d with the given x and y (cosine and sine)
* components. The x and y don't have to be normalized.
@@ -174,7 +181,7 @@ class Rotation2d {
double Tan() const { return m_sin / m_cos; }
private:
units::radian_t m_value = 0_deg;
units::radian_t m_value = 0_rad;
double m_cos = 1;
double m_sin = 0;
};