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.00f ); ///< 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 / 3.00f ); ///< 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_30 = Radian( Math::PI / 6.00f ); ///< 30 degree turn in radians
115 static const Radian ANGLE_0 = Radian( 0.0f ); ///< 0 degree turn in radians
118 * @brief Compare equality between two radians.
120 * @param[in] lhs Radian to compare
121 * @param[in] rhs Radian to compare to
122 * @return true if the values are identical
124 inline bool operator==( Radian lhs, Radian rhs )
126 return fabsf( lhs.radian - rhs.radian ) < Math::MACHINE_EPSILON_10; // expect Radian angles to be between 0 and 10 (multiplies of Math::PI)
130 * @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.
144 * @param[in] lhs Radian to compare
145 * @param[in] rhs Degree to compare to
146 * @return true if the values are identical
148 inline bool operator==( Radian lhs, Degree rhs )
150 return fabsf( lhs.radian - Radian( rhs ).radian ) < Math::MACHINE_EPSILON_100; // expect Degree angles to be between 0 and 999
154 * @brief Compare inequality between a radian and a degree.
156 * @param[in] lhs Radian to compare
157 * @param[in] rhs Degree to compare to
158 * @return true if the values are not identical
160 inline bool operator!=( Radian lhs, Degree rhs )
162 return !( operator==( lhs, rhs ) );
166 * @brief Compare equality between a degree and a radian.
168 * @param[in] lhs Degree to compare
169 * @param[in] rhs Radian to compare to
170 * @return true if the values are identical
172 inline bool operator==( Degree lhs, Radian rhs )
174 return fabsf( Radian( lhs ).radian - rhs.radian ) < Math::MACHINE_EPSILON_100; // expect Degree angles to be between 0 and 999
178 * @brief Compare inequality between a degree and a radian.
180 * @param[in] lhs Degree to compare
181 * @param[in] rhs Radian to compare to
182 * @return true if the values are not identical
184 inline bool operator!=( Degree lhs, Radian rhs )
186 return !( operator==( lhs, rhs ) );
190 * @brief Compare greater than between two radians
192 * @param[in] lhs Radian to compare
193 * @param[in] rhs Radian to compare to
194 * @return true if lhs is greater than rhs
196 inline bool operator>( Radian lhs, Radian rhs )
198 return lhs.radian > rhs.radian;
202 * @brief Compare greater than between a radian and a degree.
204 * @param[in] lhs Radian to compare
205 * @param[in] rhs Degree to compare to
206 * @return true if lhs is greater than rhs
208 inline bool operator>( Radian lhs, Degree rhs )
210 return lhs.radian > Radian(rhs).radian;
214 * @brief Compare greater than between a radian and a degree.
216 * @param[in] lhs Radian to compare
217 * @param[in] rhs Degree to compare to
218 * @return true if lhs is greater than rhs
220 inline bool operator>( Degree lhs, Radian rhs )
222 return Radian(lhs).radian > rhs.radian;
226 * @brief Compare less than between two radians.
228 * @param[in] lhs Radian to compare
229 * @param[in] rhs Radian to compare to
230 * @return true if lhs is less than rhs
232 inline bool operator<( Radian lhs, Radian rhs )
234 return lhs.radian < rhs.radian;
238 * @brief Compare less than between a radian and a degree.
240 * @param[in] lhs Radian to compare
241 * @param[in] rhs Degree to compare to
242 * @return true if lhs is less than rhs
244 inline bool operator<( Radian lhs, Degree rhs )
246 return lhs.radian < Radian(rhs).radian;
250 * @brief Compare less than between a degree and a radian.
252 * @param[in] lhs Degree to compare
253 * @param[in] rhs Radian to compare to
254 * @return true if lhs is less than rhs
256 inline bool operator<( Degree lhs, Radian rhs )
258 return Radian(lhs).radian < rhs.radian;
262 * @brief Multiply Radian with a float
264 * @param[in] lhs Radian to multiply
265 * @param[in] rhs float to multiply
266 * @return result of the multiplication
268 inline Radian operator*( Radian lhs, float rhs )
270 return Radian( lhs.radian * rhs );
274 * @brief Negate the radian
275 * @return The negative angle
277 inline Radian operator-( Radian in )
279 return Radian( -in.radian );
283 * @brief Clamp a radian value
284 * @param angle to clamp
287 * @return the resulting radian
289 inline Radian Clamp( Radian angle, float min, float max )
291 return Radian( Clamp<float>( angle.radian, min, max ) );
296 #endif // __DALI_RADIAN_H__