[wpimath] Constrain Rotation2d range to -pi to pi (#4611)

Co-authored-by: Ryan Blue <ryanzblue@gmail.com>
This commit is contained in:
ohowe
2022-11-14 15:25:15 -07:00
committed by GitHub
parent f656e99245
commit d1d458db2b
7 changed files with 69 additions and 43 deletions

View File

@@ -10,6 +10,16 @@
using namespace frc;
TEST(Rotation2dTest, InScope) {
const auto rot1 = Rotation2d{units::radian_t{std::numbers::pi * 5 / 2}};
const auto rot2 = Rotation2d{units::radian_t{std::numbers::pi * 7 / 2}};
const auto rot3 = Rotation2d{270_deg};
EXPECT_DOUBLE_EQ(std::numbers::pi / 2, rot1.Radians().value());
EXPECT_DOUBLE_EQ(-std::numbers::pi / 2, rot2.Radians().value());
EXPECT_DOUBLE_EQ(-90, rot3.Degrees().value());
}
TEST(Rotation2dTest, RadiansToDegrees) {
const Rotation2d rot1{units::radian_t{std::numbers::pi / 3.0}};
const Rotation2d rot2{units::radian_t{std::numbers::pi / 4.0}};
@@ -66,8 +76,8 @@ TEST(Rotation2dTest, Inequality) {
TEST(Rotation2dTest, Constexpr) {
constexpr Rotation2d defaultCtor;
constexpr Rotation2d radianCtor{5_rad};
constexpr Rotation2d degreeCtor{270_deg};
constexpr Rotation2d radianCtor{0.25_rad};
constexpr Rotation2d degreeCtor{-90_deg};
constexpr Rotation2d rotation45{45_deg};
constexpr Rotation2d cartesianCtor{3.5, -3.5};
@@ -76,9 +86,9 @@ TEST(Rotation2dTest, Constexpr) {
constexpr auto subtracted = cartesianCtor - degreeCtor;
static_assert(defaultCtor.Radians() == 0_rad);
static_assert(degreeCtor.Degrees() == 270_deg);
static_assert(negated.Radians() == (-5_rad));
static_assert(multiplied.Radians() == 10_rad);
static_assert(degreeCtor.Degrees() == -90_deg);
static_assert(negated.Radians() == -0.25_rad);
static_assert(multiplied.Radians() == 0.5_rad);
static_assert(subtracted == rotation45);
static_assert(radianCtor != degreeCtor);
}