- cpp3ds
- Vector2
Utility template class for manipulating 2-dimensional vectors. More...
#include <Vector2.hpp>
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 | |
T | x |
X coordinate of the vector. More... | |
T | y |
Y coordinate of the vector. More... | |
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... | |
Utility template class for manipulating 2-dimensional vectors.
cpp3ds::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 (cpp3ds::Vector2<T>), the most common specializations have special typedefs:
The cpp3ds::Vector2 class has a small and simple interface, its x and y members can be accessed directly (there's no accessor like setX(), getX()) and it contains no mathematical function like dot product, cross product, length, etc.
Usage example:
Note: for 3-dimensional vectors, see cpp3ds::Vector3.
Definition at line 37 of file Vector2.hpp.
cpp3ds::Vector2< T >::Vector2 | ( | ) |
Default constructor.
Creates a Vector2(0, 0).
cpp3ds::Vector2< T >::Vector2 | ( | T | X, |
T | Y | ||
) |
Construct the vector from its coordinates.
X | X coordinate |
Y | Y coordinate |
|
explicit |
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.
vector | Vector to convert |
|
related |
Overload of binary operator !=.
This operator compares strict difference between two vectors.
left | Left operand (a vector) |
right | Right operand (a vector) |
Overload of binary operator *.
left | Left operand (a vector) |
right | Right operand (a scalar value) |
Overload of binary operator *.
left | Left operand (a scalar value) |
right | Right operand (a vector) |
Overload of binary operator *=.
This operator performs a memberwise multiplication by right, and assigns the result to left.
left | Left operand (a vector) |
right | Right operand (a scalar value) |
|
related |
Overload of binary operator +.
left | Left operand (a vector) |
right | Right operand (a vector) |
|
related |
Overload of binary operator +=.
This operator performs a memberwise addition of both vectors, and assigns the result to left.
left | Left operand (a vector) |
right | Right operand (a vector) |
Overload of unary operator -.
right | Vector to negate |
|
related |
Overload of binary operator -.
left | Left operand (a vector) |
right | Right operand (a vector) |
|
related |
Overload of binary operator -=.
This operator performs a memberwise subtraction of both vectors, and assigns the result to left.
left | Left operand (a vector) |
right | Right operand (a vector) |
Overload of binary operator /.
left | Left operand (a vector) |
right | Right operand (a scalar value) |
Overload of binary operator /=.
This operator performs a memberwise division by right, and assigns the result to left.
left | Left operand (a vector) |
right | Right operand (a scalar value) |
|
related |
Overload of binary operator ==.
This operator compares strict equality between two vectors.
left | Left operand (a vector) |
right | Right operand (a vector) |
T cpp3ds::Vector2< T >::x |
X coordinate of the vector.
Definition at line 75 of file Vector2.hpp.
T cpp3ds::Vector2< T >::y |
Y coordinate of the vector.
Definition at line 76 of file Vector2.hpp.