gramods
Loading...
Searching...
No Matches
io_angle.hh
1
2#ifndef GRAMODS_CORE_ANGLE
3#define GRAMODS_CORE_ANGLE
4
5#include <gmCore/config.hh>
6#include <gmCore/MathConstants.hh>
7
8#include <array>
9#include <iostream>
10
11BEGIN_NAMESPACE_GMCORE;
12
20struct angle {
21
22public:
23
24 angle() {}
25
26 angle(float v)
27 : value(v) {}
28
30 void deg(float v) { value = v * from_degrees; }
31
33 float deg() { return value * to_degrees; }
34
36 void rad(float v) { value = v; }
37
39 float rad() { return value; }
40
42 void operator =(float v) { value = v; }
43
45 operator float() { return value; }
46
48 float value;
49
51 static constexpr float from_degrees = (float)(GM_PI / 180.0);
52
54 static constexpr float to_degrees = (float)(180.f / GM_PI);
55
56};
57
59typedef std::array<angle, 2> angle2;
60
62typedef std::array<angle, 3> angle3;
63
65typedef std::array<angle, 4> angle4;
66
67END_NAMESPACE_GMCORE;
68
69BEGIN_NAMESPACE_GRAMODS;
70
79std::istream& operator>> (std::istream &in, gmCore::angle &v);
80
82inline std::istream& operator>> (std::istream &in, gramods::gmCore::angle2 &s) {
83 in >> s[0] >> s[1];
84 return in;
85}
86
88inline std::istream& operator>> (std::istream &in, gramods::gmCore::angle3 &s) {
89 in >> s[0] >> s[1] >> s[2];
90 return in;
91}
92
94inline std::istream& operator>> (std::istream &in, gramods::gmCore::angle4 &s) {
95 in >> s[0] >> s[1] >> s[2] >> s[3];
96 return in;
97}
98
100inline std::ostream& operator<< (std::ostream &out, gramods::gmCore::angle2 &s) {
101 out << s[0] << " " << s[1];
102 return out;
103}
104
106inline std::ostream& operator<< (std::ostream &out, gramods::gmCore::angle3 &s) {
107 out << s[0] << " " << s[1] << " " << s[2];
108 return out;
109}
110
112inline std::ostream& operator<< (std::ostream &out, gramods::gmCore::angle4 &s) {
113 out << s[0] << " " << s[1] << " " << s[2] << " " << s[3];
114 return out;
115}
116
117END_NAMESPACE_GRAMODS;
118
119#endif
std::array< angle, 2 > angle2
Array of 2 angle.
Definition io_angle.hh:59
std::array< angle, 4 > angle4
Array of 4 angle.
Definition io_angle.hh:65
std::array< angle, 3 > angle3
Array of 3 angle.
Definition io_angle.hh:62
A simple placeholder for angle values expressed in radians.
Definition io_angle.hh:20
float deg()
The angle, in degrees.
Definition io_angle.hh:33
void deg(float v)
Set the angle, in degrees.
Definition io_angle.hh:30
float value
The angle in radians.
Definition io_angle.hh:48
float rad()
The angle, in radians.
Definition io_angle.hh:39
void rad(float v)
Set the angle, in radians.
Definition io_angle.hh:36