Merge "Remove unnecessary stream operators from radian and degree as well as unnecess...
[platform/core/uifw/dali-core.git] / dali / public-api / math / degree.h
1 #ifndef __DALI_DEGREE_H__
2 #define __DALI_DEGREE_H__
3
4 /*
5  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // INTERNAL INCLUDES
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
26 namespace Dali
27 {
28
29 struct Radian;
30
31 /**
32  * @brief An angle in degrees.
33  *
34  * This reduces ambiguity when using methods which accept angles in degrees or radians.
35  */
36 struct Degree
37 {
38   /**
39    * @brief default constructor, initialises to 0.
40    */
41   Degree()
42   : degree( 0.f )
43   { }
44
45   /**
46    * @brief Create an angle in degrees.
47    *
48    * @param[in] value The initial value in degrees.
49    */
50   explicit Degree( float value )
51   : degree( value )
52   { }
53
54   /**
55    * @brief Create an angle in degrees from a Radian.
56    *
57    * @param[in] value The initial value in Radians.
58    */
59   DALI_EXPORT_API Degree( Radian value );
60
61 public:
62
63   // member data
64   float degree; ///< The value in degrees
65
66 };
67
68 // compiler generated destructor, copy constructor and assignment operators are ok as this class is POD
69
70 /**
71  * @brief Compare equality between two degrees.
72  *
73  * @param[in] lhs Degree to compare
74  * @param[in] rhs Degree to compare to
75  * @return true if the values are identical
76  */
77 inline bool operator==( const Degree& lhs, const Degree& rhs )
78 {
79   return fabsf( lhs.degree - rhs.degree ) < Math::MACHINE_EPSILON_1000; // expect degree angles to be between 0 and 1000
80 }
81
82 /**
83  * @brief Compare inequality between two degrees.
84  *
85  * @param[in] lhs Degree to compare
86  * @param[in] rhs Degree to compare to
87  * @return true if the values are not identical
88  */
89 inline bool operator!=( const Degree& lhs, const Degree& rhs )
90 {
91   return !( operator==( lhs, rhs ) );
92 }
93
94 /**
95  * @brief Clamp a radian value
96  * @param angle to clamp
97  * @param min value
98  * @param max value
99  * @return the resulting radian
100  */
101 inline Degree Clamp( Degree angle, float min, float max )
102 {
103   return Degree( Clamp<float>( angle.degree, min, max ) );
104 }
105
106 } // namespace Dali
107
108 #endif // __DALI_DEGREE_H__