GDevelop Core
Core library for developing platforms and tools compatible with GDevelop.
Public Member Functions | Public Attributes | Related Functions | List of all members
gd::Vector2< T > Class Template Reference

Utility template class for manipulating 2-dimensional vectors. More...

#include <Vector2.h>

Public Member Functions

 Vector2 ()
 Default constructor. More...
 
 Vector2 (T X, T Y)
 Construct the vector from its coordinates. More...
 
template<typename U >
 Vector2 (const Vector2< U > &vector)
 Construct the vector from another type of vector. More...
 

Public Attributes

x
 X coordinate of the vector.
 
y
 Y coordinate of the vector.
 

Related Functions

(Note that these are not member functions.)

template<typename T >
Vector2< T > operator- (const Vector2< T > &right)
 Overload of unary operator -. More...
 
template<typename T >
Vector2< T > & operator+= (Vector2< T > &left, const Vector2< T > &right)
 Overload of binary operator +=. More...
 
template<typename T >
Vector2< T > & operator-= (Vector2< T > &left, const Vector2< T > &right)
 Overload of binary operator -=. More...
 
template<typename T >
Vector2< T > operator+ (const Vector2< T > &left, const Vector2< T > &right)
 Overload of binary operator +. More...
 
template<typename T >
Vector2< T > operator- (const Vector2< T > &left, const Vector2< T > &right)
 Overload of binary operator -. More...
 
template<typename T >
Vector2< T > operator* (const Vector2< T > &left, T right)
 Overload of binary operator *. More...
 
template<typename T >
Vector2< T > operator* (T left, const Vector2< T > &right)
 Overload of binary operator *. More...
 
template<typename T >
Vector2< T > & operator*= (Vector2< T > &left, T right)
 Overload of binary operator *=. More...
 
template<typename T >
Vector2< T > operator/ (const Vector2< T > &left, T right)
 Overload of binary operator /. More...
 
template<typename T >
Vector2< T > & operator/= (Vector2< T > &left, T right)
 Overload of binary operator /=. More...
 
template<typename T >
bool operator== (const Vector2< T > &left, const Vector2< T > &right)
 Overload of binary operator ==. More...
 
template<typename T >
bool operator!= (const Vector2< T > &left, const Vector2< T > &right)
 Overload of binary operator !=. More...
 

Detailed Description

template<typename T>
class gd::Vector2< T >

Utility template class for manipulating 2-dimensional vectors.

gd::Vector2 is a simple class that defines a mathematical vector with two coordinates (x and y). It can be used to represent anything that has two dimensions: a size, a point, a velocity, etc.

The template parameter T is the type of the coordinates. It can be any type that supports arithmetic operations (+, -, /, *) and comparisons (==, !=), for example int or float.

You generally don't have to care about the templated form (gd::Vector2<T>), the most common specializations have special typedefs:

The gd::Vector2 class has a small and simple interface, its x and y members can be accessed directly (there are no accessors like setX(), getX()) and it contains no mathematical function like dot product, cross product, length, etc.

Usage example:

gd::Vector2f v1(16.5f, 24.f);
v1.x = 18.2f;
float y = v1.y;
gd::Vector2f v2 = v1 * 5.f;
v3 = v1 + v2;
bool different = (v2 != v3);
Utility template class for manipulating 2-dimensional vectors.
Definition: Vector2.h:40
T y
Y coordinate of the vector.
Definition: Vector2.h:89

Note: for 3-dimensional vectors, see gd::Vector3.

Constructor & Destructor Documentation

◆ Vector2() [1/3]

template<typename T >
gd::Vector2< T >::Vector2 ( )
inline

Default constructor.

Creates a Vector2(0, 0).

◆ Vector2() [2/3]

template<typename T >
gd::Vector2< T >::Vector2 ( X,
Y 
)
inline

Construct the vector from its coordinates.

Parameters
XX coordinate
YY coordinate

◆ Vector2() [3/3]

