mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
[wpimath] Fix Rotation2d equality operator (#3128)
This commit is contained in:
@@ -14,19 +14,19 @@ using namespace frc;
|
||||
static constexpr double kEpsilon = 1E-9;
|
||||
|
||||
TEST(Rotation2dTest, RadiansToDegrees) {
|
||||
const Rotation2d one{units::radian_t(wpi::math::pi / 3)};
|
||||
const Rotation2d two{units::radian_t(wpi::math::pi / 4)};
|
||||
const Rotation2d rot1{units::radian_t(wpi::math::pi / 3)};
|
||||
const Rotation2d rot2{units::radian_t(wpi::math::pi / 4)};
|
||||
|
||||
EXPECT_NEAR(one.Degrees().to<double>(), 60.0, kEpsilon);
|
||||
EXPECT_NEAR(two.Degrees().to<double>(), 45.0, kEpsilon);
|
||||
EXPECT_NEAR(rot1.Degrees().to<double>(), 60.0, kEpsilon);
|
||||
EXPECT_NEAR(rot2.Degrees().to<double>(), 45.0, kEpsilon);
|
||||
}
|
||||
|
||||
TEST(Rotation2dTest, DegreesToRadians) {
|
||||
const auto one = Rotation2d(45.0_deg);
|
||||
const auto two = Rotation2d(30.0_deg);
|
||||
const auto rot1 = Rotation2d(45.0_deg);
|
||||
const auto rot2 = Rotation2d(30.0_deg);
|
||||
|
||||
EXPECT_NEAR(one.Radians().to<double>(), wpi::math::pi / 4.0, kEpsilon);
|
||||
EXPECT_NEAR(two.Radians().to<double>(), wpi::math::pi / 6.0, kEpsilon);
|
||||
EXPECT_NEAR(rot1.Radians().to<double>(), wpi::math::pi / 4.0, kEpsilon);
|
||||
EXPECT_NEAR(rot2.Radians().to<double>(), wpi::math::pi / 6.0, kEpsilon);
|
||||
}
|
||||
|
||||
TEST(Rotation2dTest, RotateByFromZero) {
|
||||
@@ -45,20 +45,24 @@ TEST(Rotation2dTest, RotateByNonZero) {
|
||||
}
|
||||
|
||||
TEST(Rotation2dTest, Minus) {
|
||||
const auto one = Rotation2d(70.0_deg);
|
||||
const auto two = Rotation2d(30.0_deg);
|
||||
const auto rot1 = Rotation2d(70.0_deg);
|
||||
const auto rot2 = Rotation2d(30.0_deg);
|
||||
|
||||
EXPECT_NEAR((one - two).Degrees().to<double>(), 40.0, kEpsilon);
|
||||
EXPECT_NEAR((rot1 - rot2).Degrees().to<double>(), 40.0, kEpsilon);
|
||||
}
|
||||
|
||||
TEST(Rotation2dTest, Equality) {
|
||||
const auto one = Rotation2d(43_deg);
|
||||
const auto two = Rotation2d(43_deg);
|
||||
EXPECT_TRUE(one == two);
|
||||
const auto rot1 = Rotation2d(43_deg);
|
||||
const auto rot2 = Rotation2d(43_deg);
|
||||
EXPECT_EQ(rot1, rot2);
|
||||
|
||||
const auto rot3 = Rotation2d(-180_deg);
|
||||
const auto rot4 = Rotation2d(180_deg);
|
||||
EXPECT_EQ(rot3, rot4);
|
||||
}
|
||||
|
||||
TEST(Rotation2dTest, Inequality) {
|
||||
const auto one = Rotation2d(43_deg);
|
||||
const auto two = Rotation2d(43.5_deg);
|
||||
EXPECT_TRUE(one != two);
|
||||
const auto rot1 = Rotation2d(43_deg);
|
||||
const auto rot2 = Rotation2d(43.5_deg);
|
||||
EXPECT_NE(rot1, rot2);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user