Skip to content

Commit ec18dd0

Browse files
authored
Merge pull request #35 from LemLib/feat/AngleDistance
✨ AngleRange class
2 parents f1a5e62 + 9c549f6 commit ec18dd0

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ IS_LIBRARY:=1
2929
# Be sure that your header files are in the include directory inside of a folder with the
3030
# same name as what you set LIBNAME to below.
3131
LIBNAME:=units
32-
VERSION:=0.4.1
32+
VERSION:=0.4.2
3333
# EXCLUDE_SRC_FROM_LIB= $(SRCDIR)/unpublishedfile.c
3434
# this line excludes opcontrol.c and similar files
3535
EXCLUDE_SRC_FROM_LIB+=$(foreach file, $(SRCDIR)/main,$(foreach cext,$(CEXTS),$(file).$(cext)) $(foreach cxxext,$(CXXEXTS),$(file).$(cxxext)))

include/units/Angle.hpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,29 @@ class CAngle {
6868
constexpr CAngle(double value) : value(value) {}
6969
};
7070

71+
/**
72+
* @brief Angle Distance class
73+
*
74+
* yet another helper class to manage the compass angle fiasco (it's getting nuked on May 15 2025)
75+
*
76+
* consider the following:
77+
* Angle exitRange1 = 0_cDeg;
78+
* Angle exitRange2 = 0_stDeg;
79+
*
80+
* It is expected that exitRange1 and exitRange2 is equal to each other.
81+
* However, this is not the case. 0_cDeg gets converted to 90_stDeg
82+
* implicitly. So, yet another helper class is necessary (hooray)
83+
*
84+
*/
85+
class AngleRange : public Angle {
86+
public:
87+
explicit constexpr AngleRange(double value) : Angle(fabs(value)) {}
88+
89+
constexpr AngleRange(Angle value) : Angle(units::abs(value)) {}
90+
91+
constexpr AngleRange(CAngle value) : Angle(units::abs(Angle(value) - Angle(M_PI_2))) {}
92+
};
93+
7194
constexpr bool operator==(Angle lhs, CAngle rhs) { return lhs == Angle(rhs); }
7295

7396
constexpr Angle rad = Angle(1.0);

src/main.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,21 @@ void initialize() {
4545
units::Vector2D<Number> v2e = units::V2Position(2_in, 2_in) / 2_in;
4646
}
4747

48-
void angleTests() {
48+
constexpr void angleTests() {
4949
static_assert(+15_cDeg == 75_stDeg);
5050
static_assert(to_stDeg(-+15_cDeg) == to_stDeg(105_stDeg));
5151
static_assert(r2i(to_stDeg(30_cDeg)) == r2i(to_stDeg(60_stDeg)));
5252
static_assert(r2i(to_stDeg(+0_cDeg)) == r2i(to_stDeg(90_stDeg)));
5353
Angle a = 2_cDeg;
5454
}
5555

56+
constexpr void angleRangeTests() {
57+
static_assert(r2i(to_stDeg(AngleRange(-15_cDeg))) == r2i(to_stDeg(AngleRange(+15_stDeg))));
58+
Angle a = 2_stDeg + AngleRange(15_stDeg);
59+
Angle b = AngleRange(15_stDeg) + 2_stDeg;
60+
Angle c = 2_stDeg + AngleRange(15_cDeg);
61+
}
62+
5663
constexpr Number numAssignmentTests() {
5764
Number n = 1_num; // 1
5865
n += 2; // 3
@@ -73,7 +80,6 @@ constexpr double doubleAssignmentTests() {
7380
return d;
7481
}
7582

76-
7783
void numberOperatorTests() {
7884
static_assert(1_num + 2 == 3);
7985
static_assert(1 + 2_num <= 3);

0 commit comments

Comments
 (0)