mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41: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:
@@ -93,3 +93,21 @@ TEST(Translation2dTest, PolarConstructor) {
|
||||
EXPECT_DOUBLE_EQ(1.0, two.X().value());
|
||||
EXPECT_DOUBLE_EQ(std::sqrt(3.0), two.Y().value());
|
||||
}
|
||||
|
||||
TEST(Translation2dTest, Constexpr) {
|
||||
constexpr Translation2d defaultCtor;
|
||||
constexpr Translation2d componentCtor{1_m, 2_m};
|
||||
constexpr auto added = defaultCtor + componentCtor;
|
||||
constexpr auto subtracted = defaultCtor - componentCtor;
|
||||
constexpr auto negated = -componentCtor;
|
||||
constexpr auto multiplied = componentCtor * 2;
|
||||
constexpr auto divided = componentCtor / 2;
|
||||
|
||||
static_assert(defaultCtor.X() == 0_m);
|
||||
static_assert(componentCtor.Y() == 2_m);
|
||||
static_assert(added.X() == 1_m);
|
||||
static_assert(subtracted.Y() == (-2_m));
|
||||
static_assert(negated.X() == (-1_m));
|
||||
static_assert(multiplied.X() == 2_m);
|
||||
static_assert(divided.Y() == 1_m);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user