mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
[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:
@@ -63,3 +63,22 @@ TEST(Rotation2dTest, Inequality) {
|
||||
const auto rot2 = Rotation2d{43.5_deg};
|
||||
EXPECT_NE(rot1, rot2);
|
||||
}
|
||||
|
||||
TEST(Rotation2dTest, Constexpr) {
|
||||
constexpr Rotation2d defaultCtor;
|
||||
constexpr Rotation2d radianCtor{5_rad};
|
||||
constexpr Rotation2d degreeCtor{270_deg};
|
||||
constexpr Rotation2d rotation45{45_deg};
|
||||
constexpr Rotation2d cartesianCtor{3.5, -3.5};
|
||||
|
||||
constexpr auto negated = -radianCtor;
|
||||
constexpr auto multiplied = radianCtor * 2;
|
||||
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(subtracted == rotation45);
|
||||
static_assert(radianCtor != degreeCtor);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user