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
115 // useful constant angles
116 static const Radian ANGLE_360 = Radian( Math::PI * 2.f ); ///< 360 degree turn in radians
117 static const Radian ANGLE_315 = Radian( Math::PI * 1.75f ); ///< 315 degree turn in radians
118 static const Radian ANGLE_270 = Radian( Math::PI * 1.50f ); ///< 270 degree turn in radians
119 static const Radian ANGLE_225 = Radian( Math::PI * 1.25f ); ///< 225 degree turn in radians
120 static const Radian ANGLE_180 = Radian( Math::PI ); ///< 180 degree turn in radians
121 static const Radian ANGLE_135 = Radian( Math::PI * 0.75f ); ///< 135 degree turn in radians
122 static const Radian ANGLE_120 = Radian( Math::PI * 2.f/3.f ); ///< 120 degree turn in radians
123 static const Radian ANGLE_90 = Radian( Math::PI_2 ); ///< 90 degree turn in radians
124 static const Radian ANGLE_45 = Radian( Math::PI_4 ); ///< 45 degree turn in radians
125 static const Radian ANGLE_60 = Radian( Math::PI / 3.f ); ///< 60 degree turn in radians
126 static const Radian ANGLE_30 = Radian( Math::PI / 6.f ); ///< 30 degree turn in radians
127 static const Radian ANGLE_0 = Radian( 0.0f ); ///< 0 degree turn in radians
130 * @brief Compare equality between two radians.
133 * @param[in] lhs Radian to compare
134 * @param[in] rhs Radian to compare to
135 * @return true if the values are identical
137 inline bool operator==( Radian lhs, Radian rhs )
139 return fabsf( lhs.radian - rhs.radian ) < Math::MACHINE_EPSILON_10; // expect Radian angles to be between 0 and 10 (multiplies of Math::PI)
143 * @brief Compare inequality between two radians.
146 * @param[in] lhs Radian to compare
147 * @param[in] rhs Radian to compare to
148 * @return true if the values are not identical
150 inline bool operator!=( Radian lhs, Radian rhs )
152 return !( operator==( lhs, rhs ) );
156 * @brief Compare equality between a radian and degree.
159 * @param[in] lhs Radian to compare
160 * @param[in] rhs Degree to compare to
161 * @return true if the values are identical
163 inline bool operator==( Radian lhs, Degree rhs )
165 return fabsf( lhs.radian - Radian( rhs ).radian ) < Math::MACHINE_EPSILON_100; // expect Degree angles to be between 0 and 999
169 * @brief Compare inequality between a radian and a degree.
172 * @param[in] lhs Radian to compare
173 * @param[in] rhs Degree to compare to
174 * @return true if the values are not identical
176 inline bool operator!=( Radian lhs, Degree rhs )
178 return !( operator==( lhs, rhs ) );
182 * @brief Compare equality between a degree and a radian.
185 * @param[in] lhs Degree to compare
186 * @param[in] rhs Radian to compare to
187 * @return true if the values are identical
189 inline bool operator==( Degree lhs, Radian rhs )
191 return fabsf( Radian( lhs ).radian - rhs.radian ) < Math::MACHINE_EPSILON_100; // expect Degree angles to be between 0 and 999
195 * @brief Compare inequality between a degree and a radian.
198 * @param[in] lhs Degree to compare
199 * @param[in] rhs Radian to compare to
200 * @return true if the values are not identical
202 inline bool operator!=( Degree lhs, Radian rhs )
204 return !( operator==( lhs, rhs ) );
208 * @brief Compare greater than between two radians
211 * @param[in] lhs Radian to compare
212 * @param[in] rhs Radian to compare to
213 * @return true if lhs is greater than rhs
215 inline bool operator>( Radian lhs, Radian rhs )
217 return lhs.radian > rhs.radian;
221 * @brief Compare greater than between a radian and a degree.
224 * @param[in] lhs Radian to compare
225 * @param[in] rhs Degree to compare to
226 * @return true if lhs is greater than rhs
228 inline bool operator>( Radian lhs, Degree rhs )
230 return lhs.radian > Radian(rhs).radian;
234 * @brief Compare greater than between a radian and a degree.
237 * @param[in] lhs Radian to compare
238 * @param[in] rhs Degree to compare to
239 * @return true if lhs is greater than rhs
241 inline bool operator>( Degree lhs, Radian rhs )
243 return Radian(lhs).radian > rhs.radian;
247 * @brief Compare less than between two radians.
250 * @param[in] lhs Radian to compare
251 * @param[in] rhs Radian to compare to
252 * @return true if lhs is less than rhs
254 inline bool operator<( Radian lhs, Radian rhs )
256 return lhs.radian < rhs.radian;
260 * @brief Compare less than between a radian and a degree.
263 * @param[in] lhs Radian to compare
264 * @param[in] rhs Degree to compare to
265 * @return true if lhs is less than rhs
267 inline bool operator<( Radian lhs, Degree rhs )
269 return lhs.radian < Radian(rhs).radian;
273 * @brief Compare less than between a degree and a radian.
276 * @param[in] lhs Degree to compare
277 * @param[in] rhs Radian to compare to
278 * @return true if lhs is less than rhs
280 inline bool operator<( Degree lhs, Radian rhs )
282 return Radian(lhs).radian < rhs.radian;
286 * @brief Multiply Radian with a float
289 * @param[in] lhs Radian to multiply
290 * @param[in] rhs float to multiply
291 * @return result of the multiplication
293 inline Radian operator*( Radian lhs, float rhs )
295 return Radian( lhs.radian * rhs );
299 * @brief Negate the radian
301 * @return The negative angle
303 inline Radian operator-( Radian in )
305 return Radian( -in.radian );
309 * @brief Clamp a radian value
311 * @param angle to clamp
314 * @return the resulting radian
316 inline Radian Clamp( Radian angle, float min, float max )
318 return Radian( Clamp<float>( angle.radian, min, max ) );
326 #endif // __DALI_RADIAN_H__