template<typename T >
template<typename U >
gd::Vector2< T >::Vector2 ( const Vector2< U > &  vector)
inlineexplicit

Construct the vector from another type of vector.

This constructor doesn't replace the copy constructor, it's called only when U != T. A call to this constructor will fail to compile if U is not convertible to T.

Parameters
vectorVector to convert

Friends And Related Function Documentation

◆ operator!=()

template<typename T >
bool operator!= ( const Vector2< T > &  left,
const Vector2< T > &  right 
)
related

Overload of binary operator !=.

This operator compares strict difference between two vectors.

Parameters
leftLeft operand (a vector)
rightRight operand (a vector)
Returns
True if left is not equal to right

◆ operator*() [1/2]

template<typename T >
Vector2< T > operator* ( const Vector2< T > &  left,
right 
)
related

Overload of binary operator *.

Parameters
leftLeft operand (a vector)
rightRight operand (a scalar value)
Returns
Memberwise multiplication by right

◆ operator*() [2/2]

template<typename T >
Vector2< T > operator* ( left,
const Vector2< T > &  right 
)
related

Overload of binary operator *.

Parameters
leftLeft operand (a scalar value)
rightRight operand (a vector)
Returns
Memberwise multiplication by left

◆ operator*=()

template<typename T >
Vector2< T > & operator*= ( Vector2< T > &  left,
right 
)
related

Overload of binary operator *=.

This operator performs a memberwise multiplication by right, and assigns the result to left.

Parameters
leftLeft operand (a vector)
rightRight operand (a scalar value)
Returns
Reference to left

◆ operator+()

template<typename T >
Vector2< T > operator+ ( const Vector2< T > &  left,
const Vector2< T > &  right 
)
related

Overload of binary operator +.

Parameters
leftLeft operand (a vector)
rightRight operand (a vector)
Returns
Memberwise addition of both vectors

◆ operator+=()

template<typename T >
Vector2< T > & operator+= ( Vector2< T > &  left,
const Vector2< T > &  right 
)
related

Overload of binary operator +=.

This operator performs a memberwise addition of both vectors, and assigns the result to left.

Parameters
leftLeft operand (a vector)
rightRight operand (a vector)
Returns
Reference to left

◆ operator-() [1/2]

template<typename T >
Vector2< T > operator- ( const Vector2< T > &  left,
const Vector2< T > &  right 
)
related

Overload of binary operator -.

Parameters
leftLeft operand (a vector)
rightRight operand (a vector)
Returns
Memberwise subtraction of both vectors

◆ operator-() [2/2]

template<typename T >
Vector2< T > operator- ( const Vector2< T > &  right)
related

Overload of unary operator -.

Parameters
rightVector to negate
Returns
Memberwise opposite of the vector

◆ operator-=()

template<typename T >
Vector2< T > & operator-= ( Vector2< T > &  left,
const Vector2< T > &  right 
)
related

Overload of binary operator -=.

This operator performs a memberwise subtraction of both vectors, and assigns the result to left.

Parameters
leftLeft operand (a vector)
rightRight operand (a vector)
Returns
Reference to left

◆ operator/()

template<typename T >
Vector2< T > operator/ ( const Vector2< T > &  left,
right 
)
related

Overload of binary operator /.

Parameters
leftLeft operand (a vector)
rightRight operand (a scalar value)
Returns
Memberwise division by right

◆ operator/=()

template<typename T >
Vector2< T > & operator/= ( Vector2< T > &  left,
right 
)
related

Overload of binary operator /=.

This operator performs a memberwise division by right, and assigns the result to left.

Parameters
leftLeft operand (a vector)
rightRight operand (a scalar value)
Returns
Reference to left

◆ operator==()

template<typename T >
bool operator== ( const Vector2< T > &  left,
const Vector2< T > &  right 
)
related

Overload of binary operator ==.

This operator compares strict equality between two vectors.

Parameters
leftLeft operand (a vector)
rightRight operand (a vector)
Returns
True if left is equal to right

The documentation for this class was generated from the following file: