1 #ifndef __DALI_RADIAN_H__
2 #define __DALI_RADIAN_H__
5 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
30 * @addtogroup dali_core_math
35 * @brief An angle in radians.
37 * This reduces ambiguity when using methods which accept angles in degrees or radians.
43 * @brief default constructor, initialises to 0.
51 * @brief Create an angle in radians.
54 * @param[in] value The initial value in radians.
56 explicit Radian( float value )
61 * @brief Create an angle in radians from an angle in degrees.
64 * @param[in] degree The initial value in degrees.
66 Radian( Degree degree )
67 : radian( degree.degree * Math::PI_OVER_180 )
71 * @brief Assign an angle from a float value.
74 * @param[in] value Float value in radians
75 * @return A reference to this
77 Radian& operator=( float value )
84 * @brief Assign an angle from a Degree value.
87 * @param[in] degree The value in degrees.
88 * @return A reference to this
90 Radian& operator=( Degree degree )
92 radian = degree.degree * Math::PI_OVER_180;
97 * @brief Conversion to float
99 * @return the float value of this Radian
101 operator float() const
109 float radian; ///< The value in radians
113 // compiler generated destructor, copy constructor and assignment operators are ok as this class is POD
116 * @brief Compare equality between two radians.
119 * @param[in] lhs Radian to compare
120 * @param[in] rhs Radian to compare to
121 * @return true if the values are identical
123 inline bool operator==( Radian lhs, Radian rhs )
125 return fabsf( lhs.radian - rhs.radian ) < Math::MACHINE_EPSILON_10; // expect Radian angles to be between 0 and 10 (multiplies of Math::PI)
129 * @brief Compare inequality between two radians.
132 * @param[in] lhs Radian to compare
133 * @param[in] rhs Radian to compare to
134 * @return true if the values are not identical
136 inline bool operator!=( Radian lhs, Radian rhs )
138 return !( operator==( lhs, rhs ) );
142 * @brief Compare equality between a radian and degree.
145 * @param[in] lhs Radian to compare
146 * @param[in] rhs Degree to compare to
147 * @return true if the values are identical
149 inline bool operator==( Radian lhs, Degree rhs )
151 return fabsf( lhs.radian - Radian( rhs ).radian ) < Math::MACHINE_EPSILON_100; // expect Degree angles to be between 0 and 999
155 * @brief Compare inequality between a radian and a degree.
158 * @param[in] lhs Radian to compare
159 * @param[in] rhs Degree to compare to
160 * @return true if the values are not identical
162 inline bool operator!=( Radian lhs, Degree rhs )
164 return !( operator==( lhs, rhs ) );
168 * @brief Compare equality between a degree and a radian.
171 * @param[in] lhs Degree to compare
172 * @param[in] rhs Radian to compare to
173 * @return true if the values are identical
175 inline bool operator==( Degree lhs, Radian rhs )
177 return fabsf( Radian( lhs ).radian - rhs.radian ) < Math::MACHINE_EPSILON_100; // expect Degree angles to be between 0 and 999
181 * @brief Compare inequality between a degree and a radian.
184 * @param[in] lhs Degree to compare
185 * @param[in] rhs Radian to compare to
186 * @return true if the values are not identical
188 inline bool operator!=( Degree lhs, Radian rhs )
190 return !( operator==( lhs, rhs ) );
194 * @brief Compare greater than between two radians
197 * @param[in] lhs Radian to compare
198 * @param[in] rhs Radian to compare to
199 * @return true if lhs is greater than rhs
201 inline bool operator>( Radian lhs, Radian rhs )
203 return lhs.radian > rhs.radian;
207 * @brief Compare greater than between a radian and a degree.
210 * @param[in] lhs Radian to compare
211 * @param[in] rhs Degree to compare to
212 * @return true if lhs is greater than rhs
214 inline bool operator>( Radian lhs, Degree rhs )
216 return lhs.radian > Radian(rhs).radian;
220 * @brief Compare greater than between a radian and a degree.
223 * @param[in] lhs Radian to compare
224 * @param[in] rhs Degree to compare to
225 * @return true if lhs is greater than rhs
227 inline bool operator>( Degree lhs, Radian rhs )
229 return Radian(lhs).radian > rhs.radian;
233 * @brief Compare less than between two radians.
236 * @param[in] lhs Radian to compare
237 * @param[in] rhs Radian to compare to
238 * @return true if lhs is less than rhs
240 inline bool operator<( Radian lhs, Radian rhs )
242 return lhs.radian < rhs.radian;
246 * @brief Compare less than between a radian and a degree.
249 * @param[in] lhs Radian to compare
250 * @param[in] rhs Degree to compare to
251 * @return true if lhs is less than rhs
253 inline bool operator<( Radian lhs, Degree rhs )
255 return lhs.radian < Radian(rhs).radian;
259 * @brief Compare less than between a degree and a radian.
262 * @param[in] lhs Degree to compare
263 * @param[in] rhs Radian to compare to
264 * @return true if lhs is less than rhs
266 inline bool operator<( Degree lhs, Radian rhs )
268 return Radian(lhs).radian < rhs.radian;
272 * @brief Multiply Radian with a float
275 * @param[in] lhs Radian to multiply
276 * @param[in] rhs float to multiply
277 * @return result of the multiplication
279 inline Radian operator*( Radian lhs, float rhs )
281 return Radian( lhs.radian * rhs );
285 * @brief Negate the radian
287 * @return The negative angle
289 inline Radian operator-( Radian in )
291 return Radian( -in.radian );
295 * @brief Clamp a radian value
297 * @param angle to clamp
300 * @return the resulting radian
302 inline Radian Clamp( Radian angle, float min, float max )
304 return Radian( Clamp<float>( angle.radian, min, max ) );
312 #endif // __DALI_RADIAN_H__