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
109 * @brief Compare equality between two radians.
111 * @param[in] lhs Radian to compare
112 * @param[in] rhs Radian to compare to
113 * @return true if the values are identical
115 inline bool operator==( Radian lhs, Radian rhs )
117 return fabsf( lhs.radian - rhs.radian ) < Math::MACHINE_EPSILON_10; // expect Radian angles to be between 0 and 10 (multiplies of Math::PI)
121 * @brief Compare inequality between two radians.
123 * @param[in] lhs Radian to compare
124 * @param[in] rhs Radian to compare to
125 * @return true if the values are not identical
127 inline bool operator!=( Radian lhs, Radian rhs )
129 return !( operator==( lhs, rhs ) );
133 * @brief Compare equality between a radian and degree.
135 * @param[in] lhs Radian to compare
136 * @param[in] rhs Degree to compare to
137 * @return true if the values are identical
139 inline bool operator==( Radian lhs, Degree rhs )
141 return fabsf( lhs.radian - Radian( rhs ).radian ) < Math::MACHINE_EPSILON_100; // expect Degree angles to be between 0 and 999
145 * @brief Compare inequality between a radian and a degree.
147 * @param[in] lhs Radian to compare
148 * @param[in] rhs Degree to compare to
149 * @return true if the values are not identical
151 inline bool operator!=( Radian lhs, Degree rhs )
153 return !( operator==( lhs, rhs ) );
157 * @brief Compare equality between a degree and a radian.
159 * @param[in] lhs Degree to compare
160 * @param[in] rhs Radian to compare to
161 * @return true if the values are identical
163 inline bool operator==( Degree lhs, Radian rhs )
165 return fabsf( Radian( lhs ).radian - rhs.radian ) < Math::MACHINE_EPSILON_100; // expect Degree angles to be between 0 and 999
169 * @brief Compare inequality 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 not identical
175 inline bool operator!=( Degree lhs, Radian rhs )
177 return !( operator==( lhs, rhs ) );
181 * @brief Compare greater than between two radians
183 * @param[in] lhs Radian to compare
184 * @param[in] rhs Radian to compare to
185 * @return true if lhs is greater than rhs
187 inline bool operator>( Radian lhs, Radian rhs )
189 return lhs.radian > rhs.radian;
193 * @brief Compare greater than between a radian and a degree.
195 * @param[in] lhs Radian to compare
196 * @param[in] rhs Degree to compare to
197 * @return true if lhs is greater than rhs
199 inline bool operator>( Radian lhs, Degree rhs )
201 return lhs.radian > Radian(rhs).radian;
205 * @brief Compare greater than between a radian and a degree.
207 * @param[in] lhs Radian to compare
208 * @param[in] rhs Degree to compare to
209 * @return true if lhs is greater than rhs
211 inline bool operator>( Degree lhs, Radian rhs )
213 return Radian(lhs).radian > rhs.radian;
217 * @brief Compare less than between two radians.
219 * @param[in] lhs Radian to compare
220 * @param[in] rhs Radian to compare to
221 * @return true if lhs is less than rhs
223 inline bool operator<( Radian lhs, Radian rhs )
225 return lhs.radian < rhs.radian;
229 * @brief Compare less than between a radian and a degree.
231 * @param[in] lhs Radian to compare
232 * @param[in] rhs Degree to compare to
233 * @return true if lhs is less than rhs
235 inline bool operator<( Radian lhs, Degree rhs )
237 return lhs.radian < Radian(rhs).radian;
241 * @brief Compare less than between a degree and a radian.
243 * @param[in] lhs Degree to compare
244 * @param[in] rhs Radian to compare to
245 * @return true if lhs is less than rhs
247 inline bool operator<( Degree lhs, Radian rhs )
249 return Radian(lhs).radian < rhs.radian;
253 * @brief Multiply Radian with a float
255 * @param[in] lhs Radian to multiply
256 * @param[in] rhs float to multiply
257 * @return result of the multiplication
259 inline Radian operator*( Radian lhs, float rhs )
261 return Radian( lhs.radian * rhs );
265 * @brief Negate the radian
266 * @return The negative angle
268 inline Radian operator-( Radian in )
270 return Radian( -in.radian );
274 * @brief Clamp a radian value
275 * @param angle to clamp
278 * @return the resulting radian
280 inline Radian Clamp( Radian angle, float min, float max )
282 return Radian( Clamp<float>( angle.radian, min, max ) );
290 #endif // __DALI_RADIAN_H__