[wpimath] Add 3D geometry classes (#4175)

Also clean up 2D geometry documentation.
This commit is contained in:
Tyler Veness
2022-05-06 08:41:23 -07:00
committed by GitHub
parent 708a4bc3bc
commit f20a20f3f1
48 changed files with 4299 additions and 255 deletions

View File

@@ -11,58 +11,56 @@
using namespace frc;
static constexpr double kEpsilon = 1E-9;
TEST(Rotation2dTest, RadiansToDegrees) {
const Rotation2d rot1{units::radian_t(wpi::numbers::pi / 3)};
const Rotation2d rot2{units::radian_t(wpi::numbers::pi / 4)};
const Rotation2d rot1{units::radian_t{wpi::numbers::pi / 3.0}};
const Rotation2d rot2{units::radian_t{wpi::numbers::pi / 4.0}};
EXPECT_NEAR(rot1.Degrees().value(), 60.0, kEpsilon);
EXPECT_NEAR(rot2.Degrees().value(), 45.0, kEpsilon);
EXPECT_DOUBLE_EQ(60.0, rot1.Degrees().value());
EXPECT_DOUBLE_EQ(45.0, rot2.Degrees().value());
}
TEST(Rotation2dTest, DegreesToRadians) {
const auto rot1 = Rotation2d(45.0_deg);
const auto rot2 = Rotation2d(30.0_deg);
const auto rot1 = Rotation2d{45_deg};
const auto rot2 = Rotation2d{30_deg};
EXPECT_NEAR(rot1.Radians().value(), wpi::numbers::pi / 4.0, kEpsilon);
EXPECT_NEAR(rot2.Radians().value(), wpi::numbers::pi / 6.0, kEpsilon);
EXPECT_DOUBLE_EQ(wpi::numbers::pi / 4.0, rot1.Radians().value());
EXPECT_DOUBLE_EQ(wpi::numbers::pi / 6.0, rot2.Radians().value());
}
TEST(Rotation2dTest, RotateByFromZero) {
const Rotation2d zero;
auto sum = zero + Rotation2d(90.0_deg);
auto rotated = zero + Rotation2d(90_deg);
EXPECT_NEAR(sum.Radians().value(), wpi::numbers::pi / 2.0, kEpsilon);
EXPECT_NEAR(sum.Degrees().value(), 90.0, kEpsilon);
EXPECT_DOUBLE_EQ(wpi::numbers::pi / 2.0, rotated.Radians().value());
EXPECT_DOUBLE_EQ(90.0, rotated.Degrees().value());
}
TEST(Rotation2dTest, RotateByNonZero) {
auto rot = Rotation2d(90.0_deg);
rot = rot + Rotation2d(30.0_deg);
auto rot = Rotation2d{90_deg};
rot = rot + Rotation2d{30_deg};
EXPECT_NEAR(rot.Degrees().value(), 120.0, kEpsilon);
EXPECT_DOUBLE_EQ(120.0, rot.Degrees().value());
}
TEST(Rotation2dTest, Minus) {
const auto rot1 = Rotation2d(70.0_deg);
const auto rot2 = Rotation2d(30.0_deg);
const auto rot1 = Rotation2d{70_deg};
const auto rot2 = Rotation2d{30_deg};
EXPECT_NEAR((rot1 - rot2).Degrees().value(), 40.0, kEpsilon);
EXPECT_DOUBLE_EQ(40.0, (rot1 - rot2).Degrees().value());
}
TEST(Rotation2dTest, Equality) {
const auto rot1 = Rotation2d(43_deg);
const auto rot2 = Rotation2d(43_deg);
auto rot1 = Rotation2d{43_deg};
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);
rot1 = Rotation2d{-180_deg};
rot2 = Rotation2d{180_deg};
EXPECT_EQ(rot1, rot2);
}
TEST(Rotation2dTest, Inequality) {
const auto rot1 = Rotation2d(43_deg);
const auto rot2 = Rotation2d(43.5_deg);
const auto rot1 = Rotation2d{43_deg};
const auto rot2 = Rotation2d{43.5_deg};
EXPECT_NE(rot1, rot2);
}