Vector2.inl
1
2//
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
29template <typename T>
30Vector2<T>::Vector2() :
31x(0),
32y(0)
33{
34
35}
36
37
41template <typename T>
42Vector2<T>::Vector2(T X, T Y) :
43x(X),
44y(Y)
45{
46
47}
48
49
53template <typename T>
54Vector2<T> operator -(const Vector2<T>& V)
55{
56 return Vector2<T>(-V.x, -V.y);
57}
58
59
63template <typename T>
64Vector2<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
76template <typename T>
77Vector2<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
89template <typename T>
90Vector2<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
99template <typename T>
100Vector2<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
109template <typename T>
110Vector2<T> operator *(const Vector2<T>& V, T X)
111{
112 return Vector2<T>(V.x * X, V.y * X);
113}
114
115
119template <typename T>
120Vector2<T> operator *(T X, const Vector2<T>& V)
121{
122 return Vector2<T>(V.x * X, V.y * X);
123}
124
125
129template <typename T>
130Vector2<T>& operator *=(Vector2<T>& V, T X)
131{
132 V.x *= X;
133 V.y *= X;
134
135 return V;
136}
137
138
142template <typename T>
143Vector2<T> operator /(const Vector2<T>& V, T X)
144{
145 return Vector2<T>(V.x / X, V.y / X);
146}
147
148
152template <typename T>
153Vector2<T>& operator /=(Vector2<T>& V, T X)
154{
155 V.x /= X;
156 V.y /= X;
157
158 return V;
159}
160
161
165template <typename T>
166bool operator ==(const Vector2<T>& V1, const Vector2<T>& V2)
167{
168 return (V1.x == V2.x) && (V1.y == V2.y);
169}
170
171
175template <typename T>
176bool operator !=(const Vector2<T>& V1, const Vector2<T>& V2)
177{
178 return (V1.x != V2.x) || (V1.y != V2.y);
179}