[Tizen] Add codes for Dali Windows Backend
[platform/core/uifw/dali-core.git] / dali / public-api / math / radian.h
1 #ifndef __DALI_RADIAN_H__
2 #define __DALI_RADIAN_H__
3
4 /*
5  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/common/constants.h>
23 #include <dali/public-api/common/dali-common.h>
24 #include <dali/public-api/math/math-utils.h>
25 #include <dali/public-api/math/degree.h>
26
27 namespace Dali
28 {
29 /**
30  * @addtogroup dali_core_math
31  * @{
32  */
33
34 /**
35  * @brief An angle in radians.
36  *
37  * This reduces ambiguity when using methods which accept angles in degrees or radians.
38  * @SINCE_1_0.0
39  */
40 struct Radian
41 {
42   /**
43    * @brief Default constructor, initializes to 0.
44    * @SINCE_1_0.0
45    */
46   Radian()
47   : radian( 0.f )
48   { }
49
50   /**
51    * @brief Creates an angle in radians.
52    *
53    * @SINCE_1_0.0
54    * @param[in] value The initial value in radians
55    */
56   explicit Radian( float value )
57   : radian( value )
58   { }
59
60   /**
61    * @brief Creates an angle in radians from an angle in degrees.
62    *
63    * @SINCE_1_0.0
64    * @param[in] degree The initial value in degrees
65    */
66   Radian( Degree degree )
67   : radian( degree.degree * Math::PI_OVER_180 )
68   { }
69
70   /**
71    * @brief Assigns an angle from a float value.
72    *
73    * @SINCE_1_0.0
74    * @param[in] value Float value in radians
75    * @return A reference to this
76    */
77   Radian& operator=( float value )
78   {
79     radian = value;
80     return *this;
81   }
82
83   /**
84    * @brief Assigns an angle from a Degree value.
85    *
86    * @SINCE_1_0.0
87    * @param[in] degree The value in degrees
88    * @return A reference to this
89    */
90   Radian& operator=( Degree degree )
91   {
92     radian = degree.degree * Math::PI_OVER_180;
93     return *this;
94   }
95
96   /**
97    * @brief Conversion to float.
98    * @SINCE_1_0.0
99    * @return The float value of this Radian
100    */
101   operator float() const
102   {
103     return radian;
104   }
105
106 public:
107
108   // member data
109   float radian; ///< The value in radians
110
111 };
112
113 // compiler generated destructor, copy constructor and assignment operators are ok as this class is POD
114
115 /**
116  * @brief Compares equality between two radians.
117  *
118  * @SINCE_1_0.0
119  * @param[in] lhs Radian to compare
120  * @param[in] rhs Radian to compare to
121  * @return True if the values are identical
122  */
123 inline bool operator==( Radian lhs, Radian rhs )
124 {
125   return fabsf( lhs.radian - rhs.radian ) < Math::MACHINE_EPSILON_10; // expect Radian angles to be between 0 and 10 (multiplies of Math::PI)
126 }
127
128 /**
129  * @brief Compares inequality between two radians.
130  *
131  * @SINCE_1_0.0
132  * @param[in] lhs Radian to compare
133  * @param[in] rhs Radian to compare to
134  * @return True if the values are not identical
135  */
136 inline bool operator!=( Radian lhs, Radian rhs )
137 {
138   return !( operator==( lhs, rhs ) );
139 }
140
141 /**
142  * @brief Compares equality between a radian and degree.
143  *
144  * @SINCE_1_0.0
145  * @param[in] lhs Radian to compare
146  * @param[in] rhs Degree to compare to
147  * @return True if the values are identical
148  */
149 inline bool operator==( Radian lhs, Degree rhs )
150 {
151   return fabsf( lhs.radian - Radian( rhs ).radian ) < Math::MACHINE_EPSILON_100; // expect Degree angles to be between 0 and 999
152 }
153
154 /**
155  * @brief Compares inequality between a radian and a degree.
156  *
157  * @SINCE_1_0.0
158  * @param[in] lhs Radian to compare
159  * @param[in] rhs Degree to compare to
160  * @return True if the values are not identical
161  */
162 inline bool operator!=( Radian lhs, Degree rhs )
163 {
164   return !( operator==( lhs, rhs ) );
165 }
166
167 /**
168  * @brief Compares equality between a degree and a radian.
169  *
170  * @SINCE_1_0.0
171  * @param[in] lhs Degree to compare
172  * @param[in] rhs Radian to compare to
173  * @return True if the values are identical
174  */
175 inline bool operator==( Degree lhs, Radian rhs )
176 {
177   return fabsf( Radian( lhs ).radian - rhs.radian ) < Math::MACHINE_EPSILON_100; // expect Degree angles to be between 0 and 999
178 }
179
180 /**
181  * @brief Compares inequality between a degree and a radian.
182  *
183  * @SINCE_1_0.0
184  * @param[in] lhs Degree to compare
185  * @param[in] rhs Radian to compare to
186  * @return True if the values are not identical
187  */
188 inline bool operator!=( Degree lhs, Radian rhs )
189 {
190   return !( operator==( lhs, rhs ) );
191 }
192
193 /**
194  * @brief Compares greater than between two radians
195  *
196  * @SINCE_1_0.0
197  * @param[in] lhs Radian to compare
198  * @param[in] rhs Radian to compare to
199  * @return True if lhs is greater than rhs
200  */
201 inline bool operator>( Radian lhs, Radian rhs )
202 {
203   return lhs.radian > rhs.radian;
204 }
205
206 /**
207  * @brief Compares greater than between a radian and a degree.
208  *
209  * @SINCE_1_0.0
210  * @param[in] lhs Radian to compare
211  * @param[in] rhs Degree to compare to
212  * @return True if lhs is greater than rhs
213  */
214 inline bool operator>( Radian lhs, Degree rhs )
215 {
216   return lhs.radian > Radian(rhs).radian;
217 }
218
219 /**
220  * @brief Compares greater than between a radian and a degree.
221  *
222  * @SINCE_1_0.0
223  * @param[in] lhs Radian to compare
224  * @param[in] rhs Degree to compare to
225  * @return True if lhs is greater than rhs
226  */
227 inline bool operator>( Degree lhs, Radian rhs )
228 {
229   return Radian(lhs).radian > rhs.radian;
230 }
231
232 /**
233  * @brief Compares less than between two radians.
234  *
235  * @SINCE_1_0.0
236  * @param[in] lhs Radian to compare
237  * @param[in] rhs Radian to compare to
238  * @return True if lhs is less than rhs
239  */
240 inline bool operator<( Radian lhs, Radian rhs )
241 {
242   return lhs.radian < rhs.radian;
243 }
244
245 /**
246  * @brief Compares less than between a radian and a degree.
247  *
248  * @SINCE_1_0.0
249  * @param[in] lhs Radian to compare
250  * @param[in] rhs Degree to compare to
251  * @return True if lhs is less than rhs
252  */
253 inline bool operator<( Radian lhs, Degree rhs )
254 {
255   return lhs.radian < Radian(rhs).radian;
256 }
257
258 /**
259  * @brief Compares less than between a degree and a radian.
260  *
261  * @SINCE_1_0.0
262  * @param[in] lhs Degree to compare
263  * @param[in] rhs Radian to compare to
264  * @return True if lhs is less than rhs
265  */
266 inline bool operator<( Degree lhs, Radian rhs )
267 {
268   return Radian(lhs).radian < rhs.radian;
269 }
270
271 /**
272  * @brief Multiplies Radian with a float.
273  *
274  * @SINCE_1_0.0
275  * @param[in] lhs Radian to multiply
276  * @param[in] rhs float to multiply
277  * @return Result of the multiplication
278  */
279 inline Radian operator*( Radian lhs, float rhs )
280 {
281   return Radian( lhs.radian * rhs );
282 }
283
284 /**
285  * @brief Negates the radian.
286  * @SINCE_1_0.0
287  * @param[in] in Radian to negate
288  * @return The negative angle
289  */
290 inline Radian operator-( Radian in )
291 {
292    return Radian( -in.radian );
293 }
294
295 /**
296  * @brief Clamps a radian value.
297  * @SINCE_1_0.0
298  * @param angle to clamp
299  * @param min value
300  * @param max value
301  * @return The resulting radian
302  */
303 inline Radian Clamp( Radian angle, float min, float max )
304 {
305   return Radian( Clamp<float>( angle.radian, min, max ) );
306 }
307
308 /**
309  * @}
310  */
311 } // namespace Dali
312
313 #endif // __DALI_RADIAN_H__