1 #ifndef MSP_GEOMETRY_ANGLE_H_
2 #define MSP_GEOMETRY_ANGLE_H_
10 A planar angle. Creating an Angle from a raw value or extracting it requires
11 specifying whether degrees or radians are used. This eliminates a common
23 Angle(const Angle<U> &);
25 static Angle from_degrees(T);
26 static Angle from_radians(T);
29 static Angle quarter_circle();
30 static Angle straight();
31 static Angle half_circle();
32 static Angle full_circle();
37 Angle &operator+=(const Angle &);
38 Angle &operator-=(const Angle &);
44 inline Angle<T>::Angle(T v):
50 inline Angle<T>::Angle(const Angle<U> &other):
55 inline Angle<T> Angle<T>::from_degrees(T d)
57 return Angle<T>(d*M_PI/180);
61 inline Angle<T> Angle<T>::from_radians(T r)
67 inline Angle<T> Angle<T>::right()
69 return from_radians(M_PI/2);
73 inline Angle<T> Angle<T>::quarter_circle()
79 inline Angle<T> Angle<T>::straight()
81 return from_radians(M_PI);
85 inline Angle<T> Angle<T>::half_circle()
91 inline Angle<T> Angle<T>::full_circle()
93 return from_radians(M_PI*2);
97 inline T Angle<T>::degrees() const
99 return value*180/M_PI;
103 inline T Angle<T>::radians() const
109 inline Angle<T> &Angle<T>::operator+=(const Angle &a)
116 inline Angle<T> operator+(const Angle<T> &a1, const Angle<T> &a2)
123 inline Angle<T> &Angle<T>::operator-=(const Angle &a)
130 inline Angle<T> operator-(const Angle<T> &a1, const Angle<T> &a2)
137 inline Angle<T> &Angle<T>::operator*=(T s)
144 inline Angle<T> operator*(const Angle<T> &a, T s)
151 inline Angle<T> operator*(T s, const Angle<T> &a)
157 inline Angle<T> &Angle<T>::operator/=(T s)
164 inline Angle<T> operator/(const Angle<T> &a, T s)
171 inline Angle<T> operator/(T s, const Angle<T> &a)
177 inline T sin(const Angle<T> &angle)
179 return std::sin(angle.radians());
183 inline Angle<T> asin(T s)
185 return Angle<T>::from_radians(std::asin(s));
189 inline T cos(const Angle<T> &angle)
191 return std::cos(angle.radians());
195 inline Angle<T> acos(T s)
197 return Angle<T>::from_radians(std::acos(s));
201 inline T tan(const Angle<T> &angle)
203 return std::tan(angle.radians());
207 inline Angle<T> atan(T s)
209 return Angle<T>::from_radians(std::atan(s));
213 inline Angle<T> atan2(T y, T x)
215 return Angle<T>::from_radians(std::atan2(y, x));
218 } // namespace Geometry