Simulant  21.12-1303
A portable game engine for Windows, OSX, Linux, Dreamcast, and PSP
degrees.h
1 #pragma once
2 
3 #if defined(_MSC_VER)
4 #include "radians.h"
5 #endif
6 
7 namespace smlt {
8 
9 #if !defined(_MSC_VER)
10 struct Radians;
11 #endif
12 
13 struct Degrees {
14 private:
15  float value_ = 0.0f;
16 
17 public:
18  Degrees():
19  value_(0) {}
20 
21  explicit Degrees(float value) :
22  value_(value) {}
23 
24  Degrees(const Radians& rhs);
25 
26  float to_float() const {
27  return value_;
28  }
29 
30  Radians to_radians() const;
31 
32  Degrees operator*(float scalar) {
33  return Degrees(to_float() * scalar);
34  }
35 
36  Degrees& operator*=(float scalar) {
37  value_ *= scalar;
38  return *this;
39  }
40 
41  template<typename T>
42  bool operator<(T value) const {
43  return value_ < value;
44  }
45 
46  template<typename T>
47  bool operator<=(T value) const {
48  return value_ <= value;
49  }
50 
51  template<typename T>
52  bool operator>(T value) const {
53  return value_ > value;
54  }
55 
56  template<typename T>
57  bool operator>=(T value) const {
58  return value_ >= value;
59  }
60 
61  bool operator<(const Degrees& d) const {
62  return value_ < d.value_;
63  }
64 
65  bool operator<=(const Degrees& d) const {
66  return value_ <= d.value_;
67  }
68 
69  bool operator>(const Degrees& d) const {
70  return value_ > d.value_;
71  }
72 
73  bool operator>=(const Degrees& d) const {
74  return value_ >= d.value_;
75  }
76 
77  Degrees operator-() const {
78  Degrees ret = *this;
79  ret.value_ = -ret.value_;
80  return ret;
81  }
82 
83  Degrees operator-=(const Degrees& rhs) const {
84  Degrees ret = *this;
85  ret.value_ -= rhs.value_;
86  return ret;
87  }
88 
89  Degrees operator+=(const Degrees& rhs) const {
90  Degrees ret = *this;
91  ret.value_ += rhs.value_;
92  return ret;
93  }
94 
95  bool operator==(const Degrees& rhs) const {
96  return value_ == rhs.value_;
97  }
98 
99  bool operator!=(const Degrees& rhs) const {
100  return !(*this == rhs);
101  }
102 
103  bool is_effectively_equal_to(const Degrees& rhs, float epsilon=0.0f) const {
104  // Returns equal if the values represent basically the same thing (e.g. -90 == 270)
105  float rhs_v = rhs.value_;
106  if(rhs_v < 0) rhs_v += 360.0f;
107 
108  float lhs_v = value_;
109  if(lhs_v < 0) lhs_v += 360.0f;
110 
111  return lhs_v - epsilon < rhs_v && lhs_v + epsilon > rhs_v;
112  }
113 };
114 
115 Degrees lerp_angle(Degrees a, Degrees b, float t);
116 
117 typedef Degrees Deg;
118 }
119 
120 smlt::Degrees operator""_deg(long double v);
smlt::Radians
Definition: radians.h:7
smlt
Definition: animation.cpp:25
smlt::Degrees
Definition: degrees.h:13