|
|
|||
File indexing completed on 2026-06-02 08:58:14
0001 //////////////////////////////////////////////////////////// 0002 // 0003 // SFML - Simple and Fast Multimedia Library 0004 // Copyright (C) 2007-2023 Laurent Gomila (laurent@sfml-dev.org) 0005 // 0006 // This software is provided 'as-is', without any express or implied warranty. 0007 // In no event will the authors be held liable for any damages arising from the use of this software. 0008 // 0009 // Permission is granted to anyone to use this software for any purpose, 0010 // including commercial applications, and to alter it and redistribute it freely, 0011 // subject to the following restrictions: 0012 // 0013 // 1. The origin of this software must not be misrepresented; 0014 // you must not claim that you wrote the original software. 0015 // If you use this software in a product, an acknowledgment 0016 // in the product documentation would be appreciated but is not required. 0017 // 0018 // 2. Altered source versions must be plainly marked as such, 0019 // and must not be misrepresented as being the original software. 0020 // 0021 // 3. This notice may not be removed or altered from any source distribution. 0022 // 0023 //////////////////////////////////////////////////////////// 0024 0025 #ifndef SFML_VECTOR2_HPP 0026 #define SFML_VECTOR2_HPP 0027 0028 0029 namespace sf 0030 { 0031 //////////////////////////////////////////////////////////// 0032 /// \brief Utility template class for manipulating 0033 /// 2-dimensional vectors 0034 /// 0035 //////////////////////////////////////////////////////////// 0036 template <typename T> 0037 class Vector2 0038 { 0039 public: 0040 0041 //////////////////////////////////////////////////////////// 0042 /// \brief Default constructor 0043 /// 0044 /// Creates a Vector2(0, 0). 0045 /// 0046 //////////////////////////////////////////////////////////// 0047 Vector2(); 0048 0049 //////////////////////////////////////////////////////////// 0050 /// \brief Construct the vector from its coordinates 0051 /// 0052 /// \param X X coordinate 0053 /// \param Y Y coordinate 0054 /// 0055 //////////////////////////////////////////////////////////// 0056 Vector2(T X, T Y); 0057 0058 //////////////////////////////////////////////////////////// 0059 /// \brief Construct the vector from another type of vector 0060 /// 0061 /// This constructor doesn't replace the copy constructor, 0062 /// it's called only when U != T. 0063 /// A call to this constructor will fail to compile if U 0064 /// is not convertible to T. 0065 /// 0066 /// \param vector Vector to convert 0067 /// 0068 //////////////////////////////////////////////////////////// 0069 template <typename U> 0070 explicit Vector2(const Vector2<U>& vector); 0071 0072 //////////////////////////////////////////////////////////// 0073 // Member data 0074 //////////////////////////////////////////////////////////// 0075 T x; //!< X coordinate of the vector 0076 T y; //!< Y coordinate of the vector 0077 }; 0078 0079 //////////////////////////////////////////////////////////// 0080 /// \relates Vector2 0081 /// \brief Overload of unary operator - 0082 /// 0083 /// \param right Vector to negate 0084 /// 0085 /// \return Memberwise opposite of the vector 0086 /// 0087 //////////////////////////////////////////////////////////// 0088 template <typename T> 0089 Vector2<T> operator -(const Vector2<T>& right); 0090 0091 //////////////////////////////////////////////////////////// 0092 /// \relates Vector2 0093 /// \brief Overload of binary operator += 0094 /// 0095 /// This operator performs a memberwise addition of both vectors, 0096 /// and assigns the result to \a left. 0097 /// 0098 /// \param left Left operand (a vector) 0099 /// \param right Right operand (a vector) 0100 /// 0101 /// \return Reference to \a left 0102 /// 0103 //////////////////////////////////////////////////////////// 0104 template <typename T> 0105 Vector2<T>& operator +=(Vector2<T>& left, const Vector2<T>& right); 0106 0107 //////////////////////////////////////////////////////////// 0108 /// \relates Vector2 0109 /// \brief Overload of binary operator -= 0110 /// 0111 /// This operator performs a memberwise subtraction of both vectors, 0112 /// and assigns the result to \a left. 0113 /// 0114 /// \param left Left operand (a vector) 0115 /// \param right Right operand (a vector) 0116 /// 0117 /// \return Reference to \a left 0118 /// 0119 //////////////////////////////////////////////////////////// 0120 template <typename T> 0121 Vector2<T>& operator -=(Vector2<T>& left, const Vector2<T>& right); 0122 0123 //////////////////////////////////////////////////////////// 0124 /// \relates Vector2 0125 /// \brief Overload of binary operator + 0126 /// 0127 /// \param left Left operand (a vector) 0128 /// \param right Right operand (a vector) 0129 /// 0130 /// \return Memberwise addition of both vectors 0131 /// 0132 //////////////////////////////////////////////////////////// 0133 template <typename T> 0134 Vector2<T> operator +(const Vector2<T>& left, const Vector2<T>& right); 0135 0136 //////////////////////////////////////////////////////////// 0137 /// \relates Vector2 0138 /// \brief Overload of binary operator - 0139 /// 0140 /// \param left Left operand (a vector) 0141 /// \param right Right operand (a vector) 0142 /// 0143 /// \return Memberwise subtraction of both vectors 0144 /// 0145 //////////////////////////////////////////////////////////// 0146 template <typename T> 0147 Vector2<T> operator -(const Vector2<T>& left, const Vector2<T>& right); 0148 0149 //////////////////////////////////////////////////////////// 0150 /// \relates Vector2 0151 /// \brief Overload of binary operator * 0152 /// 0153 /// \param left Left operand (a vector) 0154 /// \param right Right operand (a scalar value) 0155 /// 0156 /// \return Memberwise multiplication by \a right 0157 /// 0158 //////////////////////////////////////////////////////////// 0159 template <typename T> 0160 Vector2<T> operator *(const Vector2<T>& left, T right); 0161 0162 //////////////////////////////////////////////////////////// 0163 /// \relates Vector2 0164 /// \brief Overload of binary operator * 0165 /// 0166 /// \param left Left operand (a scalar value) 0167 /// \param right Right operand (a vector) 0168 /// 0169 /// \return Memberwise multiplication by \a left 0170 /// 0171 //////////////////////////////////////////////////////////// 0172 template <typename T> 0173 Vector2<T> operator *(T left, const Vector2<T>& right); 0174 0175 //////////////////////////////////////////////////////////// 0176 /// \relates Vector2 0177 /// \brief Overload of binary operator *= 0178 /// 0179 /// This operator performs a memberwise multiplication by \a right, 0180 /// and assigns the result to \a left. 0181 /// 0182 /// \param left Left operand (a vector) 0183 /// \param right Right operand (a scalar value) 0184 /// 0185 /// \return Reference to \a left 0186 /// 0187 //////////////////////////////////////////////////////////// 0188 template <typename T> 0189 Vector2<T>& operator *=(Vector2<T>& left, T right); 0190 0191 //////////////////////////////////////////////////////////// 0192 /// \relates Vector2 0193 /// \brief Overload of binary operator / 0194 /// 0195 /// \param left Left operand (a vector) 0196 /// \param right Right operand (a scalar value) 0197 /// 0198 /// \return Memberwise division by \a right 0199 /// 0200 //////////////////////////////////////////////////////////// 0201 template <typename T> 0202 Vector2<T> operator /(const Vector2<T>& left, T right); 0203 0204 //////////////////////////////////////////////////////////// 0205 /// \relates Vector2 0206 /// \brief Overload of binary operator /= 0207 /// 0208 /// This operator performs a memberwise division by \a right, 0209 /// and assigns the result to \a left. 0210 /// 0211 /// \param left Left operand (a vector) 0212 /// \param right Right operand (a scalar value) 0213 /// 0214 /// \return Reference to \a left 0215 /// 0216 //////////////////////////////////////////////////////////// 0217 template <typename T> 0218 Vector2<T>& operator /=(Vector2<T>& left, T right); 0219 0220 //////////////////////////////////////////////////////////// 0221 /// \relates Vector2 0222 /// \brief Overload of binary operator == 0223 /// 0224 /// This operator compares strict equality between two vectors. 0225 /// 0226 /// \param left Left operand (a vector) 0227 /// \param right Right operand (a vector) 0228 /// 0229 /// \return True if \a left is equal to \a right 0230 /// 0231 //////////////////////////////////////////////////////////// 0232 template <typename T> 0233 bool operator ==(const Vector2<T>& left, const Vector2<T>& right); 0234 0235 //////////////////////////////////////////////////////////// 0236 /// \relates Vector2 0237 /// \brief Overload of binary operator != 0238 /// 0239 /// This operator compares strict difference between two vectors. 0240 /// 0241 /// \param left Left operand (a vector) 0242 /// \param right Right operand (a vector) 0243 /// 0244 /// \return True if \a left is not equal to \a right 0245 /// 0246 //////////////////////////////////////////////////////////// 0247 template <typename T> 0248 bool operator !=(const Vector2<T>& left, const Vector2<T>& right); 0249 0250 #include <SFML/System/Vector2.inl> 0251 0252 // Define the most common types 0253 typedef Vector2<int> Vector2i; 0254 typedef Vector2<unsigned int> Vector2u; 0255 typedef Vector2<float> Vector2f; 0256 0257 } // namespace sf 0258 0259 0260 #endif // SFML_VECTOR2_HPP 0261 0262 0263 //////////////////////////////////////////////////////////// 0264 /// \class sf::Vector2 0265 /// \ingroup system 0266 /// 0267 /// sf::Vector2 is a simple class that defines a mathematical 0268 /// vector with two coordinates (x and y). It can be used to 0269 /// represent anything that has two dimensions: a size, a point, 0270 /// a velocity, etc. 0271 /// 0272 /// The template parameter T is the type of the coordinates. It 0273 /// can be any type that supports arithmetic operations (+, -, /, *) 0274 /// and comparisons (==, !=), for example int or float. 0275 /// 0276 /// You generally don't have to care about the templated form (sf::Vector2<T>), 0277 /// the most common specializations have special typedefs: 0278 /// \li sf::Vector2<float> is sf::Vector2f 0279 /// \li sf::Vector2<int> is sf::Vector2i 0280 /// \li sf::Vector2<unsigned int> is sf::Vector2u 0281 /// 0282 /// The sf::Vector2 class has a small and simple interface, its x and y members 0283 /// can be accessed directly (there are no accessors like setX(), getX()) and it 0284 /// contains no mathematical function like dot product, cross product, length, etc. 0285 /// 0286 /// Usage example: 0287 /// \code 0288 /// sf::Vector2f v1(16.5f, 24.f); 0289 /// v1.x = 18.2f; 0290 /// float y = v1.y; 0291 /// 0292 /// sf::Vector2f v2 = v1 * 5.f; 0293 /// sf::Vector2f v3; 0294 /// v3 = v1 + v2; 0295 /// 0296 /// bool different = (v2 != v3); 0297 /// \endcode 0298 /// 0299 /// Note: for 3-dimensional vectors, see sf::Vector3. 0300 /// 0301 ////////////////////////////////////////////////////////////
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|