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.
42 * @brief default constructor, initialises to 0.
49 * @brief Create an angle in radians.
51 * @param[in] value The initial value in radians.
53 explicit Radian( float value )
58 * @brief Create an angle in radians from an angle in degrees.
60 * @param[in] degree The initial value in degrees.
62 Radian( Degree degree )
63 : radian( degree.degree * Math::PI_OVER_180 )
67 * @brief Assign an angle from a float value.
69 * @param[in] value Float value in radians
70 * @return a reference to this object
72 Radian& operator=( float value )
79 * @brief Assign an angle from a Degree value.
81 * @param[in] degree The value in degrees.
82 * @return a reference to this object
84 Radian& operator=( Degree degree )
86 radian = degree.degree * Math::PI_OVER_180;
91 * @brief Conversion to float
92 * @return the float value of this Radian
94 operator float() const
102 float radian; ///< The value in radians
106 // compiler generated destructor, copy constructor and assignment operators are ok as this class is POD
108 // useful constant angles
109 static const Radian ANGLE_360 = Radian( Math::PI * 2.f ); ///< 360 degree turn in radians
110 static const Radian ANGLE_315 = Radian( Math::PI * 1.75f ); ///< 315 degree turn in radians
111 static const Radian ANGLE_270 = Radian( Math::PI * 1.50f ); ///< 270 degree turn in radians
112 static const Radian ANGLE_225 = Radian( Math::PI * 1.25f ); ///< 225 degree turn in radians
113 static const Radian ANGLE_180 = Radian( Math::PI ); ///< 180 degree turn in radians
114 static const Radian ANGLE_135 = Radian( Math::PI * 0.75f ); ///< 135 degree turn in radians
115 static const Radian ANGLE_120 = Radian( Math::PI * 2.f/3.f ); ///< 120 degree turn in radians
116 static const Radian ANGLE_90 = Radian( Math::PI_2 ); ///< 90 degree turn in radians
117 static const Radian ANGLE_45 = Radian( Math::PI_4 ); ///< 45 degree turn in radians
118 static const Radian ANGLE_60 = Radian( Math::PI / 3.f ); ///< 60 degree turn in radians
119 static const Radian ANGLE_30 = Radian( Math::PI / 6.f ); ///< 30 degree turn in radians
120 static const Radian ANGLE_0 = Radian( 0.0f ); ///< 0 degree turn in radians
123 * @brief Compare equality between two radians.
125 * @param[in] lhs Radian to compare
126 * @param[in] rhs Radian to compare to
127 * @return true if the values are identical
129 inline bool operator==( Radian lhs, Radian rhs )
131 return fabsf( lhs.radian - rhs.radian ) < Math::MACHINE_EPSILON_10; // expect Radian angles to be between 0 and 10 (multiplies of Math::PI)
135 * @brief Compare inequality between two radians.
137 * @param[in] lhs Radian to compare
138 * @param[in] rhs Radian to compare to
139 * @return true if the values are not identical
141 inline bool operator!=( Radian lhs, Radian rhs )
143 return !( operator==( lhs, rhs ) );
147 * @brief Compare equality between a radian and degree.
149 * @param[in] lhs Radian to compare
150 * @param[in] rhs Degree to compare to
151 * @return true if the values are identical
153 inline bool operator==( Radian lhs, Degree rhs )
155 return fabsf( lhs.radian - Radian( rhs ).radian ) < Math::MACHINE_EPSILON_100; // expect Degree angles to be between 0 and 999
159 * @brief Compare inequality between a radian and a degree.
161 * @param[in] lhs Radian to compare
162 * @param[in] rhs Degree to compare to
163 * @return true if the values are not identical
165 inline bool operator!=( Radian lhs, Degree rhs )
167 return !( operator==( lhs, rhs ) );
171 * @brief Compare equality between a degree and a radian.
173 * @param[in] lhs Degree to compare
174 * @param[in] rhs Radian to compare to
175 * @return true if the values are identical
177 inline bool operator==( Degree lhs, Radian rhs )
179 return fabsf( Radian( lhs ).radian - rhs.radian ) < Math::MACHINE_EPSILON_100; // expect Degree angles to be between 0 and 999
183 * @brief Compare inequality 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 not identical
189 inline bool operator!=( Degree lhs, Radian rhs )
191 return !( operator==( lhs, rhs ) );
195 * @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.
209 * @param[in] lhs Radian to compare
210 * @param[in] rhs Degree to compare to
211 * @return true if lhs is greater than rhs
213 inline bool operator>( Radian lhs, Degree rhs )
215 return lhs.radian > Radian(rhs).radian;
219 * @brief Compare greater than between a radian and a degree.
221 * @param[in] lhs Radian to compare
222 * @param[in] rhs Degree to compare to
223 * @return true if lhs is greater than rhs
225 inline bool operator>( Degree lhs, Radian rhs )
227 return Radian(lhs).radian > rhs.radian;
231 * @brief Compare less than between two radians.
233 * @param[in] lhs Radian to compare
234 * @param[in] rhs Radian to compare to
235 * @return true if lhs is less than rhs
237 inline bool operator<( Radian lhs, Radian rhs )
239 return lhs.radian < rhs.radian;
243 * @brief Compare less than between a radian and a degree.
245 * @param[in] lhs Radian to compare
246 * @param[in] rhs Degree to compare to
247 * @return true if lhs is less than rhs
249 inline bool operator<( Radian lhs, Degree rhs )
251 return lhs.radian < Radian(rhs).radian;
255 * @brief Compare less than between a degree and a radian.
257 * @param[in] lhs Degree to compare
258 * @param[in] rhs Radian to compare to
259 * @return true if lhs is less than rhs
261 inline bool operator<( Degree lhs, Radian rhs )
263 return Radian(lhs).radian < rhs.radian;
267 * @brief Multiply Radian with a float
269 * @param[in] lhs Radian to multiply
270 * @param[in] rhs float to multiply
271 * @return result of the multiplication
273 inline Radian operator*( Radian lhs, float rhs )
275 return Radian( lhs.radian * rhs );
279 * @brief Negate the radian
280 * @return The negative angle
282 inline Radian operator-( Radian in )
284 return Radian( -in.radian );
288 * @brief Clamp a radian value
289 * @param angle to clamp
292 * @return the resulting radian
294 inline Radian Clamp( Radian angle, float min, float max )
296 return Radian( Clamp<float>( angle.radian, min, max ) );
304 #endif // __DALI_RADIAN_H__