[wpimath] Increase constexpr support in geometry data types (#4231)

This uses std::is_constant_evaluated() to conditionally use the gcem library for constexpr calculations.
This commit is contained in:
David K Turner
2022-10-31 11:17:00 -05:00
committed by GitHub
parent 1c3c86e9f1
commit 3a5a376465
94 changed files with 6919 additions and 212 deletions

View File

@@ -53,3 +53,22 @@ TEST(Pose2dTest, Minus) {
EXPECT_NEAR(0.0, transform.Y().value(), 1e-9);
EXPECT_DOUBLE_EQ(0.0, transform.Rotation().Degrees().value());
}
TEST(Pose2dTest, Constexpr) {
constexpr Pose2d defaultConstructed;
constexpr Pose2d translationRotation{Translation2d{0_m, 1_m},
Rotation2d{0_deg}};
constexpr Pose2d coordRotation{0_m, 0_m, Rotation2d{45_deg}};
constexpr auto added =
translationRotation + Transform2d{Translation2d{}, Rotation2d{45_deg}};
constexpr auto multiplied = coordRotation * 2;
static_assert(defaultConstructed.X() == 0_m);
static_assert(translationRotation.Y() == 1_m);
static_assert(coordRotation.Rotation().Degrees() == 45_deg);
static_assert(added.X() == 0_m);
static_assert(added.Y() == 1_m);
static_assert(added.Rotation().Degrees() == 45_deg);
static_assert(multiplied.Rotation().Degrees() == 90_deg);
}