Vector2.inl
1 //
3 // SFML - Simple and Fast Multimedia Library
4 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.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 
29 template <typename T>
31 x(0),
32 y(0)
33 {
34 
35 }
36 
37 
41 template <typename T>
43 x(X),
44 y(Y)
45 {
46 
47 }
48 
49 
53 template <typename T>
54 Vector2<T> operator -(const Vector2<T>& V)
55 {
56  return Vector2<T>(-V.x, -V.y);
57 }
58 
59 
63 template <typename T>
64 Vector2<T>& operator +=(Vector2<T>& V1, const Vector2<T>& V2)
65 {
66  V1.x += V2.x;
67  V1.y += V2.y;
68 
69  return V1;
70 }
71 
72 
76 template <typename T>
77 Vector2<T>& operator -=(Vector2<T>& V1, const Vector2<T>& V2)
78 {
79  V1.x -= V2.x;
80  V1.y -= V2.y;
81 
82  return V1;
83 }
84 
85 
89 template <typename T>
90 Vector2<T> operator +(const Vector2<T>& V1, const Vector2<T>& V2)
91 {
92  return Vector2<T>(V1.x + V2.x, V1.y + V2.y);
93 }
94 
95 
99 template <typename T>
100 Vector2<T> operator -(const Vector2<T>& V1, const Vector2<T>& V2)
101 {
102  return Vector2<T>(V1.x - V2.x, V1.y - V2.y);
103 }
104 
105 
109 template <typename T>
110 Vector2<T> operator *(const Vector2<T>& V, T X)
111 {
112  return Vector2<T>(V.x * X, V.y * X);
113 }
114 
115 
119 template <typename T>
120 Vector2<T> operator *(T X, const Vector2<T>& V)
121 {
122  return Vector2<T>(V.x * X, V.y * X);
123 }
124 
125 
129 template <typename T>
130 Vector2<T>& operator *=(Vector2<T>& V, T X)
131 {
132  V.x *= X;
133  V.y *= X;
134 
135  return V;
136 }
137 
138 
142 template <typename T>
143 Vector2<T> operator /(const Vector2<T>& V, T X)
144 {
145  return Vector2<T>(V.x / X, V.y / X);
146 }
147 
148 
152 template <typename T>
153 Vector2<T>& operator /=(Vector2<T>& V, T X)
154 {
155  V.x /= X;
156  V.y /= X;
157 
158  return V;
159 }
160 
161 
165 template <typename T>
166 bool operator ==(const Vector2<T>& V1, const Vector2<T>& V2)
167 {
168  return (V1.x == V2.x) && (V1.y == V2.y);
169 }
170 
171 
175 template <typename T>
176 bool operator !=(const Vector2<T>& V1, const Vector2<T>& V2)
177 {
178  return (V1.x != V2.x) || (V1.y != V2.y);
179 }
T x
X coordinate of the vector.
Definition: Vector2.hpp:59
Vector2()
Default constructor.
Definition: Vector2.inl:30
Vector2 is an utility class for manipulating 2 dimensional vectors.
Definition: Vector2.hpp:37
T y
Y coordinate of the vector.
Definition: Vector2.hpp:60