1 ////////////////////////////////////////////////////////////
\r
3 // SFML - Simple and Fast Multimedia Library
\r
4 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
\r
6 // This software is provided 'as-is', without any express or implied warranty.
\r
7 // In no event will the authors be held liable for any damages arising from the use of this software.
\r
9 // Permission is granted to anyone to use this software for any purpose,
\r
10 // including commercial applications, and to alter it and redistribute it freely,
\r
11 // subject to the following restrictions:
\r
13 // 1. The origin of this software must not be misrepresented;
\r
14 // you must not claim that you wrote the original software.
\r
15 // If you use this software in a product, an acknowledgment
\r
16 // in the product documentation would be appreciated but is not required.
\r
18 // 2. Altered source versions must be plainly marked as such,
\r
19 // and must not be misrepresented as being the original software.
\r
21 // 3. This notice may not be removed or altered from any source distribution.
\r
23 ////////////////////////////////////////////////////////////
\r
25 #ifndef SFML_VECTOR2_HPP
\r
26 #define SFML_VECTOR2_HPP
\r
31 ////////////////////////////////////////////////////////////
\r
32 /// Vector2 is an utility class for manipulating 2 dimensional
\r
33 /// vectors. Template parameter defines the type of coordinates
\r
34 /// (integer, float, ...)
\r
35 ////////////////////////////////////////////////////////////
\r
36 template <typename T>
\r
41 ////////////////////////////////////////////////////////////
\r
42 /// Default constructor
\r
44 ////////////////////////////////////////////////////////////
\r
47 ////////////////////////////////////////////////////////////
\r
48 /// Construct the vector from its coordinates
\r
50 /// \param X : X coordinate
\r
51 /// \param Y : Y coordinate
\r
53 ////////////////////////////////////////////////////////////
\r
56 ////////////////////////////////////////////////////////////
\r
58 ////////////////////////////////////////////////////////////
\r
59 T x; ///< X coordinate of the vector
\r
60 T y; ///< Y coordinate of the vector
\r
63 ////////////////////////////////////////////////////////////
\r
64 /// Operator - overload ; returns the opposite of a vector
\r
66 /// \param V : Vector to negate
\r
70 ////////////////////////////////////////////////////////////
\r
71 template <typename T>
\r
72 Vector2<T> operator -(const Vector2<T>& V);
\r
74 ////////////////////////////////////////////////////////////
\r
75 /// Operator += overload ; add two vectors and assign to the first op
\r
77 /// \param V1 : First vector
\r
78 /// \param V2 : Second vector
\r
82 ////////////////////////////////////////////////////////////
\r
83 template <typename T>
\r
84 Vector2<T>& operator +=(Vector2<T>& V1, const Vector2<T>& V2);
\r
86 ////////////////////////////////////////////////////////////
\r
87 /// Operator -= overload ; subtract two vectors and assign to the first op
\r
89 /// \param V1 : First vector
\r
90 /// \param V2 : Second vector
\r
94 ////////////////////////////////////////////////////////////
\r
95 template <typename T>
\r
96 Vector2<T>& operator -=(Vector2<T>& V1, const Vector2<T>& V2);
\r
98 ////////////////////////////////////////////////////////////
\r
99 /// Operator + overload ; adds two vectors
\r
101 /// \param V1 : First vector
\r
102 /// \param V2 : Second vector
\r
104 /// \return V1 + V2
\r
106 ////////////////////////////////////////////////////////////
\r
107 template <typename T>
\r
108 Vector2<T> operator +(const Vector2<T>& V1, const Vector2<T>& V2);
\r
110 ////////////////////////////////////////////////////////////
\r
111 /// Operator - overload ; subtracts two vectors
\r
113 /// \param V1 : First vector
\r
114 /// \param V2 : Second vector
\r
116 /// \return V1 - V2
\r
118 ////////////////////////////////////////////////////////////
\r
119 template <typename T>
\r
120 Vector2<T> operator -(const Vector2<T>& V1, const Vector2<T>& V2);
\r
122 ////////////////////////////////////////////////////////////
\r
123 /// Operator * overload ; multiply a vector by a scalar value
\r
125 /// \param V : Vector
\r
126 /// \param X : Scalar value
\r
130 ////////////////////////////////////////////////////////////
\r
131 template <typename T>
\r
132 Vector2<T> operator *(const Vector2<T>& V, T X);
\r
134 ////////////////////////////////////////////////////////////
\r
135 /// Operator * overload ; multiply a scalar value by a vector
\r
137 /// \param X : Scalar value
\r
138 /// \param V : Vector
\r
142 ////////////////////////////////////////////////////////////
\r
143 template <typename T>
\r
144 Vector2<T> operator *(T X, const Vector2<T>& V);
\r
146 ////////////////////////////////////////////////////////////
\r
147 /// Operator *= overload ; multiply-assign a vector by a scalar value
\r
149 /// \param V : Vector
\r
150 /// \param X : Scalar value
\r
154 ////////////////////////////////////////////////////////////
\r
155 template <typename T>
\r
156 Vector2<T>& operator *=(Vector2<T>& V, T X);
\r
158 ////////////////////////////////////////////////////////////
\r
159 /// Operator / overload ; divide a vector by a scalar value
\r
161 /// \param V : Vector
\r
162 /// \param X : Scalar value
\r
166 ////////////////////////////////////////////////////////////
\r
167 template <typename T>
\r
168 Vector2<T> operator /(const Vector2<T>& V, T X);
\r
170 ////////////////////////////////////////////////////////////
\r
171 /// Operator /= overload ; divide-assign a vector by a scalar value
\r
173 /// \param V : Vector
\r
174 /// \param X : Scalar value
\r
178 ////////////////////////////////////////////////////////////
\r
179 template <typename T>
\r
180 Vector2<T>& operator /=(Vector2<T>& V, T X);
\r
182 ////////////////////////////////////////////////////////////
\r
183 /// Operator == overload ; compares the equality of two vectors
\r
185 /// \param V1 : First vector
\r
186 /// \param V2 : Second vector
\r
188 /// \return True if V1 is equal to V2
\r
190 ////////////////////////////////////////////////////////////
\r
191 template <typename T>
\r
192 bool operator ==(const Vector2<T>& V1, const Vector2<T>& V2);
\r
194 ////////////////////////////////////////////////////////////
\r
195 /// Operator != overload ; compares the difference of two vectors
\r
197 /// \param V1 : First vector
\r
198 /// \param V2 : Second vector
\r
200 /// \return True if V1 is different than V2
\r
202 ////////////////////////////////////////////////////////////
\r
203 template <typename T>
\r
204 bool operator !=(const Vector2<T>& V1, const Vector2<T>& V2);
\r
206 #include <SFML/System/Vector2.inl>
\r
208 // Define the most common types
\r
209 typedef Vector2<int> Vector2i;
\r
210 typedef Vector2<float> Vector2f;
\r
215 #endif // SFML_VECTOR2_HPP
\r