2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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
9 // http://floralicense.org/license/
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.
19 * @file FUiEffects_UtilsAdapterFunctions.h
20 * @brief The adapter math functions for user types
24 #ifndef _FUI_EFFECTS_INTERNAL_UTILS_ADAPTER_FUNCTIONS_H_
25 #define _FUI_EFFECTS_INTERNAL_UTILS_ADAPTER_FUNCTIONS_H_
28 #include "FUiEffects_UtilsCommon.h"
30 namespace Tizen { namespace Ui { namespace Effects { namespace _Utils
32 inline float effects_sqrt(float aValue);
33 inline double effects_sqrt(double aValue);
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);
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);
45 template<class T> inline T EffectsAbs(const T& aValue);
46 inline float EffectsAbs(const float& aValue);
47 inline double EffectsAbs(const double& aValue);
49 inline float effects_atan2(float x, float y);
50 inline double effects_atan2(double x, double y);
52 inline float effects_atan(float val);
53 inline double effects_atan(double val);
55 template<class T> struct effects_epsilon
57 static inline const T& epsilon() {return get_epsilon(static_cast<const T*>(0));}
59 template<> struct effects_epsilon<float>
61 static inline const float& epsilon() {return fEPS;}
63 template<> struct effects_epsilon<double>
65 static inline const double& epsilon() {return dEPS;}
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);
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);
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);
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);
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);
90 inline float effects_sqrt(float aValue)
94 inline double effects_sqrt(double aValue)
99 template<class T> inline bool EffectsEqual(const T& aLhv, const T& aRhv, const T& aEpsilon = effects_epsilon<T>::epsilon())
103 inline bool EffectsEqual(const float& aLhv, const float& aRhv, const float& aEpsilon)
105 return (aLhv + aEpsilon >= aRhv) && (aLhv - aEpsilon <= aRhv);
107 inline bool EffectsEqual(const double& aLhv, const double& aRhv, const double& aEpsilon)
109 return (aLhv + aEpsilon >= aRhv) && (aLhv - aEpsilon <= aRhv);
112 inline float effects_cos(float aAngle)
116 inline double effects_cos(double aAngle)
120 inline float effects_acos(float aAngle)
122 return acosf(aAngle);
124 inline double effects_acos(double aAngle)
129 inline float effects_sin(float aAngle)
133 inline double effects_sin(double aAngle)
138 inline float effects_asin(float aAngle)
140 return asinf(aAngle);
142 inline double effects_asin(double aAngle)
147 template<class T> inline T EffectsAbs(const T& aValue)
151 inline float EffectsAbs(float aValue)
153 return fabsf(aValue);
155 inline double EffectsAbs(double aValue)
160 inline float effects_atan2(float x, float y)
164 inline double effects_atan2(double x, double y)
169 inline float effects_atan(float val)
173 inline double effects_atan(double val)
178 template<class T> inline void EffectsSwap(T& aLhv, T& aRhv)
184 inline void EffectsSwap(float& aLhv, float& aRhv)
186 std::swap(aLhv, aRhv);
188 inline void EffectsSwap(double& aLhv, double& aRhv)
190 std::swap(aLhv, aRhv);
193 template<class T> inline T effects_clamp(const T& aValue, const T& aMin, const T& aMax)
201 inline float effects_clamp(const float& aValue, const float& aMin, const float& aMax)
209 inline double effects_clamp(const double& aValue, const double& aMin, const double& aMax)
218 template<class T> inline T effects_lerp(const T& aFrom, const T& aTo, const T& aCoeff)
220 return aFrom + (aTo - aFrom) * aCoeff;
222 inline float effects_lerp(const float& aFrom, const float& aTo, const float& aCoeff)
224 return aFrom + (aTo - aFrom) * aCoeff;
226 inline double effects_lerp(const double& aFrom, const double& aTo, const double& aCoeff)
228 return aFrom + (aTo - aFrom) * aCoeff;
230 inline int effects_lerp(const int& aFrom, const int& aTo, const int& aCoeff)
232 return aFrom + (((aTo - aFrom) * aCoeff) >> 8);
234 inline unsigned int effects_lerp(const unsigned int& aFrom, const unsigned int& aTo, const unsigned int& aCoeff)
236 return aFrom + (((aTo - aFrom) * aCoeff) >> 8);
239 template<class T> inline T EffectsMin(const T& a1, const T& a2)
245 template<class T> inline T EffectsMin3(const T& a1, const T& a2, const T& a3)
247 return EffectsMin(EffectsMin(a1, a2), a3);
249 template<class T> inline T EffectsMax(const T& a1, const T& a2)
255 template<class T> inline T EffectsMax3(const T& a1, const T& a2, const T& a3)
257 return EffectsMax(EffectsMax(a1, a2), a3);
259 } } } } //Tizen::Ui::Effects::_Utils
261 #endif //_FUI_EFFECTS_INTERNAL_UTILS_ADAPTER_FUNCTIONS_H_