Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / effects / inc / renderer / math / FUiEffects_RendererMathAdapterFunctions.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_RendererMathAdapterFunctions.h
20  * @brief      The adapter math functions for user types
21  *
22  */
23
24 #ifndef _FUI_EFFECTS_INTERNAL_RENDERER_MATH_ADAPTER_FUNCTIONS_H_
25 #define _FUI_EFFECTS_INTERNAL_RENDERER_MATH_ADAPTER_FUNCTIONS_H_
26
27 #include <renderer/math/FUiEffects_RendererMathCommon.h>
28
29 namespace Tizen { namespace Ui { namespace Effects { namespace _Renderer { namespace Math
30 {
31
32 inline float EffectsSqrt(float value);
33 inline double EffectsSqrt(double value);
34
35 inline float EffectsCos(float angle);
36 inline double EffectsCos(double angle);
37 inline float EffectsAcos(float angle);
38 inline double EffectsAcos(double angle);
39
40 inline float EffectsSin(float angle);
41 inline double EffectsSin(double angle);
42 inline float EffectsAsin(float angle);
43 inline double EffectsAsin(double angle);
44
45 template<class T> inline T EffectsAbs(const T& value);
46 inline float EffectsAbs(const float& value);
47 inline double EffectsAbs(const double& value);
48
49 inline float EffectsAtan2(float x, float y);
50 inline double EffectsAtan2(double x, double y);
51
52 inline float EffectsAtan(float value);
53 inline double EffectsAtan(double value);
54
55 template<class T> struct EffectsEpsilon
56 {
57         static inline const T& Epsilon(void)
58         {
59                 return get_epsilon(static_cast<const T*>(0));
60         }
61 };
62
63 template<> struct EffectsEpsilon<float>
64 {
65         static inline const float& Epsilon(void)
66         {
67                 return F_EPS;
68         }
69 };
70
71 template<> struct EffectsEpsilon<double>
72 {
73         static inline const double& Epsilon(void)
74         {
75                 return D_EPS;
76         }
77 };
78
79 inline bool EffectsEqual(const float& lhv, const float& rhv, const float& epsilon = F_EPS);
80 inline bool EffectsEqual(const double& lhv, const double& rhv, const double& epsilon = D_EPS);
81
82 template<class T> inline void EffectsSwap(T& lhv, T& rhv);
83 inline void EffectsSwap(float& lhv, float& rhv);
84 inline void EffectsSwap(double& lhv, double& rhv);
85
86 template<class T> inline T EffectsClamp(const T& value, const T& min, const T& max);
87 inline float EffectsClamp(const float& value, const float& min, const float& max);
88 inline double EffectsClamp(const double& value, const double& min, const double& max);
89
90 template<class T> inline T EffectsLerp(const T& from, const T& to, const T& coeff);
91 inline float EffectsLerp(const float& from, const float& to, const float& coeff);
92 inline double EffectsLerp(const double& from, const double& to, const double& coeff);
93 inline int EffectsLerp(const int& from, const int& to, const int& coeff);
94 inline unsigned int EffectsLerp(const unsigned int& from, const unsigned int& to, const unsigned int& coeff);
95
96 template<class T> inline T EffectsMin(const T& a1, const T& a2);
97 template<class T> inline T EffectsMin3(const T& a1, const T& a2, const T& a3);
98 template<class T> inline T EffectsMax(const T& a1, const T& a2);
99 template<class T> inline T EffectsMax3(const T& a1, const T& a2, const T& a3);
100
101 inline float EffectsSqrt(float value)
102 {
103         return sqrtf(value);
104 }
105 inline double EffectsSqrt(double value)
106 {
107         return sqrt(value);
108 }
109
110 template<class T> inline bool EffectsEqual(const T& lhv, const T& rhv, const T& epsilon = EffectsEpsilon<T>::epsilon())
111 {
112         return lhv == rhv;
113 }
114 inline bool EffectsEqual(const float& lhv, const float& rhv, const float& epsilon)
115 {
116         return (lhv + epsilon >= rhv) && (lhv - epsilon <= rhv);
117 }
118 inline bool EffectsEqual(const double& lhv, const double& rhv, const double& epsilon)
119 {
120         return (lhv + epsilon >= rhv) && (lhv - epsilon <= rhv);
121 }
122
123 inline float EffectsCos(float angle)
124 {
125         return cosf(angle);
126 }
127 inline double EffectsCos(double angle)
128 {
129         return cos(angle);
130 }
131 inline float EffectsAcos(float angle)
132 {
133         return acosf(angle);
134 }
135 inline double EffectsAcos(double angle)
136 {
137         return acos(angle);
138 }
139
140 inline float EffectsSin(float angle)
141 {
142         return sinf(angle);
143 }
144 inline double EffectsSin(double angle)
145 {
146         return sin(angle);
147 }
148
149 inline float EffectsAsin(float angle)
150 {
151         return asinf(angle);
152 }
153 inline double EffectsAsin(double angle)
154 {
155         return asin(angle);
156 }
157
158 template<class T> inline T EffectsAbs(const T& value)
159 {
160         return abs(value);
161 }
162 inline float EffectsAbs(const float &value)
163 {
164         return fabsf(value);
165 }
166 inline double EffectsAbs(const double &value)
167 {
168         return fabs(value);
169 }
170
171 inline float EffectsAtan2(float x, float y)
172 {
173         return atan2f(x, y);
174 }
175 inline double EffectsAtan2(double x, double y)
176 {
177         return atan2(x, y);
178 }
179
180 inline float EffectsAtan(float value)
181 {
182         return atanf(value);
183 }
184 inline double EffectsAtan(double value)
185 {
186         return atan(value);
187 }
188
189 template<class T> inline void EffectsSwap(T& lhv, T& rhv)
190 {
191         T temp(lhv);
192         lhv = rhv;
193         rhv = temp;
194 }
195 inline void EffectsSwap(float& lhv, float& rhv)
196 {
197         std::swap(lhv, rhv);
198 }
199 inline void EffectsSwap(double& lhv, double& rhv)
200 {
201         std::swap(lhv, rhv);
202 }
203
204 template<class T> inline T EffectsClamp(const T& value, const T& min, const T& max)
205 {
206         if (value < min)
207         {
208                 return min;
209         }
210         if (value > max)
211         {
212                 return max;
213         }
214         return value;
215 }
216 inline float EffectsClamp(const float& value, const float& min, const float& max)
217 {
218         if (value < min)
219         {
220                 return min;
221         }
222         if (value > max)
223         {
224                 return max;
225         }
226         return value;
227 }
228 inline double EffectsClamp(const double& value, const double& min, const double& max)
229 {
230         if (value < min)
231         {
232                 return min;
233         }
234         if (value > max)
235         {
236                 return max;
237         }
238         return value;
239 }
240
241 template<class T> inline T EffectsLerp(const T& from, const T& to, const T& coeff)
242 {
243         return from + (to - from) * coeff;
244 }
245 inline float EffectsLerp(const float& from, const float& to, const float& coeff)
246 {
247         return from + (to - from) * coeff;
248 }
249 inline double EffectsLerp(const double& from, const double& to, const double& coeff)
250 {
251         return from + (to - from) * coeff;
252 }
253 inline int EffectsLerp(const int& from, const int& to, const int& coeff)
254 {
255         return from + (((to - from) * coeff) >> 8);
256 }
257 inline unsigned int EffectsLerp(const unsigned int& from, const unsigned int& to, const unsigned int& coeff)
258 {
259         return from + (((to - from) * coeff) >> 8);
260 }
261
262 template<class T> inline T EffectsMin(const T& a1, const T& a2)
263 {
264         if (a1 < a2)
265         {
266                 return a1;
267         }
268         return a2;
269 }
270 template<class T> inline T EffectsMin3(const T& a1, const T& a2, const T& a3)
271 {
272         return EffectsMin(EffectsMin(a1, a2), a3);
273 }
274 template<class T> inline T EffectsMax(const T& a1, const T& a2)
275 {
276         if (a1 < a2)
277         {
278                 return a2;
279         }
280
281         return a1;
282 }
283 template<class T> inline T EffectsMax3(const T& a1, const T& a2, const T& a3)
284 {
285         return EffectsMax(EffectsMax(a1, a2), a3);
286 }
287
288 }}}}} //Tizen::Ui::Effects::_Renderer::Math
289
290 #endif //_FUI_EFFECTS_INTERNAL_RENDERER_MATH_ADAPTER_FUNCTIONS_H_