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>
31 * @brief An angle in radians.
33 * This reduces ambiguity when using methods which accept angles in degrees or radians.
38 * @brief default constructor, initialises to 0.
45 * @brief Create an angle in radians.
47 * @param[in] value The initial value in radians.
49 explicit Radian( float value )
54 * @brief Create an angle in radians from an angle in degrees.
56 * @param[in] degree The initial value in degrees.
58 Radian( Degree degree )
59 : radian( degree.degree * Math::PI_OVER_180 )
63 * @brief Assign an angle from a float value.
65 * @param[in] value Float value in radians
66 * @return a reference to this object
68 Radian& operator=( float value )
75 * @brief Assign an angle from a Degree value.
77 * @param[in] degree The value in degrees.
78 * @return a reference to this object
80 Radian& operator=( Degree degree )
82 radian = degree.degree * Math::PI_OVER_180;
87 * @brief Conversion to float
88 * @return the float value of this Radian
90 operator float() const
98 float radian; ///< The value in radians
102 // compiler generated destructor, copy constructor and assignment operators are ok as this class is POD
104 // useful constant angles
105 static const Radian ANGLE_360 = Radian( Math::PI * 2.f ); ///< 360 degree turn in radians
106 static const Radian ANGLE_315 = Radian( Math::PI * 1.75f ); ///< 315 degree turn in radians
107 static const Radian ANGLE_270 = Radian( Math::PI * 1.50f ); ///< 270 degree turn in radians
108 static const Radian ANGLE_225 = Radian( Math::PI * 1.25f ); ///< 225 degree turn in radians
109 static const Radian ANGLE_180 = Radian( Math::PI ); ///< 180 degree turn in radians
110 static const Radian ANGLE_135 = Radian( Math::PI * 0.75f ); ///< 135 degree turn in radians
111 static const Radian ANGLE_120 = Radian( Math::PI * 2.f/3.f ); ///< 120 degree turn in radians
112 static const Radian ANGLE_90 = Radian( Math::PI_2 ); ///< 90 degree turn in radians
113 static const Radian ANGLE_45 = Radian( Math::PI_4 ); ///< 45 degree turn in radians
114 static const Radian ANGLE_60 = Radian( Math::PI / 3.f ); ///< 60 degree turn in radians
115 static const Radian ANGLE_30 = Radian( Math::PI / 6.f ); ///< 30 degree turn in radians
116 static const Radian ANGLE_0 = Radian( 0.0f ); ///< 0 degree turn in radians
119 * @brief Compare equality between two radians.
121 * @param[in] lhs Radian to compare
122 * @param[in] rhs Radian to compare to
123 * @return true if the values are identical
125 inline bool operator==( Radian lhs, Radian rhs )
127 return fabsf( lhs.radian - rhs.radian ) < Math::MACHINE_EPSILON_10; // expect Radian angles to be between 0 and 10 (multiplies of Math::PI)
131 * @brief Compare inequality 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 not identical
137 inline bool operator!=( Radian lhs, Radian rhs )
139 return !( operator==( lhs, rhs ) );
143 * @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.
157 * @param[in] lhs Radian to compare
158 * @param[in] rhs Degree to compare to
159 * @return true if the values are not identical
161 inline bool operator!=( Radian lhs, Degree rhs )
163 return !( operator==( lhs, rhs ) );
167 * @brief Compare equality between a degree and a radian.
169 * @param[in] lhs Degree to compare
170 * @param[in] rhs Radian to compare to
171 * @return true if the values are identical
173 inline bool operator==( Degree lhs, Radian rhs )
175 return fabsf( Radian( lhs ).radian - rhs.radian ) < Math::MACHINE_EPSILON_100; // expect Degree angles to be between 0 and 999
179 * @brief Compare inequality between a degree and a radian.
181 * @param[in] lhs Degree to compare
182 * @param[in] rhs Radian to compare to
183 * @return true if the values are not identical
185 inline bool operator!=( Degree lhs, Radian rhs )
187 return !( operator==( lhs, rhs ) );
191 * @brief Compare greater than between two radians
193 * @param[in] lhs Radian to compare
194 * @param[in] rhs Radian to compare to
195 * @return true if lhs is greater than rhs
197 inline bool operator>( Radian lhs, Radian rhs )
199 return lhs.radian > rhs.radian;
203 * @brief Compare greater than between a radian and a degree.
205 * @param[in] lhs Radian to compare
206 * @param[in] rhs Degree to compare to
207 * @return true if lhs is greater than rhs
209 inline bool operator>( Radian lhs, Degree rhs )
211 return lhs.radian > Radian(rhs).radian;
215 * @brief Compare greater than between a radian and a degree.
217 * @param[in] lhs Radian to compare
218 * @param[in] rhs Degree to compare to
219 * @return true if lhs is greater than rhs
221 inline bool operator>( Degree lhs, Radian rhs )
223 return Radian(lhs).radian > rhs.radian;
227 * @brief Compare less than between two radians.
229 * @param[in] lhs Radian to compare
230 * @param[in] rhs Radian to compare to
231 * @return true if lhs is less than rhs
233 inline bool operator<( Radian lhs, Radian rhs )
235 return lhs.radian < rhs.radian;
239 * @brief Compare less than between a radian and a degree.
241 * @param[in] lhs Radian to compare
242 * @param[in] rhs Degree to compare to
243 * @return true if lhs is less than rhs
245 inline bool operator<( Radian lhs, Degree rhs )
247 return lhs.radian < Radian(rhs).radian;
251 * @brief Compare less than between a degree and a radian.
253 * @param[in] lhs Degree to compare
254 * @param[in] rhs Radian to compare to
255 * @return true if lhs is less than rhs
257 inline bool operator<( Degree lhs, Radian rhs )
259 return Radian(lhs).radian < rhs.radian;
263 * @brief Multiply Radian with a float
265 * @param[in] lhs Radian to multiply
266 * @param[in] rhs float to multiply
267 * @return result of the multiplication
269 inline Radian operator*( Radian lhs, float rhs )
271 return Radian( lhs.radian * rhs );
275 * @brief Negate the radian
276 * @return The negative angle
278 inline Radian operator-( Radian in )
280 return Radian( -in.radian );
284 * @brief Clamp a radian value
285 * @param angle to clamp
288 * @return the resulting radian
290 inline Radian Clamp( Radian angle, float min, float max )
292 return Radian( Clamp<float>( angle.radian, min, max ) );
297 #endif // __DALI_RADIAN_H__