Merge "Added P/N test cases, fixed last 2 cases." into tizen
[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 // EXTERNAL INCLUDES
22 #include <ostream>
23
24 // INTERNAL INCLUDES
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
29 namespace Dali
30 {
31
32 struct Radian;
33
34 /**
35  * @brief An angle in degrees.
36  *
37  * This reduces ambiguity when using methods which accept angles in degrees or radians.
38  */
39 struct Degree
40 {
41   /**
42    * @brief default constructor, initialises to 0.
43    */
44   Degree()
45   : degree( 0.f )
46   { }
47
48   /**
49    * @brief Create an angle in degrees.
50    *
51    * @param[in] value The initial value in degrees.
52    */
53   explicit Degree( float value )
54   : degree( value )
55   { }
56
57   /**
58    * @brief Create an angle in degrees from a Radian.
59    *
60    * @param[in] value The initial value in Radians.
61    */
62   DALI_EXPORT_API Degree( Radian value );
63
64 public:
65
66   // member data
67   float degree; ///< The value in degrees
68
69 };
70
71 // compiler generated destructor, copy constructor and assignment operators are ok as this class is POD
72
73 /**
74  * @brief Compare equality between two degrees.
75  *
76  * @param[in] lhs Degree to compare
77  * @param[in] rhs Degree to compare to
78  * @return true if the values are identical
79  */
80 inline bool operator==( const Degree& lhs, const Degree& rhs )
81 {
82   return fabsf( lhs.degree - rhs.degree ) < Math::MACHINE_EPSILON_1000; // expect degree angles to be between 0 and 1000
83 }
84
85 /**
86  * @brief Compare inequality between two degrees.
87  *
88  * @param[in] lhs Degree to compare
89  * @param[in] rhs Degree to compare to
90  * @return true if the values are not identical
91  */
92 inline bool operator!=( const Degree& lhs, const Degree& rhs )
93 {
94   return !( operator==( lhs, rhs ) );
95 }
96
97 /**
98  * @brief Clamp a radian value
99  * @param angle to clamp
100  * @param min value
101  * @param max value
102  * @return the resulting radian
103  */
104 inline Degree Clamp( Degree angle, float min, float max )
105 {
106   return Degree( Clamp<float>( angle.degree, min, max ) );
107 }
108
109 /**
110  * @brief Stream a degree value
111  * @param [in] ostream The output stream to use.
112  * @param [in] angle in Degree.
113  * @return The output stream.
114  */
115 inline std::ostream& operator<<( std::ostream& ostream, Degree angle )
116 {
117   ostream << angle.degree;
118   return ostream;
119 }
120
121 } // namespace Dali
122
123 #endif // __DALI_DEGREE_H__