sculpto
angle_measure.h
Go to the documentation of this file.
1/*!****************************************************************//*!*
2 * \file angle_measure.h
3 * \brief Angle measures types implementatino module.
4 *
5 * \author Sabitov Kirill
6 * \date 19 June 2022
7 *********************************************************************/
8
9#pragma once
10
11#include "math_common.h"
12
13namespace scl::math
14{
16 template <typename T> struct radians;
17 template <typename T> struct degrees;
18
20 template <typename T>
21 struct radians
22 {
23 public:
24 T Value { 0 };
27 radians() = default;
28
29 /*!*
30 * Radians angle constructor by value.
31 *
32 * \param Value - angle value.
33 */
35
36 /*!*
37 * Radians copy constructor.
38 *
39 * \param Other
40 * \return
41 */
42 const radians &operator=(const radians &Other) {
43 if (this != &Other) Value = Other.Value;
44 return *this;
45 }
46
47 /*!*
48 * Radians angle compare function.
49 *
50 * \param Other - radians angle to compare with.
51 * \return is radians degrees equal flag.
52 */
53 bool operator==(const radians &Other)
54 {
55 return Value == Other.Value;
56 }
57
58 /*!*
59 * Getting negative radians angle operation.
60 *
61 * \param None.
62 * \return negative radians angle.
63 */
64 const radians operator-() const
65 {
66 return radians(-Value);
67 }
68
69 /*!*
70 * Radians degrees addition operator overloading.
71 *
72 * \param Other - radians angle to add.
73 * \return radians angle with added coordinates.
74 */
75 const radians operator+(const radians &Other) const
76 {
77 return radians(Value + Other.Value);
78 }
79
80 /*!*
81 * Radians degrees addition with assigments operator overlaoding.
82 *
83 * \param Other - radians angle to add.
84 * \return self reference
85 */
86 const radians &operator+=(const radians &Other)
87 {
88 Value += Other.Value;
89 return *this;
90 }
91
92 /*!*
93 * Radians degrees subtraction operator overloading.
94 *
95 * \param Other - radians angle to subtract.
96 * \return radians angle with subtract coordinates.
97 */
98 const radians operator-(const radians &Other) const
99 {
100 return radians(Value - Other.Value);
101 }
102
103 /*!*
104 * Radians degrees subtraction with assigments operator overlaoding.
105 *
106 * \param Other - radians angle to subtract.
107 * \return self reference.
108 */
109 const radians &operator-=(const radians &Other)
110 {
111 Value -= Other.Value;
112 return *this;
113 }
114
115 /*!*
116 * Radians degrees multiplying operator overloading.
117 *
118 * \param Other - radians angle to multiply.
119 * \return radians angle with multiplied coordinates.
120 */
121 const radians operator*(const radians &Other) const
122 {
123 return radians(Value * Other.Value);
124 }
125
126 /*!*
127 * Radians degrees multiplying with assigments operator overlaoding.
128 *
129 * \param Other - radians angle to multiply.
130 * \return self reference.
131 */
132 const radians &operator*=(const radians &Other)
133 {
134 Value *= Other.Value;
135 return *this;
136 }
137
138 /*!*
139 * Radians degrees dividing operator overloading.
140 *
141 * \param Other - radians angle to devide.
142 * \return radians angle with devided coordinates.
143 */
144 const radians operator/(const radians &Other) const
145 {
146 return radians(Value / Other.Value);
147 }
148
149 /*!*
150 * Radians degrees dividing with assigments operator overlaoding.
151 *
152 * \param Other - radians angle to devide.
153 * \return self reference.
154 */
155 const radians &operator/=(const radians &Other)
156 {
157 Value /= Other.Value;
158 return *this;
159 }
160
161 /*!*
162 * СCast to degree measure from radians to degrees.
163 *
164 * \return angle in degrees.
165 */
166 operator degrees<T>() { return degrees<T>(Value * 180.0 / PI); }
167
168 /*!*
169 * Cast to scalar type.
170 *
171 * \return angle value.
172 */
173 operator T() { return Value; }
174 };
175
177 template <typename T>
178 struct degrees
179 {
180 public:
181 T Value { 0 };
184 degrees() = default;
185
186 /*!*
187 * Degrees angle constructor by value.
188 *
189 * \param Value - angle value.
190 */
192
193 /*!*
194 * Degrees copy constructor.
195 *
196 * \param Other
197 * \return
198 */
199 const degrees &operator=(const degrees &Other) {
200 if (this != &Other) Value = Other.Value;
201 return *this;
202 }
203
204 /*!*
205 * Degrees angle compare function.
206 *
207 * \param Other - degrees angle to compare with.
208 * \return is degrees degrees equal flag.
209 */
210 bool operator==(const degrees &Other)
211 {
212 return Value == Other.Value;
213 }
214
215 /*!*
216 * Getting negative degrees angle operation.
217 *
218 * \param None.
219 * \return negative degrees angle.
220 */
221 const degrees operator-() const
222 {
223 return degrees(-Value);
224 }
225
226 /*!*
227 * Degrees degrees addition operator overloading.
228 *
229 * \param Other - degrees angle to add.
230 * \return degrees angle with added coordinates.
231 */
232 const degrees operator+(const degrees &Other) const
233 {
234 return degrees(Value + Other.Value);
235 }
236
237 /*!*
238 * Degrees degrees addition with assigments operator overlaoding.
239 *
240 * \param Other - degrees angle to add.
241 * \return self reference
242 */
243 const degrees &operator+=(const degrees &Other)
244 {
245 Value += Other.Value;
246 return *this;
247 }
248
249 /*!*
250 * Degrees degrees subtraction operator overloading.
251 *
252 * \param Other - degrees angle to subtract.
253 * \return degrees angle with subtract coordinates.
254 */
255 const degrees operator-(const degrees &Other) const
256 {
257 return degrees(Value - Other.Value);
258 }
259
260 /*!*
261 * Degrees degrees subtraction with assigments operator overlaoding.
262 *
263 * \param Other - degrees angle to subtract.
264 * \return self reference.
265 */
266 const degrees &operator-=(const degrees &Other)
267 {
268 Value -= Other.Value;
269 return *this;
270 }
271
272 /*!*
273 * Degrees degrees multiplying operator overloading.
274 *
275 * \param Other - degrees angle to multiply.
276 * \return degrees angle with multiplied coordinates.
277 */
278 const degrees operator*(const degrees &Other) const
279 {
280 return degrees(Value * Other.Value);
281 }
282
283 /*!*
284 * Degrees degrees multiplying with assigments operator overlaoding.
285 *
286 * \param Other - degrees angle to multiply.
287 * \return self reference.
288 */
289 const degrees &operator*=(const degrees &Other)
290 {
291 Value *= Other.Value;
292 return *this;
293 }
294
295 /*!*
296 * Degrees degrees dividing operator overloading.
297 *
298 * \param Other - degrees angle to devide.
299 * \return degrees angle with devided coordinates.
300 */
301 const degrees operator/(const degrees &Other) const
302 {
303 return degrees(Value / Other.Value);
304 }
305
306 /*!*
307 * Degrees degrees dividing with assigments operator overlaoding.
308 *
309 * \param Other - degrees angle to devide.
310 * \return self reference.
311 */
312 const degrees &operator/=(const degrees &Other)
313 {
314 Value /= Other.Value;
315 return *this;
316 }
317
318 /*!*
319 * Cast to degree measure from degrees to degrees.
320 *
321 * \return angle in degrees.
322 */
323 operator radians<T>() { return radians<T>(Value * PI / 180); }
324
325 /*!*
326 * Cast to scalar type.
327 *
328 * \return angle value.
329 */
330 operator T() { return Value; }
331 };
332}
const float PI
Definition: math_common.h:33
math::radians< float > radians
Definition: base.h:36
math::degrees< float > degrees
Definition: base.h:35
const degrees operator/(const degrees &Other) const
const degrees operator-(const degrees &Other) const
const degrees operator+(const degrees &Other) const
const degrees operator*(const degrees &Other) const
bool operator==(const degrees &Other)
const degrees & operator*=(const degrees &Other)
const degrees & operator-=(const degrees &Other)
const degrees operator-() const
const degrees & operator=(const degrees &Other)
const degrees & operator/=(const degrees &Other)
const degrees & operator+=(const degrees &Other)
const radians & operator*=(const radians &Other)
const radians & operator/=(const radians &Other)
const radians operator/(const radians &Other) const
const radians & operator-=(const radians &Other)
const radians & operator=(const radians &Other)
Definition: angle_measure.h:42
bool operator==(const radians &Other)
Definition: angle_measure.h:53
const radians operator+(const radians &Other) const
Definition: angle_measure.h:75
const radians operator-() const
Definition: angle_measure.h:64
const radians operator-(const radians &Other) const
Definition: angle_measure.h:98
const radians & operator+=(const radians &Other)
Definition: angle_measure.h:86
const radians operator*(const radians &Other) const