RBControl
Library for the RB3201-RBControl board with the ESP32 by RoboticsBrno.
RBControl_angle.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <cmath>
4 
5 #ifndef M_PI
6 #define M_PI 3.14159265358979323846
7 #endif
8 
9 namespace rb {
10 
11 class Angle {
12 public:
13  typedef float _T;
14  static const Angle Pi;
15 
17  : _rads(0) {}
18 
19  static Angle rad(_T r) { return Angle(r); }
20  static Angle deg(_T d) { return Angle(d * _T(M_PI / 180)); }
21  static Angle nan() { return Angle(nanf("")); }
22 
23  bool isNaN() const { return std::isnan(_rads); }
24 
26  _rads += a._rads;
27  return *this;
28  }
30  _rads -= a._rads;
31  return *this;
32  }
33  Angle operator-() const { return Angle(-_rads); }
35  _rads *= c;
36  return *this;
37  }
39  _rads /= c;
40  return *this;
41  }
42 
43  _T deg() const { return _rads * _T(180.0 / M_PI); }
44  _T rad() const { return _rads; }
45 
46 private:
47  _T _rads;
48  Angle(_T r)
49  : _rads(r) {}
50 };
51 
52 Angle operator+(Angle a, Angle b);
53 Angle operator-(Angle a, Angle b);
54 Angle operator*(Angle a, Angle::_T c);
55 Angle operator/(Angle a, Angle::_T c);
56 Angle operator"" _deg(long double d);
57 Angle operator"" _rad(long double r);
58 Angle operator"" _deg(unsigned long long int d);
59 Angle operator"" _rad(unsigned long long int r);
60 
61 }; // namespace rb
#define M_PI
Definition: RBControl_angle.hpp:6
Definition: RBControl_angle.hpp:11
Angle & operator/=(_T c)
Definition: RBControl_angle.hpp:38
bool isNaN() const
Definition: RBControl_angle.hpp:23
_T deg() const
Definition: RBControl_angle.hpp:43
Angle operator-() const
Definition: RBControl_angle.hpp:33
Angle & operator-=(Angle a)
Definition: RBControl_angle.hpp:29
Angle()
Definition: RBControl_angle.hpp:16
Angle & operator*=(_T c)
Definition: RBControl_angle.hpp:34
static const Angle Pi
Definition: RBControl_angle.hpp:14
Angle & operator+=(Angle a)
Definition: RBControl_angle.hpp:25
static Angle nan()
Definition: RBControl_angle.hpp:21
_T rad() const
Definition: RBControl_angle.hpp:44
static Angle rad(_T r)
Definition: RBControl_angle.hpp:19
float _T
Definition: RBControl_angle.hpp:13
static Angle deg(_T d)
Definition: RBControl_angle.hpp:20
The base namespace. Contains some logging functions, too.
Definition: half_duplex_uart.cpp:53
Angle operator*(Angle a, Angle::_T c)
Definition: RBControl_angle.cpp:17
Angle operator-(Angle a, Angle b)
Definition: RBControl_angle.cpp:12
Angle operator/(Angle a, Angle::_T c)
Definition: RBControl_angle.cpp:22
Angle operator+(Angle a, Angle b)
Definition: RBControl_angle.cpp:7