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.
25 #include <dali/public-api/common/constants.h>
26 #include <dali/public-api/common/dali-common.h>
27 #include <dali/public-api/math/math-utils.h>
28 #include <dali/public-api/math/degree.h>
34 * @brief An angle in radians.
36 * This reduces ambiguity when using methods which accept angles in degrees or radians.
41 * @brief default constructor, initialises to 0.
48 * @brief Create an angle in radians.
50 * @param[in] value The initial value in radians.
52 explicit Radian( float value )
57 * @brief Create an angle in radians from an angle in degrees.
59 * @param[in] degree The initial value in degrees.
61 Radian( Degree degree )
62 : radian( degree.degree * Math::PI_OVER_180 )
66 * @brief Assign an angle from a float value.
68 * @param[in] value Float value in radians
69 * @return a reference to this object
71 Radian& operator=( float value )
78 * @brief Assign an angle from a Degree value.
80 * @param[in] degree The value in degrees.
81 * @return a reference to this object
83 Radian& operator=( Degree degree )
85 radian = degree.degree * Math::PI_OVER_180;
90 * @brief Conversion to float
91 * @return the float value of this Radian
93 operator float() const
101 float radian; ///< The value in radians
105 // compiler generated destructor, copy constructor and assignment operators are ok as this class is POD
107 // useful constant angles
108 static const Radian ANGLE_360 = Radian( Math::PI * 2.00f ); ///< 360 degree turn in radians
109 static const Radian ANGLE_315 = Radian( Math::PI * 1.75f ); ///< 315 degree turn in radians
110 static const Radian ANGLE_270 = Radian( Math::PI * 1.50f );///< 270 degree turn in radians
111 static const Radian ANGLE_225 = Radian( Math::PI * 1.25f ); ///< 225 degree turn in radians
112 static const Radian ANGLE_180 = Radian( Math::PI ); ///< 180 degree turn in radians
113 static const Radian ANGLE_135 = Radian( Math::PI * 0.75f ); ///< 135 degree turn in radians
114 static const Radian ANGLE_120 = Radian( Math::PI / 3.00f ); ///< 120 degree turn in radians
115 static const Radian ANGLE_90 = Radian( Math::PI_2 ); ///< 90 degree turn in radians
116 static const Radian ANGLE_45 = Radian( Math::PI_4 ); ///< 45 degree turn in radians
117 static const Radian ANGLE_30 = Radian( Math::PI / 6.00f ); ///< 30 degree turn in radians
118 static const Radian ANGLE_0 = Radian( 0.0f ); ///< 0 degree turn in radians
121 * @brief Compare equality 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 identical
127 inline bool operator==( Radian lhs, Radian rhs )
129 return fabsf( lhs.radian - rhs.radian ) < Math::MACHINE_EPSILON_10; // expect Radian angles to be between 0 and 10 (multiplies of Math::PI)
133 * @brief Compare inequality between two radians.
135 * @param[in] lhs Radian to compare
136 * @param[in] rhs Radian to compare to
137 * @return true if the values are not identical
139 inline bool operator!=( Radian lhs, Radian rhs )
141 return !( operator==( lhs, rhs ) );
145 * @brief Compare equality between a radian and degree.
147 * @param[in] lhs Radian to compare
148 * @param[in] rhs Degree to compare to
149 * @return true if the values are identical
151 inline bool operator==( Radian lhs, Degree rhs )
153 return fabsf( lhs.radian - Radian( rhs ).radian ) < Math::MACHINE_EPSILON_100; // expect Degree angles to be between 0 and 999
157 * @brief Compare inequality between a radian and a degree.
159 * @param[in] lhs Radian to compare
160 * @param[in] rhs Degree to compare to
161 * @return true if the values are not identical
163 inline bool operator!=( Radian lhs, Degree rhs )
165 return !( operator==( lhs, rhs ) );
169 * @brief Compare equality 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 identical
175 inline bool operator==( Degree lhs, Radian rhs )
177 return fabsf( Radian( lhs ).radian - rhs.radian ) < Math::MACHINE_EPSILON_100; // expect Degree angles to be between 0 and 999
181 * @brief Compare inequality between a degree and a radian.
183 * @param[in] lhs Degree to compare
184 * @param[in] rhs Radian to compare to
185 * @return true if the values are not identical
187 inline bool operator!=( Degree lhs, Radian rhs )
189 return !( operator==( lhs, rhs ) );
193 * @brief Compare greater than between two radians
195 * @param[in] lhs Radian to compare
196 * @param[in] rhs Radian to compare to
197 * @return true if lhs is greater than rhs
199 inline bool operator>( Radian lhs, Radian rhs )
201 return lhs.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>( Radian lhs, Degree rhs )
213 return lhs.radian > Radian(rhs).radian;
217 * @brief Compare greater than between a radian and a degree.
219 * @param[in] lhs Radian to compare
220 * @param[in] rhs Degree to compare to
221 * @return true if lhs is greater than rhs
223 inline bool operator>( Degree lhs, Radian rhs )
225 return Radian(lhs).radian > rhs.radian;
229 * @brief Compare less than between two radians.
231 * @param[in] lhs Radian to compare
232 * @param[in] rhs Radian to compare to
233 * @return true if lhs is less than rhs
235 inline bool operator<( Radian lhs, Radian rhs )
237 return lhs.radian < rhs.radian;
241 * @brief Compare less than between a radian and a degree.
243 * @param[in] lhs Radian to compare
244 * @param[in] rhs Degree to compare to
245 * @return true if lhs is less than rhs
247 inline bool operator<( Radian lhs, Degree rhs )
249 return lhs.radian < Radian(rhs).radian;
253 * @brief Compare less than between a degree and a radian.
255 * @param[in] lhs Degree to compare
256 * @param[in] rhs Radian to compare to
257 * @return true if lhs is less than rhs
259 inline bool operator<( Degree lhs, Radian rhs )
261 return Radian(lhs).radian < rhs.radian;
265 * @brief Multiply Radian with a float
267 * @param[in] lhs Radian to multiply
268 * @param[in] rhs float to multiply
269 * @return result of the multiplication
271 inline Radian operator*( Radian lhs, float rhs )
273 return Radian( lhs.radian * rhs );
277 * @brief Negate the radian
278 * @return The negative angle
280 inline Radian operator-( Radian in )
282 return Radian( -in.radian );
286 * @brief Clamp a radian value
287 * @param angle to clamp
290 * @return the resulting radian
292 inline Radian Clamp( Radian angle, float min, float max )
294 return Radian( Clamp<float>( angle.radian, min, max ) );
298 * @brief Stream a radian value
299 * @param [in] ostream The output stream to use.
300 * @param [in] angle in Radian.
301 * @return The output stream.
303 inline std::ostream& operator<<( std::ostream& ostream, Radian angle )
305 ostream << angle.radian;
311 #endif // __DALI_RADIAN_H__