Fork for IVI: mesa fixing
[profile/ivi/uifw.git] / src / ui / effects / inc / utils / FUiEffects_UtilsAdapterFunctions.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://floralicense.org/license/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file       FUiEffects_UtilsAdapterFunctions.h
20  * @brief      The adapter math functions for user types
21  *
22  */
23
24 #ifndef _FUI_EFFECTS_INTERNAL_UTILS_ADAPTER_FUNCTIONS_H_
25 #define _FUI_EFFECTS_INTERNAL_UTILS_ADAPTER_FUNCTIONS_H_
26
27 #include <algorithm>
28 #include "FUiEffects_UtilsCommon.h"
29
30 namespace Tizen { namespace Ui { namespace Effects { namespace _Utils
31 {
32         inline float effects_sqrt(float aValue);
33         inline double effects_sqrt(double aValue);
34
35         inline float effects_cos(float aAngle);
36         inline double effects_cos(double aAngle);
37         inline float effects_acos(float aAngle);
38         inline double effects_acos(double aAngle);
39
40         inline float effects_sin(float aAngle);
41         inline double effects_sin(double aAngle);
42         inline float effects_asin(float aAngle);
43         inline double effects_asin(double aAngle);
44
45         template<class T> inline T EffectsAbs(const T& aValue);
46         inline float EffectsAbs(const float& aValue);
47         inline double EffectsAbs(const double& aValue);
48
49         inline float effects_atan2(float x, float y);
50         inline double effects_atan2(double x, double y);
51
52         inline float effects_atan(float val);
53         inline double effects_atan(double val);
54
55         template<class T> struct effects_epsilon
56         {
57             static inline const T& epsilon() {return get_epsilon(static_cast<const T*>(0));}
58         };
59         template<> struct effects_epsilon<float>
60         {
61             static inline const float& epsilon() {return fEPS;}
62         };
63         template<> struct effects_epsilon<double>
64         {
65             static inline const double& epsilon() {return dEPS;}
66         };
67
68         inline bool EffectsEqual(const float& aLhv, const float& aRhv, const float& aEpsilon = fEPS);
69         inline bool EffectsEqual(const double& aLhv, const double& aRhv, const double& aEpsilon = dEPS);
70
71         template<class T> inline void EffectsSwap(T& aLhv, T& aRhv);
72         inline void EffectsSwap(float& aLhv, float& aRhv);
73         inline void EffectsSwap(double& aLhv, double& aRhv);
74
75         template<class T> inline T effects_clamp(const T& aValue, const T& aMin, const T& aMax);
76         inline float effects_clamp(const float& aValue, const float& aMin, const float& aMax);
77         inline double effects_clamp(const double& aValue, const double& aMin, const double& aMax);
78
79         template<class T> inline T effects_lerp(const T& aFrom, const T& aTo, const T& aCoeff);
80         inline float effects_lerp(const float& aFrom, const float& aTo, const float& aCoeff);
81         inline double effects_lerp(const double& aFrom, const double& aTo, const double& aCoeff);
82         inline int effects_lerp(const int& aFrom, const int& aTo, const int& aCoeff);
83         inline unsigned int effects_lerp(const unsigned int& aFrom, const unsigned int& aTo, const unsigned int& aCoeff);
84
85         template<class T> inline T EffectsMin(const T& a1, const T& a2);
86         template<class T> inline T EffectsMin3(const T& a1, const T& a2, const T& a3);
87         template<class T> inline T EffectsMax(const T& a1, const T& a2);
88         template<class T> inline T EffectsMax3(const T& a1, const T& a2, const T& a3);
89
90         inline float effects_sqrt(float aValue)
91         {
92             return sqrtf(aValue);
93         }
94         inline double effects_sqrt(double aValue)
95         {
96             return sqrt(aValue);
97         }
98
99         template<class T> inline bool EffectsEqual(const T& aLhv, const T& aRhv, const T& aEpsilon = effects_epsilon<T>::epsilon())
100         {
101             return aLhv == aRhv;
102         }
103         inline bool EffectsEqual(const float& aLhv, const float& aRhv, const float& aEpsilon)
104         {
105             return (aLhv + aEpsilon >= aRhv) && (aLhv - aEpsilon <= aRhv);
106         }
107         inline bool EffectsEqual(const double& aLhv, const double& aRhv, const double& aEpsilon)
108         {
109             return (aLhv + aEpsilon >= aRhv) && (aLhv - aEpsilon <= aRhv);
110         }
111
112         inline float effects_cos(float aAngle)
113         {
114             return cosf(aAngle);
115         }
116         inline double effects_cos(double aAngle)
117         {
118             return cos(aAngle);
119         }
120         inline float effects_acos(float aAngle)
121         {
122             return acosf(aAngle);
123         }
124         inline double effects_acos(double aAngle)
125         {
126             return acos(aAngle);
127         }
128
129         inline float effects_sin(float aAngle)
130         {
131             return sinf(aAngle);
132         }
133         inline double effects_sin(double aAngle)
134         {
135             return sin(aAngle);
136         }
137
138         inline float effects_asin(float aAngle)
139         {
140             return asinf(aAngle);
141         }
142         inline double effects_asin(double aAngle)
143         {
144             return asin(aAngle);
145         }
146
147         template<class T> inline T EffectsAbs(const T& aValue)
148         {
149             return abs(aValue);
150         }
151         inline float EffectsAbs(float aValue)
152         {
153             return fabsf(aValue);
154         }
155         inline double EffectsAbs(double aValue)
156         {
157             return fabs(aValue);
158         }
159
160         inline float effects_atan2(float x, float y)
161         {
162             return atan2f(x, y);
163         }
164         inline double effects_atan2(double x, double y)
165         {
166             return atan2(x, y);
167         }
168
169         inline float effects_atan(float val)
170         {
171             return atanf(val);
172         }
173         inline double effects_atan(double val)
174         {
175             return atan(val);
176         }
177
178         template<class T> inline void EffectsSwap(T& aLhv, T& aRhv)
179         {
180             T temp(aLhv);
181             aLhv = aRhv;
182             aRhv = temp;
183         }
184         inline void EffectsSwap(float& aLhv, float& aRhv)
185         {
186             std::swap(aLhv, aRhv);
187         }
188         inline void EffectsSwap(double& aLhv, double& aRhv)
189         {
190             std::swap(aLhv, aRhv);
191         }
192
193         template<class T> inline T effects_clamp(const T& aValue, const T& aMin, const T& aMax)
194         {
195             if(aValue < aMin)
196                 return aMin;
197             if(aValue > aMax)
198                 return aMax;
199             return aValue;
200         }
201         inline float effects_clamp(const float& aValue, const float& aMin, const float& aMax)
202         {
203             if(aValue < aMin)
204                 return aMin;
205             if(aValue > aMax)
206                 return aMax;
207             return aValue;
208         }
209         inline double effects_clamp(const double& aValue, const double& aMin, const double& aMax)
210         {
211             if(aValue < aMin)
212                 return aMin;
213             if(aValue > aMax)
214                 return aMax;
215             return aValue;
216         }
217
218         template<class T> inline T effects_lerp(const T& aFrom, const T& aTo, const T& aCoeff)
219         {
220             return aFrom + (aTo - aFrom) * aCoeff;
221         }
222         inline float effects_lerp(const float& aFrom, const float& aTo, const float& aCoeff)
223         {
224             return aFrom + (aTo - aFrom) * aCoeff;
225         }
226         inline double effects_lerp(const double& aFrom, const double& aTo, const double& aCoeff)
227         {
228             return aFrom + (aTo - aFrom) * aCoeff;
229         }
230         inline int effects_lerp(const int& aFrom, const int& aTo, const int& aCoeff)
231         {
232             return aFrom + (((aTo - aFrom) * aCoeff) >> 8);
233         }
234         inline unsigned int effects_lerp(const unsigned int& aFrom, const unsigned int& aTo, const unsigned int& aCoeff)
235         {
236             return aFrom + (((aTo - aFrom) * aCoeff) >> 8);
237         }
238
239         template<class T> inline T EffectsMin(const T& a1, const T& a2)
240         {
241             if(a1 < a2)
242                 return a1;
243             return a2;
244         }
245         template<class T> inline T EffectsMin3(const T& a1, const T& a2, const T& a3)
246         {
247             return EffectsMin(EffectsMin(a1, a2), a3);
248         }
249         template<class T> inline T EffectsMax(const T& a1, const T& a2)
250         {
251             if(a1 < a2)
252                 return a2;
253             return a1;
254         }
255         template<class T> inline T EffectsMax3(const T& a1, const T& a2, const T& a3)
256         {
257             return EffectsMax(EffectsMax(a1, a2), a3);
258         }
259 } } } } //Tizen::Ui::Effects::_Utils
260
261 #endif //_FUI_EFFECTS_INTERNAL_UTILS_ADAPTER_FUNCTIONS_H_