From 1e7a5485ad4823bb7675e8be6cff54f0bb5261cc Mon Sep 17 00:00:00 2001 From: Liam Teale Date: Thu, 2 Jan 2025 15:30:15 -0800 Subject: [PATCH] add AngleDistance --- include/units/Angle.hpp | 23 +++++++++++++++++++++++ src/main.cpp | 10 ++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/include/units/Angle.hpp b/include/units/Angle.hpp index 02f4b20..0675634 100644 --- a/include/units/Angle.hpp +++ b/include/units/Angle.hpp @@ -68,6 +68,29 @@ class CAngle { constexpr CAngle(double value) : value(value) {} }; +/** + * @brief Angle Distance class + * + * yet another helper class to manage the compass angle fiasco (it's getting nuked on May 15 2025) + * + * consider the following: + * Angle exitRange1 = 0_cDeg; + * Angle exitRange2 = 0_stDeg; + * + * It is expected that exitRange1 and exitRange2 is equal to each other. + * However, this is not the case. 0_cDeg gets converted to 90_stDeg + * implicitly. So, yet another helper class is necessary (hooray) + * + */ +class AngleDistance : public Angle { + public: + explicit constexpr AngleDistance(double value) : Angle(fabs(value)) {} + + constexpr AngleDistance(Angle value) : Angle(units::abs(value)) {} + + constexpr AngleDistance(CAngle value) : Angle(units::abs(Angle(value) - Angle(M_PI_2))) {} +}; + constexpr bool operator==(Angle lhs, CAngle rhs) { return lhs == Angle(rhs); } constexpr Angle rad = Angle(1.0); diff --git a/src/main.cpp b/src/main.cpp index 3d237b5..4733e56 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -45,7 +45,7 @@ void initialize() { units::Vector2D v2e = units::V2Position(2_in, 2_in) / 2_in; } -void angleTests() { +constexpr void angleTests() { static_assert(+15_cDeg == 75_stDeg); static_assert(to_stDeg(-+15_cDeg) == to_stDeg(105_stDeg)); static_assert(r2i(to_stDeg(30_cDeg)) == r2i(to_stDeg(60_stDeg))); @@ -53,6 +53,13 @@ void angleTests() { Angle a = 2_cDeg; } +constexpr void angleDistanceTests() { + // static_assert(r2i(to_stDeg(AngleDistance(-15_cDeg))) == r2i(to_stDeg(AngleDistance(+15_stDeg)))); + Angle a = 2_stDeg + AngleDistance(15_stDeg); + Angle b = AngleDistance(15_stDeg) + 2_stDeg; + Angle c = 2_stDeg + AngleDistance(15_cDeg); +} + constexpr Number numAssignmentTests() { Number n = 1_num; // 1 n += 2; // 3 @@ -73,7 +80,6 @@ constexpr double doubleAssignmentTests() { return d; } - void numberOperatorTests() { static_assert(1_num + 2 == 3); static_assert(1 + 2_num <= 3);