mf
Media Framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
angle.h
Go to the documentation of this file.
1 #ifndef MF_ANGLE_H_
2 #define MF_ANGLE_H_
3 
4 #include <iosfwd>
5 #include <cmath>
6 #include "math_constants.h"
7 
8 namespace mf {
9 
11 
12 struct angle {
13 private:
14  float radiants_;
15 
16 public:
17  static angle degrees(float d) { return d * radiant_per_degree; }
18  static angle radiants(float r) { return r; }
19 
20  angle() = default;
21  angle(float r) : radiants_(r) { }
22  angle(const angle&) = default;
23 
24  const float& get_radiants() const { return radiants_; }
25  float get_degrees() const { return radiants_ * degree_per_radiant; }
26  void set_radiants(float r) { radiants_ = r; }
27  void set_degrees(float d) { radiants_ = d * radiant_per_degree; }
28 
29  operator float& () { return radiants_; }
30  operator const float& () const { return radiants_; }
31 
32  angle& operator=(float r) { radiants_ = r; return *this; }
33  angle& operator=(const angle&) = default;
34 
35  bool operator==(angle a) const { return radiants_ == a.radiants_; }
36  bool operator!=(angle a) const { return radiants_ != a.radiants_; }
37 
38  static angle smallest_between(angle a, angle b);
39 };
40 
41 inline angle operator"" _deg(long double deg) {
42  return angle::degrees(deg);
43 }
44 
45 inline angle operator"" _rad(long double rad) {
46  return angle::radiants(rad);
47 }
48 
49 std::ostream& operator<<(std::ostream&, angle);
50 std::istream& operator>>(std::istream&, angle&);
51 
52 }
53 
54 #endif
constexpr real degree_per_radiant
Definition: math_constants.h:15
static angle radiants(float r)
Definition: angle.h:18
angle(float r)
Definition: angle.h:21
constexpr real radiant_per_degree
Definition: math_constants.h:14
bool operator==(angle a) const
Definition: angle.h:35
static angle smallest_between(angle a, angle b)
Definition: angle.cc:20
void set_degrees(float d)
Definition: angle.h:27
const float & get_radiants() const
Definition: angle.h:24
void set_radiants(float r)
Definition: angle.h:26
bool operator!=(angle a) const
Definition: angle.h:36
static angle degrees(float d)
Definition: angle.h:17
angle()=default
std::istream & operator>>(std::istream &str, angle &a)
Definition: angle.cc:13
Angle, represented in radiants.
Definition: angle.h:12
angle & operator=(float r)
Definition: angle.h:32
std::ostream & operator<<(std::ostream &str, const time_span &span)
Definition: common.h:76
float get_degrees() const
Definition: angle.h:25