Tizen 2.1 base
[framework/osp/uifw.git] / src / graphics / FGrpFloatVector4.cpp
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        FGrpFloatVector4.cpp
20  * @brief       This is the implementation for %FloatVector4 class.
21  */
22
23 #include <FGrpFloatVector4.h>
24 #include <FGrpFloatPoint3.h>
25 #include <FBaseFloat.h>
26 #include <FBaseSysLog.h>
27
28
29 namespace Tizen { namespace Graphics
30 {
31 FloatVector4::FloatVector4(void)
32         : __pImpl(null)
33 {
34         x = 0.0f;
35         y = 0.0f;
36         z = 0.0f;
37         w = 0.0f;
38 }
39
40 FloatVector4::FloatVector4(const FloatVector4& rhs)
41         : __pImpl(null)
42 {
43         x = rhs.x;
44         y = rhs.y;
45         z = rhs.z;
46         w = rhs.w;
47 }
48
49 FloatVector4::FloatVector4(const FloatPoint3& point)
50         : __pImpl(null)
51 {
52         x = point.x;
53         y = point.y;
54         z = point.z;
55         w = 1.0f;
56 }
57
58 FloatVector4::FloatVector4(const float vector[4])
59         : __pImpl(null)
60 {
61         this->x = vector[0];
62         this->y = vector[1];
63         this->z = vector[2];
64         this->w = vector[3];
65 }
66
67 FloatVector4::FloatVector4(float x, float y, float z, float w)
68         : __pImpl(null)
69 {
70         this->x = x;
71         this->y = y;
72         this->z = z;
73         this->w = w;
74 }
75
76 FloatVector4::~FloatVector4(void)
77 {
78 }
79
80 bool
81 FloatVector4::operator ==(const FloatVector4& rhs) const
82 {
83         if (this == &rhs)
84         {
85                 return true;
86         }
87
88         return (x == rhs.x && y == rhs.y && z == rhs.z && w == rhs.w);
89 }
90
91 FloatVector4&
92 FloatVector4::operator =(const FloatVector4& rhs)
93 {
94         if (this != &rhs)
95         {
96                 x = rhs.x;
97                 y = rhs.y;
98                 z = rhs.z;
99                 w = rhs.w;
100         }
101
102         return *this;
103 }
104
105 FloatVector4
106 FloatVector4::operator *(float value) const
107 {
108         return FloatVector4(x * value, y * value, z * value, w * value);
109 }
110
111 FloatVector4
112 FloatVector4::operator /(float value) const
113 {
114         return FloatVector4(x / value, y / value, z / value, w / value);
115 }
116
117 FloatVector4
118 FloatVector4::operator +(const FloatVector4& rhs) const
119 {
120         return FloatVector4(x + rhs.x, y + rhs.y, z + rhs.z, w + rhs.w);
121 }
122
123 FloatVector4
124 FloatVector4::operator -(const FloatVector4& rhs) const
125 {
126         return FloatVector4(x - rhs.x, y - rhs.y, z - rhs.z, w - rhs.w);
127 }
128
129 FloatVector4&
130 FloatVector4::operator +=(const FloatVector4& rhs)
131 {
132         this->x += rhs.x;
133         this->y += rhs.y;
134         this->z += rhs.z;
135         this->w += rhs.w;
136
137         return *this;
138 }
139
140 FloatVector4&
141 FloatVector4::operator -=(const FloatVector4& rhs)
142 {
143         this->x -= rhs.x;
144         this->y -= rhs.y;
145         this->z -= rhs.z;
146         this->w -= rhs.w;
147
148         return *this;
149 }
150
151 float
152 FloatVector4::DotProduct(const FloatVector4& rhs) const
153 {
154         return ((x * rhs.x) +
155                         (y * rhs.y) +
156                         (z * rhs.z) +
157                         (w * rhs.w));
158 }
159
160 float
161 FloatVector4::operator *(const FloatVector4& rhs) const
162 {
163         return DotProduct(rhs);
164 }
165
166 FloatVector4
167 operator *(const float& value, const FloatVector4& rhs)
168 {
169         return rhs * value;
170 }
171
172 FloatVector4
173 operator /(const float& value, const FloatVector4& rhs)
174 {
175         return rhs / value;
176 }
177
178 bool
179 FloatVector4::Equals(const Tizen::Base::Object& obj) const
180 {
181         const FloatVector4* pVector = dynamic_cast <const FloatVector4*>(&obj);
182
183         if (pVector == null)
184         {
185                 return false;
186         }
187
188         return (*this == *pVector);
189 }
190
191 int
192 FloatVector4::GetHashCode(void) const
193 {
194         return (Tizen::Base::Float::GetHashCode(x) +
195                         Tizen::Base::Float::GetHashCode(y) +
196                         Tizen::Base::Float::GetHashCode(z) +
197                         Tizen::Base::Float::GetHashCode(w));
198 }
199
200 float
201 FloatVector4::GetLength(void) const
202 {
203         return sqrt((x * x) + (y * y) + (z * z) + (w * w));
204 }
205
206 FloatVector4
207 FloatVector4::GetNormal(void) const
208 {
209         float length = GetLength();
210
211         return (*this / length);
212 }
213
214 void
215 FloatVector4::Normalize(void)
216 {
217         float length = GetLength();
218
219         x /= length;
220         y /= length;
221         z /= length;
222         w /= length;
223 }
224
225 }} // Tizen::Graphics