Merge "Add method to get ObjectRegistry from Core" into devel/master
[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) 2020 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  * @addtogroup dali_core_math
30  * @{
31  */
32
33 struct Radian;
34
35 /**
36  * @brief An angle in degrees.
37  *
38  * This reduces ambiguity when using methods which accept angles in degrees or radians.
39  * @SINCE_1_0.0
40  */
41 struct Degree
42 {
43   /**
44    * @brief Default constructor, initialises to 0.
45    * @SINCE_1_0.0
46    */
47   Degree()
48   : degree( 0.f )
49   { }
50
51   /**
52    * @brief Creates an angle in degrees.
53    *
54    * @SINCE_1_0.0
55    * @param[in] value The initial value in degrees
56    */
57   explicit Degree( float value )
58   : degree( value )
59   { }
60
61   /**
62    * @brief Creates an angle in degrees from a Radian.
63    *
64    * @SINCE_1_0.0
65    * @param[in] value The initial value in Radians
66    */
67   DALI_CORE_API Degree( Radian value );
68
69 public:
70
71   Degree( const Degree& ) = default; ///< Default copy constructor
72   Degree( Degree&& ) = default; ///< Default move constructor
73   Degree& operator=( const Degree& ) = default; ///< Default copy assignment operator
74   Degree& operator=( Degree&& ) = default; ///< Default move assignment operator
75
76 public:
77
78   // member data
79   float degree; ///< The value in degrees
80
81 };
82
83 // compiler generated destructor, copy constructor and assignment operators are ok as this class is POD
84
85 // useful constant angles
86 DALI_CORE_API extern const Radian ANGLE_360; ///< 360 degree turn in radians
87 DALI_CORE_API extern const Radian ANGLE_315; ///< 315 degree turn in radians
88 DALI_CORE_API extern const Radian ANGLE_270; ///< 270 degree turn in radians
89 DALI_CORE_API extern const Radian ANGLE_225; ///< 225 degree turn in radians
90 DALI_CORE_API extern const Radian ANGLE_180; ///< 180 degree turn in radians
91 DALI_CORE_API extern const Radian ANGLE_135; ///< 135 degree turn in radians
92 DALI_CORE_API extern const Radian ANGLE_120; ///< 120 degree turn in radians
93 DALI_CORE_API extern const Radian ANGLE_90;  ///< 90 degree turn in radians
94 DALI_CORE_API extern const Radian ANGLE_60;  ///< 60 degree turn in radians
95 DALI_CORE_API extern const Radian ANGLE_45;  ///< 45 degree turn in radians
96 DALI_CORE_API extern const Radian ANGLE_30;  ///< 30 degree turn in radians
97 DALI_CORE_API extern const Radian ANGLE_0;   ///< 0 degree turn in radians
98
99 /**
100  * @brief Compares equality between two degrees.
101  *
102  * @SINCE_1_0.0
103  * @param[in] lhs Degree to compare
104  * @param[in] rhs Degree to compare to
105  * @return True if the values are identical
106  */
107 inline bool operator==( const Degree& lhs, const Degree& rhs )
108 {
109   return fabsf( lhs.degree - rhs.degree ) < Math::MACHINE_EPSILON_1000; // expect degree angles to be between 0 and 1000
110 }
111
112 /**
113  * @brief Compares inequality between two degrees.
114  *
115  * @SINCE_1_0.0
116  * @param[in] lhs Degree to compare
117  * @param[in] rhs Degree to compare to
118  * @return True if the values are not identical
119  */
120 inline bool operator!=( const Degree& lhs, const Degree& rhs )
121 {
122   return !( operator==( lhs, rhs ) );
123 }
124
125 /**
126  * @brief Clamps a radian value.
127  * @SINCE_1_0.0
128  * @param angle to clamp
129  * @param min value
130  * @param max value
131  * @return The resulting radian
132  */
133 inline Degree Clamp( Degree angle, float min, float max )
134 {
135   return Degree( Clamp<float>( angle.degree, min, max ) );
136 }
137
138 /**
139  * @}
140  */
141 } // namespace Dali
142
143 #endif // DALI_DEGREE_H