Skip to content

Commit

Permalink
add AngleDistance
Browse files Browse the repository at this point in the history
  • Loading branch information
SizzinSeal committed Jan 2, 2025
1 parent f1a5e62 commit 1e7a548
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
23 changes: 23 additions & 0 deletions include/units/Angle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 8 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,21 @@ void initialize() {
units::Vector2D<Number> 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)));
static_assert(r2i(to_stDeg(+0_cDeg)) == r2i(to_stDeg(90_stDeg)));
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
Expand All @@ -73,7 +80,6 @@ constexpr double doubleAssignmentTests() {
return d;
}


void numberOperatorTests() {
static_assert(1_num + 2 == 3);
static_assert(1 + 2_num <= 3);
Expand Down

0 comments on commit 1e7a548

Please sign in to comment.