ActiveLib
Loading...
Searching...
No Matches
AngleUnit.h
1
6#ifndef ACTIVE_MEASURE_ANGLE_UNIT
7#define ACTIVE_MEASURE_ANGLE_UNIT
8
9#include "Active/Setting/Values/Measurement/Units/Unit.h"
10
11namespace active::measure {
12
13 // MARK: - Types
14
16 enum class AngleType : char {
17 radian,
18 degree,
19 minute,
20 second,
21 gradian,
22 };
23
24 // MARK: - Constructors
25
29 struct AngleUnit : public Unit<AngleUnit, AngleType> {
30
31 // MARK: - Types
32
33 using Type = AngleType;
34
35 using enum AngleType;
36
37 // MARK: - Static functions
38
39 //Get unit for radians
40 static AngleUnit radians(uint8_t prec = 4, bool suffixes = true) { return AngleUnit{radian, prec, true, suffixes}; }
41 //Get unit for decimal degrees
42 static AngleUnit degreesDec(uint8_t prec = 4, bool suffixes = true) { return AngleUnit{degree, prec, true, suffixes}; }
43 //Get unit for whole degrees
44 static AngleUnit degrees(bool suffixes = true) { return AngleUnit{degree, 0, true, suffixes}; }
45 //Get unit for whole degrees & minutes
46 static AngleUnit degreesMinutes() { return AngleUnit{degree, minute, 0}; }
47 //Get unit for whole degrees, minutes & seconds
48 static AngleUnit degreesMinutesSeconds() { return AngleUnit{degree, minute, second, 0}; }
49 //Get unit for surveyor bearings
50 static AngleUnit surveyorBearings() {
51 AngleUnit result{AngleUnit{degree, minute, second, 0, true}};
52 result.isSurveyBearing = true;
53 return result;
54 }
55
56 // MARK: - Constructors
57
61 AngleUnit() : Unit{radian} {} //Default to metres - can be overridden as required
69 explicit AngleUnit(AngleType type, uint8_t prec, bool isDecimal = true, bool suffixes = true) :
70 Unit{type, prec, isDecimal, suffixes} {}
78 explicit AngleUnit(AngleType first, AngleType second, uint8_t prec, bool isDecimal = true) :
79 Unit{first, second, prec, isDecimal} {}
88 explicit AngleUnit(AngleType first, AngleType second, AngleType third, uint8_t prec, bool isDecimal = true) :
89 Unit{first, second, third, prec, isDecimal} {}
90
91 // MARK: - Variables
92
94 bool isSurveyBearing = false;
96 bool isClockwisePositive = false;
98 double zeroOffset = 0.0;
99
100 // MARK: - Functions (const)
101
106 bool isConventionalAngle() const { return !isSurveyBearing && !isClockwisePositive && math::isZero(zeroOffset); }
107
108
109 private:
110#ifdef WINDOWS
111 friend typename Unit;
112#else
113 friend struct Unit;
114#endif
115
116 // MARK: Unit constants
117
119 constexpr static int lengthCount = static_cast<int>(gradian) + 1;
120
121 static std::array<const char*, lengthCount> tags;
122 static std::array<const char*, lengthCount> abbreviations;
123 static std::array<double, lengthCount> conversions;
124 static std::array<bool, lengthCount> metric;
125 };
126
127}
128
129#endif //ACTIVE_MEASURE_ANGLE_UNIT
Definition AngleUnit.cpp:14
AngleType
Enumeration of known angle measurement units.
Definition AngleUnit.h:16
Definition AngleUnit.h:29
double zeroOffset
Offset to 0° (from the positive x axis)) e.g. zeroOffset = pi / 2 if 0° points North....
Definition AngleUnit.h:98
AngleUnit(AngleType first, AngleType second, AngleType third, uint8_t prec, bool isDecimal=true)
Definition AngleUnit.h:88
bool isClockwisePositive
True if s clockwise sweep angle is positive. Ignored when isSurveyBearing = true.
Definition AngleUnit.h:96
AngleUnit()
Definition AngleUnit.h:61
bool isConventionalAngle() const
Definition AngleUnit.h:106
AngleUnit(AngleType first, AngleType second, uint8_t prec, bool isDecimal=true)
Definition AngleUnit.h:78
bool isSurveyBearing
True if convention for survey bearings is used, e.g. N 25° W.
Definition AngleUnit.h:94
AngleUnit(AngleType type, uint8_t prec, bool isDecimal=true, bool suffixes=true)
Definition AngleUnit.h:69
Definition Unit.h:35
bool isDecimal() const
Definition Unit.h:102