Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / effects / inc / utils / FUiEffects_UtilsMatrix2.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_UtilsMatrix2.h
20  * @brief      The Matrix2 class
21  *
22  */
23
24 #ifndef _FUI_EFFECTS_INTERNAL_UTILS_MATRIX2_H_
25 #define _FUI_EFFECTS_INTERNAL_UTILS_MATRIX2_H_
26
27 #include "FUiEffects_UtilsAdapterFunctions.h"
28
29 namespace Tizen { namespace Ui { namespace Effects { namespace _Utils
30 {
31         template<class T> class _Vector2;
32         template<class T> class Quaternion;
33
34         template<class T> class Matrix2
35         {
36             private:
37                 typedef Matrix2<T> SelfType;
38
39             public:
40                 _Vector2<T> i;
41                 _Vector2<T> j;
42
43                 inline Matrix2();
44                 inline explicit Matrix2(const T& aValue);
45                 inline explicit Matrix2(const T* aValue);
46                 inline Matrix2(const SelfType& aOther);
47                 inline Matrix2(const _Vector2<T>& aI, const _Vector2<T>& aJ);
48                 inline Matrix2(const T& a11, const T& a12,
49                     const T& a21, const T& a22);
50
51                 inline SelfType& operator=(const SelfType& aRhv);
52
53                 inline SelfType& set(const T& aValue);
54                 inline SelfType& set(const T* aValue);
55                 inline SelfType& set(const SelfType& aOther);
56                 inline SelfType& set(const _Vector2<T>& aI, const _Vector2<T>& aJ);
57                 inline SelfType& set(const T& a11, const T& a12,
58                     const T& a21, const T& a22);
59
60                 inline SelfType& identity();
61                 inline static const SelfType& getIdentity();
62                 inline bool isIdentity() const;
63
64                 inline SelfType operator-() const;
65                 inline SelfType& inverse();
66                 inline SelfType getInversed() const;
67                 inline SelfType& transpose();
68                 inline SelfType getTransposed() const;
69
70                 inline SelfType& operator+=(const SelfType& aRhv);
71                 inline SelfType& operator+=(const T& aRhv);
72                 inline SelfType& operator-=(const SelfType& aRhv);
73                 inline SelfType& operator-=(const T& aRhv);
74                 inline SelfType& operator*=(const SelfType& aRhv);
75                 inline SelfType& operator*=(const T& aRhv);
76                 inline SelfType& operator/=(const T& aRhv);
77                 inline SelfType GetMultipliedByMember(const SelfType& aRhv) const;
78                 inline SelfType& multiplyByMember(const SelfType& aRhv);
79                 static inline SelfType createMultipliedByMember(const SelfType& aLhv, const SelfType& aRhv);
80                 inline SelfType getDividedByMember(const SelfType& aRhv) const;
81                 inline SelfType& divideByMember(const SelfType& aRhv);
82                 static inline SelfType createDividedByMember(const SelfType& aLhv, const SelfType& aRhv);
83
84                 inline T* getPointer();
85                 inline const T* getPointer() const;
86                 inline T& get(unsigned int aRow, unsigned int aColumn);
87                 inline const T& get(unsigned int aRow, unsigned int aColumn) const;
88                 inline T& get(unsigned int aAbsIndex);
89                 inline const T& get(unsigned int aAbsIndex) const;
90                 inline SelfType& set(unsigned int aRow, unsigned int aColumn, const T& aValue);
91                 inline SelfType& set(unsigned int aAbsIndex, const T& aValue);
92                 inline _Vector2<T>& getRow(unsigned int aRow);
93                 inline const _Vector2<T>& getRow(unsigned int aRow) const;
94                 inline SelfType& setRow(unsigned int aRow, const _Vector2<T>& aValue);
95                 inline _Vector2<T> getColumn(unsigned int aColumn) const;
96                 inline SelfType& setColumn(unsigned int aColumn, const _Vector2<T>& aValue);
97                 inline T& operator()(unsigned int aRow, unsigned int aColumn);
98                 inline const T& operator()(unsigned int aRow, unsigned int aColumn) const;
99                 inline T& operator()(unsigned int aAbsIndex);
100                 inline const T& operator()(unsigned int aAbsIndex) const;
101                 inline T& operator[](unsigned int aAbsIndex);
102                 inline const T& operator[](unsigned int aAbsIndex) const;
103
104                 inline SelfType& lerp(const SelfType& aTo, const T& aCoeff);
105                 inline SelfType getLerped(const SelfType& aTo, const T& aCoeff) const;
106                 inline SelfType& makeLerped(const SelfType& aFrom, const SelfType& aTo, const T& aCoeff);
107                 static inline SelfType createLerped(const SelfType& aFrom, const SelfType& aTo, const T& aCoeff);
108                 inline SelfType& slerp(const SelfType& aTo, const T& aCoeff);
109                 inline SelfType getSlerped(const SelfType& aTo, const T& aCoeff) const;
110                 inline SelfType& makeSlerped(const SelfType& aFrom, const SelfType& aTo, const T& aCoeff);
111                 static inline SelfType createSlerped(const SelfType& aFrom, const SelfType& aTo, const T& aCoeff);
112
113                 inline T determinant() const;
114
115                 inline _Vector2<T>& applyTransform(_Vector2<T>& aVector) const;
116                 inline _Vector2<T> getAppliedTransform(const _Vector2<T>& aVector) const;
117
118                 inline SelfType& makeRotation(const T& aAngleRAD);
119                 inline SelfType& rotate(const T& aAngleRAD);
120                 static inline SelfType createRotation(const T& aAngleRAD);
121                 inline T getRotationAngle() const;
122
123                 inline SelfType& makeScale(const T& aX, const T& aY);
124                 inline SelfType& makeScale(const _Vector2<T>& aScale);
125                 static inline SelfType createScale(const T& aX, const T& aY);
126                 static inline SelfType createScale(const _Vector2<T>& aScale);
127                 inline SelfType& scale(const T& aX, const T& aY);
128                 inline SelfType& scale(const _Vector2<T>& aScale);
129         };
130
131         typedef Matrix2<float> Mat2f;
132         typedef Matrix2<double> Mat2d;
133
134         template<class T> inline Matrix2<T> operator+(const Matrix2<T>& aLhv, const Matrix2<T>& aRhv);
135         template<class T> inline Matrix2<T> operator+(const Matrix2<T>& aLhv, const T& aRhv);
136         template<class T> inline Matrix2<T> operator+(const T& aLhv, const Matrix2<T>& aRhv);
137         template<class T> inline Matrix2<T> operator-(const Matrix2<T>& aLhv, const Matrix2<T>& aRhv);
138         template<class T> inline Matrix2<T> operator-(const Matrix2<T>& aLhv, const T& aRhv);
139         template<class T> inline Matrix2<T> operator-(const T& aLhv, const Matrix2<T>& aRhv);
140         template<class T> inline Matrix2<T> operator*(const Matrix2<T>& aLhv, const Matrix2<T>& aRhv);
141         template<class T> inline Matrix2<T> operator*(const Matrix2<T>& aLhv, const T& aRhv);
142         template<class T> inline Matrix2<T> operator*(const T& aLhv, const Matrix2<T>& aRhv);
143         template<class T> inline _Vector2<T> operator*(const Matrix2<T>& aLhv, const _Vector2<T>& aRhv);
144         template<class T> inline _Vector2<T> operator*(const _Vector2<T>& aLhv, const Matrix2<T>& aRhv);
145         template<class T> inline Matrix2<T> operator/(const Matrix2<T>& aLhv, const T& aRhv);
146         template<class T> inline bool operator==(const Matrix2<T>& aLhv, const Matrix2<T>& aRhv);
147         template<class T> inline bool operator==(const T& aLhv, const Matrix2<T>& aRhv);
148         template<class T> inline bool operator==(const Matrix2<T>& aLhv, const T& aRhv);
149         template<class T> inline bool operator!=(const Matrix2<T>& aLhv, const Matrix2<T>& aRhv);
150         template<class T> inline bool operator!=(const T& aLhv, const Matrix2<T>& aRhv);
151         template<class T> inline bool operator!=(const Matrix2<T>& aLhv, const T& aRhv);
152
153         template<class T> Matrix2<T>::Matrix2() {}
154
155         template<class T> Matrix2<T>::Matrix2(const T& aValue):
156             i(aValue), j(aValue) {}
157
158         template<class T> Matrix2<T>::Matrix2(const T* aValue):
159             i(aValue[0], aValue[1]), j(aValue[2], aValue[3]) {}
160
161         template<class T> Matrix2<T>::Matrix2(const Matrix2<T>& aOther):
162             i(aOther.i), j(aOther.j) {}
163
164         template<class T> Matrix2<T>::Matrix2(const _Vector2<T>& aI, const _Vector2<T>& aJ):
165             i(aI), j(aJ) {}
166
167         template<class T> Matrix2<T>::Matrix2(  const T& a11, const T& a12,
168                                                 const T& a21, const T& a22):
169             i(a11, a12), j(a21, a22) {}
170
171         template<class T> Matrix2<T>& Matrix2<T>::operator=(const Matrix2<T>& aRhv)
172         {
173             i = aRhv.i;
174             j = aRhv.j;
175             return *this;
176         }
177
178         template<class T> Matrix2<T>& Matrix2<T>::set(const T& aValue)
179         {
180             i.set(aValue);
181             j.set(aValue);
182             return *this;
183         }
184
185         template<class T> Matrix2<T>& Matrix2<T>::set(const T* aValue)
186         {
187             i.set(aValue[0], aValue[1]);
188             j.set(aValue[2], aValue[3]);
189             return *this;
190         }
191
192         template<class T> Matrix2<T>& Matrix2<T>::set(const Matrix2<T>& aOther)
193         {
194             i = aOther.i;
195             j = aOther.j;
196             return *this;
197         }
198
199         template<class T> Matrix2<T>& Matrix2<T>::set(const _Vector2<T>& aI, const _Vector2<T>& aJ)
200         {
201             i = aI;
202             j = aJ;
203             return *this;
204         }
205
206         template<class T> Matrix2<T>& Matrix2<T>::set(const T& a11, const T& a12, const T& a21, const T& a22)
207         {
208             i.set(a11, a12);
209             j.set(a21, a22);
210             return *this;
211         }
212
213
214         template<class T> inline Matrix2<T>& Matrix2<T>::identity()
215         {
216             return operator=(getIdentity());
217         }
218
219         template<class T> inline const Matrix2<T>& Matrix2<T>::getIdentity()
220         {
221             static Matrix2<T> identityMatrix(
222                                                 T(1.0f), T(0.0f),
223                                                 T(0.0f), T(1.0f));
224             return identityMatrix;
225         }
226
227         template<class T> inline bool Matrix2<T>::isIdentity() const
228         {
229             return *this == getIdentity();
230         }
231
232         template<class T> inline Matrix2<T> Matrix2<T>::operator-() const
233         {
234             return Matrix2<T>(-i, -j);
235         }
236
237         template<class T> inline Matrix2<T>& Matrix2<T>::inverse()
238         {
239             static const T t0(0.0f);
240             static const T t1(1.0f);
241
242             T s = determinant();
243             if(EffectsEqual(s, t0))
244                 return *this;
245             T inv_det(t1 / s);
246             return set(j.y * inv_det, -i.y * inv_det, -j.x * inv_det, i.x * inv_det);
247         }
248         template<class T> inline Matrix2<T> Matrix2<T>::getInversed() const
249         {
250             static const T t0(0.0f);
251             static const T t1(1.0f);
252
253             T s = determinant();
254             if(EffectsEqual(s, t0)) return *this;
255             T inv_det(t1 / s);
256             return Matrix2<T>(j.y * inv_det, -i.y * inv_det, -j.x * inv_det, i.x * inv_det);
257         }
258
259         template <class T> inline T Matrix2<T>::determinant() const
260         {
261             return i.x * j.y - j.x * i.y;
262         }
263
264         template<class T> inline Matrix2<T>& Matrix2<T>::transpose()
265         {
266             EffectsSwap(i.y, j.x);
267             return *this;
268         }
269
270         template<class T> inline Matrix2<T> Matrix2<T>::getTransposed() const
271         {
272             return Matrix2<T>(i.x, j.x, i.y, j.y);
273         }
274
275         template<class T> inline Matrix2<T>& Matrix2<T>::operator+=(const Matrix2<T>& aRhv)
276         {
277             i += aRhv.i;
278             j += aRhv.j;
279             return *this;
280         }
281         template<class T> inline Matrix2<T>& Matrix2<T>::operator+=(const T& aRhv)
282         {
283             i += aRhv;
284             j += aRhv;
285             return *this;
286         }
287         template<class T> inline Matrix2<T>& Matrix2<T>::operator-=(const Matrix2<T>& aRhv)
288         {
289             i -= aRhv.i;
290             j -= aRhv.j;
291             return *this;
292         }
293         template<class T> inline Matrix2<T>& Matrix2<T>::operator-=(const T& aRhv)
294         {
295             i -= aRhv;
296             j -= aRhv;
297             return *this;
298         }
299         template<class T> inline Matrix2<T>& Matrix2<T>::operator*=(const T& aRhv)
300         {
301             i *= aRhv;
302             j *= aRhv;
303             return *this;
304         }
305
306         template<class T> inline Matrix2<T> Matrix2<T>::GetMultipliedByMember(const Matrix2<T>& aRhv) const
307         {
308             return Matrix2<T>(i * aRhv.i, j * aRhv.j);
309         }
310
311         template<class T> inline Matrix2<T>& Matrix2<T>::multiplyByMember(const Matrix2<T>& aRhv)
312         {
313             i *= aRhv.i;
314             j *= aRhv.j;
315             return *this;
316         }
317
318         template<class T> inline Matrix2<T> Matrix2<T>::createMultipliedByMember(const Matrix2<T>& aLhv, const Matrix2<T>& aRhv)
319         {
320             return Matrix2<T>(aLhv.i * aRhv.i, aLhv.j * aRhv.j);
321         }
322
323         template<class T> inline Matrix2<T>& Matrix2<T>::operator*=(const Matrix2<T>& aRhv)
324         {
325             set(
326                 i.x * aRhv.i.x + i.y * aRhv.j.x,
327                 i.x * aRhv.i.y + i.y * aRhv.j.y,
328
329                 j.x * aRhv.i.x + j.y * aRhv.j.x,
330                 j.x * aRhv.i.y + j.y * aRhv.j.y);
331             return *this;
332         }
333
334         template<class T> inline Matrix2<T> Matrix2<T>::getDividedByMember(const Matrix2<T>& aRhv) const
335         {
336             return Matrix2<T>(i / aRhv.i, j / aRhv.j);
337         }
338
339         template<class T> inline Matrix2<T>& Matrix2<T>::divideByMember(const Matrix2<T>& aRhv)
340         {
341             i /= aRhv.i;
342             j /= aRhv.j;
343             return *this;
344         }
345         template<class T> inline Matrix2<T> Matrix2<T>::createDividedByMember(const Matrix2<T>& aLhv, const Matrix2<T>& aRhv)
346         {
347             return Matrix2<T>(aLhv.i / aRhv.i, aLhv.j / aRhv.j);
348         }
349
350         template<class T> inline Matrix2<T>& Matrix2<T>::operator/=(const T& aRhv)
351         {
352             i /= aRhv;
353             j /= aRhv;
354             return *this;
355         }
356
357         template<class T> inline T* Matrix2<T>::getPointer()
358         {
359             return i.getPointer();
360         }
361
362         template<class T> inline const T* Matrix2<T>::getPointer() const
363         {
364             return i.getPointer();
365         }
366
367         template<class T> inline T& Matrix2<T>::get(unsigned int aRow, unsigned int aColumn)
368         {
369             return operator()(aRow, aColumn);
370         }
371
372         template<class T> inline const T& Matrix2<T>::get(unsigned int aRow, unsigned int aColumn) const
373         {
374             return operator()(aRow, aColumn);
375         }
376
377         template<class T> inline T& Matrix2<T>::get(unsigned int aAbsIndex)
378         {
379             return operator()(aAbsIndex);
380         }
381
382         template<class T> inline const T& Matrix2<T>::get(unsigned int aAbsIndex) const
383         {
384             return operator()(aAbsIndex);
385         }
386
387         template<class T> inline _Vector2<T>& Matrix2<T>::getRow(unsigned int aRow)
388         {
389             if(1 == aRow)
390                 return j;
391             return i;
392         }
393
394         template<class T> inline const _Vector2<T>& Matrix2<T>::getRow(unsigned int aRow) const
395         {
396             if(1 == aRow)
397                 return j;
398             return i;
399         }
400
401         template<class T> inline _Vector2<T> Matrix2<T>::getColumn(unsigned int aColumn) const
402         {
403             if(1 == aColumn)
404                 return _Vector2<T>(i.y, j.y);
405             return _Vector2<T>(i.x, j.x);
406         }
407
408         template<class T> inline T& Matrix2<T>::operator()(unsigned int aRow, unsigned int aColumn)
409         {
410             return operator[]((aRow << 1) + aColumn);
411         }
412
413         template<class T> inline const T& Matrix2<T>::operator()(unsigned int aRow, unsigned int aColumn) const
414         {
415             return operator[]((aRow << 1) + aColumn);
416         }
417
418         template<class T> inline T& Matrix2<T>::operator()(unsigned int aAbsIndex)
419         {
420             return operator[](aAbsIndex);
421         }
422
423         template<class T> inline const T& Matrix2<T>::operator()(unsigned int aAbsIndex) const
424         {
425             return operator[](aAbsIndex);
426         }
427
428         template<class T> inline T& Matrix2<T>::operator[](unsigned int aAbsIndex)
429         {
430             return getPointer()[aAbsIndex];
431         }
432
433         template<class T> inline const T& Matrix2<T>::operator[](unsigned int aAbsIndex) const
434         {
435             return getPointer()[aAbsIndex];
436         }
437
438         template<class T> inline Matrix2<T>& Matrix2<T>::setColumn(unsigned int aColumn, const _Vector2<T>& aValue)
439         {
440             switch(aColumn)
441             {
442             case 0:
443                 i.x = aValue.x;
444                 j.x = aValue.y;
445                 break;
446             case 1:
447                 i.y = aValue.x;
448                 j.y = aValue.y;
449                 break;
450             }
451
452             return *this;
453         }
454
455         template<class T> inline Matrix2<T>& Matrix2<T>::setRow(unsigned int aRow, const _Vector2<T>& aValue)
456         {
457             switch(aRow)
458             {
459             case 0:
460                 i = aValue;
461                 break;
462             case 1:
463                 j = aValue;
464                 break;
465             }
466
467             return *this;
468         }
469
470         template<class T> inline Matrix2<T>& Matrix2<T>::set(unsigned int aRow, unsigned int aColumn, const T& aValue)
471         {
472             operator()(aRow, aColumn) = aValue;
473             return *this;
474         }
475
476         template<class T> inline Matrix2<T>& Matrix2<T>::set(unsigned int aAbsIndex, const T& aValue)
477         {
478             operator()(aAbsIndex) = aValue;
479             return *this;
480         }
481
482         template<class T> inline Matrix2<T>& Matrix2<T>::lerp(const Matrix2<T>& aTo, const T& aCoeff)
483         {
484             i.lerp(aTo.i, aCoeff);
485             j.lerp(aTo.j, aCoeff);
486             return *this;
487         }
488
489         template<class T> inline Matrix2<T> Matrix2<T>::getLerped(const Matrix2<T>& aTo, const T& aCoeff) const
490         {
491             Matrix2<T> result(i.getLerped(aTo.i, aCoeff), j.getLerped(aTo.j, aCoeff));
492             return result;
493         }
494
495         template<class T> inline Matrix2<T>& Matrix2<T>::makeLerped(const Matrix2<T>& aFrom, const Matrix2<T>& aTo, const T& aCoeff)
496         {
497             i.makeLerped(aFrom.i, aTo.i, aCoeff);
498             j.makeLerped(aFrom.j, aTo.j, aCoeff);
499             return *this;
500         }
501         template<class T> inline Matrix2<T> Matrix2<T>::createLerped(const Matrix2<T>& aFrom, const Matrix2<T>& aTo, const T& aCoeff)
502         {
503             return Matrix2<T>().makeLerped(aFrom, aTo, aCoeff);
504         }
505
506         template<class T> inline Matrix2<T>& Matrix2<T>::slerp(const Matrix2<T>& aTo, const T& aCoeff)
507         {
508             makeRotation(effects_lerp(getRotationAngle(), aTo.getRotationAngle(), aCoeff));
509             return *this;
510         }
511
512         template<class T> inline Matrix2<T> Matrix2<T>::getSlerped(const Matrix2<T>& aTo, const T& aCoeff) const
513         {
514             Matrix2 result;
515             result.makeRotation(effects_lerp(getRotationAngle(), aTo.getRotationAngle(), aCoeff));
516             return result;
517         }
518
519         template<class T> inline Matrix2<T>& Matrix2<T>::makeSlerped(const Matrix2<T>& aFrom, const Matrix2<T>& aTo, const T& aCoeff)
520         {
521             makeRotation(effects_lerp(aFrom.getRotationAngle(), aTo.getRotationAngle(), aCoeff));
522             return *this;
523         }
524
525         template<class T> inline Matrix2<T> Matrix2<T>::createSlerped(const Matrix2<T>& aFrom, const Matrix2<T>& aTo, const T& aCoeff)
526         {
527             return Matrix2<T>().makeSlerped(aFrom, aTo, aCoeff);
528         }
529
530         template<class T> inline Matrix2<T>& Matrix2<T>::makeRotation(const T& aAngleRAD)
531         {
532             const T s = effects_sin(aAngleRAD);
533             const T c = effects_cos(aAngleRAD);
534             i.x = c;
535             i.y = s;
536             j.x = -s;
537             j.y = c;
538             return *this;
539         }
540
541         template<class T> inline Matrix2<T>& Matrix2<T>::rotate(const T& aAngleRAD)
542         {
543             const T s = effects_sin(aAngleRAD);
544             const T c = effects_cos(aAngleRAD);
545             const T ix = i.x * c - i.y * s;
546             const T iy = i.x * s + i.y * c;
547             const T jx = j.x * c - j.y * s;
548             const T jy = j.x * s + j.y * c;
549             i.x = ix;
550             i.y = iy;
551             j.x = jx;
552             j.y = jy;
553             return *this;
554         }
555         template<class T> inline Matrix2<T> Matrix2<T>::createRotation(const T& aAngleRAD)
556         {
557             return Matrix2<T>().makeRotation(aAngleRAD);
558         }
559
560         template<class T> inline T Matrix2<T>::getRotationAngle() const
561         {
562             static const T t0(0.0f);
563             static const T t1(1.0f);
564
565             static const _Vector2<T> orig_vector(t1, t0);
566             static const _Vector2<T> orig_vector_cross(t0, t1);
567
568             _Vector2<T> rotated(getAppliedTransform(orig_vector).normalize());
569             const T angleCos = effects_clamp(rotated.dot(orig_vector), -t1, t1);
570             const T angleCosCross = effects_clamp(rotated.dot(orig_vector_cross), -t1, t1);
571
572             if(angleCosCross > t0)
573                 return effects_acos(angleCos);
574             return -effects_acos(angleCos);
575         }
576
577         template<class T> inline Matrix2<T>& Matrix2<T>::makeScale(const T& aX, const T& aY)
578         {
579             i.x = aX;
580             j.y = aY;
581
582             i.y = j.x = T(0.0f);
583             return *this;
584         }
585         template<class T> inline Matrix2<T>& Matrix2<T>::makeScale(const _Vector2<T>& aScale)
586         {
587             return makeScale(aScale.x, aScale.y);
588         }
589         template<class T> inline Matrix2<T> Matrix2<T>::createScale(const T& aX, const T& aY)
590         {
591             return Matrix2<T>().makeScale(aX, aY);
592         }
593         template<class T> inline Matrix2<T> Matrix2<T>::createScale(const _Vector2<T>& aScale)
594         {
595             return Matrix2<T>().makeScale(aScale);
596         }
597
598         template<class T> inline Matrix2<T>& Matrix2<T>::scale(const T& aX, const T& aY)
599         {
600             i.x *= aX; i.y *= aY;
601             j.x *= aX; j.y *= aY;
602
603             return *this;
604         }
605         template<class T> inline Matrix2<T>& Matrix2<T>::scale(const _Vector2<T>& aScale)
606         {
607             return scale(aScale.x, aScale.y);
608         }
609
610         template<class T> inline _Vector2<T>& Matrix2<T>::applyTransform(_Vector2<T>& aVector) const
611         {
612             return aVector.set(
613                 aVector.x * i.x + aVector.y * j.x,
614                 aVector.x * i.y + aVector.y * j.y);
615         }
616
617         template<class T> inline _Vector2<T> Matrix2<T>::getAppliedTransform(const _Vector2<T>& aVector) const
618         {
619             return _Vector2<T>(
620                 aVector.x * i.x + aVector.y * j.x,
621                 aVector.x * i.y + aVector.y * j.y);
622         }
623
624         template<class T> inline bool isEqual(const Matrix2<T>& aLhv, const Matrix2<T>& aRhv, const T& aEpsilon = effects_epsilon<T>::epsilon())
625         {
626             return isEqual(aLhv.i, aRhv.i, aEpsilon) && isEqual(aLhv.j, aRhv.j, aEpsilon);
627         }
628         template<class T> inline Matrix2<T> operator+(const Matrix2<T>& aLhv, const Matrix2<T>& aRhv)
629         {
630             return Matrix2<T>(aLhv.i + aRhv.i, aLhv.j + aRhv.j);
631         }
632         template<class T> inline Matrix2<T> operator+(const Matrix2<T>& aLhv, const T& aRhv)
633         {
634             return Matrix2<T>(aLhv.i + aRhv, aLhv.j + aRhv);
635         }
636         template<class T> inline Matrix2<T> operator+(const T& aLhv, const Matrix2<T>& aRhv)
637         {
638             return Matrix2<T>(aLhv + aRhv.i, aLhv + aRhv.j);
639         }
640         template<class T> inline Matrix2<T> operator-(const Matrix2<T>& aLhv, const Matrix2<T>& aRhv)
641         {
642             return Matrix2<T>(aLhv.i - aRhv.i, aLhv.j - aRhv.j);
643         }
644         template<class T> inline Matrix2<T> operator-(const Matrix2<T>& aLhv, const T& aRhv)
645         {
646             return Matrix2<T>(aLhv.i - aRhv, aLhv.j - aRhv);
647         }
648         template<class T> inline Matrix2<T> operator-(const T& aLhv, const Matrix2<T>& aRhv)
649         {
650             return Matrix2<T>(aLhv - aRhv.i, aLhv - aRhv.j);
651         }
652         template<class T> inline Matrix2<T> operator*(const Matrix2<T>& aLhv, const Matrix2<T>& aRhv)
653         {
654             return Matrix2<T>(
655                 aLhv.i.x * aRhv.i.x + aLhv.i.y * aRhv.j.x,
656                 aLhv.i.x * aRhv.i.y + aLhv.i.y * aRhv.j.y,
657
658                 aLhv.j.x * aRhv.i.x + aLhv.j.y * aRhv.j.x,
659                 aLhv.j.x * aRhv.i.y + aLhv.j.y * aRhv.j.y);
660         }
661         template<class T> inline Matrix2<T> operator*(const Matrix2<T>& aLhv, const T& aRhv)
662         {
663             return Matrix2<T>(aLhv.i * aRhv, aLhv.j * aRhv);
664         }
665         template<class T> inline Matrix2<T> operator*(const T& aLhv, const Matrix2<T>& aRhv)
666         {
667             return Matrix2<T>(aLhv * aRhv.i, aLhv * aRhv.j);
668         }
669         template<class T> inline _Vector2<T> operator*(const _Vector2<T>& aLhv, const Matrix2<T>& aRhv)
670         {
671             return aRhv.getAppliedTransform(aLhv);
672         }
673         template<class T> inline _Vector2<T> operator*(const Matrix2<T>& aLhv, const _Vector2<T>& aRhv)
674         {
675             return _Vector2<T>(
676                 aLhv.i.x * aRhv.x + aLhv.i.y * aRhv.y,
677                 aLhv.j.x * aRhv.x + aLhv.j.y * aRhv.y);
678         }
679         template<class T> inline Matrix2<T> operator/(const Matrix2<T>& aLhv, const T& aRhv)
680         {
681             return Matrix2<T>(aLhv.i / aRhv, aLhv.j / aRhv);
682         }
683         template<class T> inline Matrix2<T> operator/(const T& aLhv, const Matrix2<T>& aRhv)
684         {
685             return Matrix2<T>(aLhv / aRhv.i, aLhv / aRhv.j);
686         }
687         template<class T> inline bool operator==(const Matrix2<T>& aLhv, const Matrix2<T>& aRhv)
688         {
689             return aLhv.i == aRhv.i && aLhv.j == aRhv.j;
690         }
691         template<class T> inline bool operator==(const Matrix2<T>& aLhv, const T& aRhv)
692         {
693             return aLhv.i == aRhv && aLhv.j == aRhv;
694         }
695         template<class T> inline bool operator==(const T& aLhv, const Matrix2<T>& aRhv)
696         {
697             return aLhv == aRhv.i && aLhv == aRhv.j;
698         }
699         template<class T> inline bool operator!=(const Matrix2<T>& aLhv, const Matrix2<T>& aRhv)
700         {
701             return !(aLhv == aRhv);
702         }
703         template<class T> inline bool operator!=(const Matrix2<T>& aLhv, const T& aRhv)
704         {
705             return !(aLhv == aRhv);
706         }
707         template<class T> inline bool operator!=(const T& aLhv, const Matrix2<T>& aRhv)
708         {
709             return !(aLhv == aRhv);
710         }
711 } } } } //Tizen::Ui::Effects::_Utils
712
713 #endif //_FUI_EFFECTS_INTERNAL_UTILS_MATRIX2_H_