TGUI  v0.5.2
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
Vectors.hpp
1 //
3 // TGUI - Texus's Graphical User Interface
4 // Copyright (C) 2012 Bruno Van de Velde (VDV_B@hotmail.com)
5 //
6 // This software is provided 'as-is', without any express or implied warranty.
7 // In no event will the authors be held liable for any damages arising from the use of this software.
8 //
9 // Permission is granted to anyone to use this software for any purpose,
10 // including commercial applications, and to alter it and redistribute it freely,
11 // subject to the following restrictions:
12 //
13 // 1. The origin of this software must not be misrepresented;
14 // you must not claim that you wrote the original software.
15 // If you use this software in a product, an acknowledgment
16 // in the product documentation would be appreciated but is not required.
17 //
18 // 2. Altered source versions must be plainly marked as such,
19 // and must not be misrepresented as being the original software.
20 //
21 // 3. This notice may not be removed or altered from any source distribution.
22 //
24 
25 
26 #ifndef _TGUI_VECTORS_INCLUDED_
27 #define _TGUI_VECTORS_INCLUDED_
28 
30 
31 namespace tgui
32 {
34 
35  template <typename T>
36  struct TGUI_API Vector4
37  {
41  Vector4() :
42  x1(0),
43  x2(0),
44  x3(0),
45  x4(0)
46  {
47  }
48 
49 
53  Vector4(T X1, T X2, T X3, T X4) :
54  x1(X1),
55  x2(X2),
56  x3(X3),
57  x4(X4)
58  {
59  }
60 
61 
65  template <typename U>
66  explicit Vector4(const Vector4<U>& vector) :
67  x1(static_cast<T>(vector.x1)),
68  x2(static_cast<T>(vector.x2)),
69  x3(static_cast<T>(vector.x3)),
70  x4(static_cast<T>(vector.x4))
71  {
72  }
73 
74 
76  T x1;
77 
79  T x2;
80 
82  T x3;
83 
85  T x4;
86  };
87 
88 
90  // Overload of unary operator -
92  template <typename T>
93  inline Vector4<T> operator -(const Vector4<T>& right)
94  {
95  return Vector4<T>(-right.x1, -right.x2, -right.x3, -right.x4);
96  }
97 
98 
100  // Overload of binary operator +=
102  template <typename T>
103  inline Vector4<T>& operator +=(Vector4<T>& left, const Vector4<T>& right)
104  {
105  left.x1 += right.x1;
106  left.x2 += right.x2;
107  left.x3 += right.x3;
108  left.x4 += right.x4;
109 
110  return left;
111  }
112 
113 
115  // Overload of binary operator -=
117  template <typename T>
118  inline Vector4<T>& operator -=(Vector4<T>& left, const Vector4<T>& right)
119  {
120  left.x1 -= right.x1;
121  left.x2 -= right.x2;
122  left.x3 -= right.x3;
123  left.x4 -= right.x4;
124 
125  return left;
126  }
127 
128 
130  // Overload of binary operator +
132  template <typename T>
133  inline Vector4<T> operator +(const Vector4<T>& left, const Vector4<T>& right)
134  {
135  return Vector4<T>(left.x1 + right.x1, left.x2 + right.x2, left.x3 + right.x3, left.x4 + right.x4);
136  }
137 
138 
140  // Overload of binary operator -
142  template <typename T>
143  inline Vector4<T> operator -(const Vector4<T>& left, const Vector4<T>& right)
144  {
145  return Vector4<T>(left.x1 - right.x1, left.x2 - right.x2, left.x3 - right.x3, left.x4 - right.x4);
146  }
147 
148 
150  // Overload of binary operator *
152  template <typename T>
153  inline Vector4<T> operator *(const Vector4<T>& left, T right)
154  {
155  return Vector4<T>(left.x1 * right, left.x2 * right, left.x3 * right, left.x4 * right);
156  }
157 
158 
160  // Overload of binary operator *
162  template <typename T>
163  inline Vector4<T> operator *(T left, const Vector4<T>& right)
164  {
165  return Vector4<T>(right.x1 * left, right.x1 * left, right.x3 * left, right.x4 * left);
166  }
167 
168 
170  // Overload of binary operator *=
172  template <typename T>
173  inline Vector4<T>& operator *=(Vector4<T>& left, T right)
174  {
175  left.x1 *= right;
176  left.x2 *= right;
177  left.x3 *= right;
178  left.x4 *= right;
179 
180  return left;
181  }
182 
183 
185  // Overload of binary operator /
187  template <typename T>
188  inline Vector4<T> operator /(const Vector4<T>& left, T right)
189  {
190  return Vector4<T>(left.x1 / right, left.x2 / right, left.x3 / right, left.x4 / right);
191  }
192 
193 
195  // Overload of binary operator /=
197  template <typename T>
198  inline Vector4<T>& operator /=(Vector4<T>& left, T right)
199  {
200  left.x1 /= right;
201  left.x2 /= right;
202  left.x3 /= right;
203  left.x4 /= right;
204 
205  return left;
206  }
207 
208 
210  // Overload of binary operator ==
212  template <typename T>
213  inline bool operator ==(const Vector4<T>& left, const Vector4<T>& right)
214  {
215  return (left.x1 == right.x1) && (left.x2 == right.x2) && (left.x3 == right.x3) && (left.x4 == right.x4);
216  }
217 
218 
220  // Overload of binary operator !=
222  template <typename T>
223  inline bool operator !=(const Vector4<T>& left, const Vector4<T>& right)
224  {
225  return (left.x1 != right.x1) || (left.x2 != right.x2) || (left.x3 != right.x3) || (left.x4 != right.x4);
226  }
227 
228 
230 
231  typedef sf::Vector2<float> Vector2f;
232  typedef sf::Vector2<int> Vector2i;
233  typedef sf::Vector2<unsigned int> Vector2u;
234 
235  typedef sf::Vector3<float> Vector3f;
236  typedef sf::Vector3<int> Vector3i;
237  typedef sf::Vector3<unsigned int> Vector3u;
238 
239  typedef Vector4<float> Vector4f;
240  typedef Vector4<int> Vector4i;
241  typedef Vector4<unsigned int> Vector4u;
242 
244 }
245 
247 
248 #endif //_TGUI_VECTORS_INCLUDED_
Vector4()
Default constructor.
Definition: Vectors.hpp:41
T x2
Member data.
Definition: Vectors.hpp:79
T x4
Member data.
Definition: Vectors.hpp:85
T x1
Member data.
Definition: Vectors.hpp:76
T x3
Member data.
Definition: Vectors.hpp:82
Definition: Vectors.hpp:36
Vector4(T X1, T X2, T X3, T X4)
Construct the vector from its coordinates.
Definition: Vectors.hpp:53
Vector4(const Vector4< U > &vector)
Construct the vector from another type of vector.
Definition: Vectors.hpp:66