Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / animations / FUiAnim_MatrixUtil.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        FUiAnim_MatrixUtil.h
20  * @brief       Header file of _MatrixUtil module
21  *
22  * This file contains declarations _MatrixUtil module.
23  */
24
25 #ifndef _FUI_ANIM_INTERNAL_MATRIX_UTIL_H_
26 #define _FUI_ANIM_INTERNAL_MATRIX_UTIL_H_
27
28 #include <FBaseSysLog.h>
29 #include <FGrpFloatMatrix4.h>
30 #include <FGrpFloatRectangle.h>
31 #include "FUi_Math.h"
32 #include "FUiAnim_TransformMatrix3Df.h"
33
34
35 namespace Tizen { namespace Ui { namespace Animations
36 {
37
38 inline bool
39 RectUtilIsEqual(const Tizen::Graphics::FloatRectangle& r1, const Tizen::Graphics::FloatRectangle& r2)
40 {
41         return (memcmp(&r1.x, &r2.x, sizeof(r1.x) * 4) == 0);
42 }
43
44 inline void
45 RectUtilCopy(Tizen::Graphics::FloatRectangle& d, const Tizen::Graphics::FloatRectangle& s)
46 {
47         memcpy(&d.x, &s.x, sizeof(d.x) * 4);
48 }
49
50 inline void
51 RectUtilMakeIntegral(Tizen::Graphics::FloatRectangle& rectangle)
52 {
53         if (unlikely(rectangle.IsEmpty()))
54                 return;
55
56         rectangle.width = ceilf(rectangle.x + rectangle.width);
57         rectangle.height = ceilf(rectangle.y + rectangle.height);
58
59         rectangle.x = floorf(rectangle.x);
60         rectangle.y = floorf(rectangle.y);
61
62         rectangle.width -= rectangle.x;
63         rectangle.height -= rectangle.y;
64 }
65
66 inline void
67 RectUtilIntersect(Tizen::Graphics::FloatRectangle& rectangle, const Tizen::Graphics::FloatRectangle& mask)
68 {
69         if (unlikely(rectangle.IsEmpty()) || unlikely(mask.IsEmpty()))
70                 return;
71
72         if (unlikely(rectangle.x >= mask.x + mask.width))
73                 return;
74
75         if (unlikely(rectangle.y >= mask.y + mask.height))
76                 return;
77
78         if (unlikely(rectangle.x + rectangle.width <= mask.x))
79                 return;
80
81         if (unlikely(rectangle.y + rectangle.height <= mask.y))
82                 return;
83
84
85         // intersected
86
87         rectangle.x = _Max(rectangle.x, mask.x);
88         rectangle.y = _Max(rectangle.y, mask.y);
89         rectangle.width = _Min(rectangle.x + rectangle.width, mask.x + mask.width) - rectangle.x;
90         rectangle.height = _Min(rectangle.y + rectangle.height, mask.y + mask.height) - rectangle.y;
91 }
92
93 inline void
94 RectUtilUnion(Tizen::Graphics::FloatRectangle& rectangle, const Tizen::Graphics::FloatRectangle& source)
95 {
96         if (rectangle.IsEmpty())
97         {
98                 if (source.IsEmpty())
99                         return;
100
101                 rectangle = source;
102                 return;
103         }
104         else
105         {
106                 if (source.IsEmpty())
107                         return;
108         }
109
110
111         // intersected
112         float x = _Min(rectangle.x, source.x);
113         float y = _Min(rectangle.y, source.y);
114         float width = _Max(rectangle.x + rectangle.width, source.x + source.width) - x;
115         float height = _Max(rectangle.y + rectangle.height, source.y + source.height) - y;
116
117         rectangle.SetBounds(x, y, width, height);
118 }
119
120
121 inline void
122 MatrixUtilCopy(Tizen::Graphics::FloatMatrix4& d, const Tizen::Graphics::FloatMatrix4& s)
123 {
124         memcpy(d.matrix, s.matrix, sizeof(d.matrix));
125 }
126
127 Matrix4Type _GetMatrix4Type(const Tizen::Graphics::FloatMatrix4& floatMatrix);
128 void _MatrixUtilSetIdentity(Tizen::Graphics::FloatMatrix4& m);
129 bool _MatrixUtilIsEqual(const Tizen::Graphics::FloatMatrix4& m1, const Tizen::Graphics::FloatMatrix4& m2);
130 void _MatrixUtilSetTranslation(Tizen::Graphics::FloatMatrix4& m, float tx, float ty, float tz);
131 void _MatrixUtilTransform(const Tizen::Graphics::FloatMatrix4& m, float* pX, float* pY, float* pZ);
132 void _MatrixUtilTranslate(Tizen::Graphics::FloatMatrix4& m, float tx, float ty, float tz);
133 bool _MatrixUtilIsTranslation(const Tizen::Graphics::FloatMatrix4& m);
134 void _MatrixUtilScale(Tizen::Graphics::FloatMatrix4& m, float sx, float sy, float sz);
135 void _MatrixUtilAtAnchor(Tizen::Graphics::FloatMatrix4& m, float x, float y, float z);
136 void _MatrixUtilRotate(Tizen::Graphics::FloatMatrix4& m, float angle, float x, float y, float z);
137 bool _MatrixUtilInvert(Tizen::Graphics::FloatMatrix4& m);
138 void _MatrixUtilMultiply(Tizen::Graphics::FloatMatrix4& d, const Tizen::Graphics::FloatMatrix4& m1, const Tizen::Graphics::FloatMatrix4& m2);
139
140
141 }}}             // Tizen::Ui::Animations
142
143 #endif //_FUI_ANIM_INTERNAL_MATRIX_UTIL_H_
144