Public Member Functions | Public Attributes | Related Functions | List of all members
ime::Vector2< T > Class Template Reference

2D vector 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...
 
float magnitude () const
 Get the magnitude/length of the vector. More...
 
float dot (const Vector2< T > &otherVec) const
 Get the scalar product of this vector and another vector. More...
 
cross (const Vector2< T > &otherVec) const
 Get the cross product of this vector and anther vector. More...
 
float distanceTo (const Vector2< T > &otherVec) const
 Get the distance between this vector and another vector. More...
 
float angle () const
 Get the angle between the vector and the positive x-axis, in degrees. More...
 
float angleTo (const Vector2< T > &otherVec) const
 Get the angle between this vector and another vector, in degrees. More...
 
Vector2< float > asUnitVector () const
 Get the unit vector of this vector. More...
 

Public Attributes

x
 X coordinate of the vector. More...
 
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/ (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...
 
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...
 
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 ime::Vector2< T >

2D vector

Definition at line 35 of file Vector2.h.

Constructor & Destructor Documentation

◆ Vector2() [1/3]

template<typename T >
ime::Vector2< T >::Vector2 ( )

Default constructor.

Creates a Vector2(0, 0)

◆ Vector2() [2/3]

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

Construct the vector from its coordinates.

Parameters
XX coordinate
YY coordinate

◆ Vector2() [3/3]

template<typename T >
template<typename U >
ime::Vector2< T >::Vector2 ( const Vector2< U > &  vector)
explicit

Construct the vector from another type of vector.

Parameters
vectorVector to convert

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

Member Function Documentation

◆ angle()

template<typename T >
float ime::Vector2< T >::angle ( ) const

Get the angle between the vector and the positive x-axis, in degrees.

Returns
The angle between this vector and the positive x-axis

◆ angleTo()

template<typename T >
float ime::Vector2< T >::angleTo ( const Vector2< T > &  otherVec) const

Get the angle between this vector and another vector, in degrees.

Parameters
otherVecThe vector to get the angle to
Returns
The angle between this vector and otherVec, in degrees

◆ asUnitVector()

template<typename T >
Vector2< float > ime::Vector2< T >::asUnitVector ( ) const

Get the unit vector of this vector.

Returns
This vector as a unit vector

◆ cross()

template<typename T >
T ime::Vector2< T >::cross ( const Vector2< T > &  otherVec) const

Get the cross product of this vector and anther vector.

Parameters
otherVecThe vector to cross with this vector
Returns
The cross product of this vector and otherVec

◆ distanceTo()

template<typename T >
float ime::Vector2< T >::distanceTo ( const Vector2< T > &  otherVec) const

Get the distance between this vector and another vector.

Parameters
otherVecThe vector to get the distance to
Returns
The distance between this vector and otherVec

◆ dot()

template<typename T >
float ime::Vector2< T >::dot ( const Vector2< T > &  otherVec) const

Get the scalar product of this vector and another vector.

Parameters
otherVecThe vector to dot with this vector
Returns
The scalar product of the this vector and otherVec

◆ magnitude()

template<typename T >
float ime::Vector2< T >::magnitude ( ) const

Get the magnitude/length of the vector.

Returns
The magnitude/length of the vector

Friends And Related Function Documentation

◆ operator!=()

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

Overload of binary operator !=.

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

This operator compares strict difference between two vectors

◆ 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 multiplication by right

◆ 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 +=.

Parameters
leftLeft operand (a vector)
rightRight operand (a vector)
Returns
Overload of binary operator +=

This operator performs a memberwise addition of both vectors, and assigns the result 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 -=.

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

This operator performs a memberwise subtraction of both vectors, and assigns the result 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
return Memberwise division by right

◆ operator/=()

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

Overload of binary operator /=.

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

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

◆ operator<()

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

Overload of binary operator <.

Parameters
leftLeft operand (a vector)
rightRight operand (a vector)
Returns
True if left is less than right

This function returns true if the x member of left is less than the x member of right AND the y member of left is less than the y member of right, otherwise it returns false

◆ operator<=()

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

Overload of binary operator <=.

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

This function returns true if the x member of left is less than or equal to the x member of right AND the y member of left is less than or equal to the y member of right, otherwise it returns false

◆ operator==()

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

Overload of binary operator ==.

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

This operator compares strict equality between two vectors

◆ operator>()

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

Overload of binary operator >

Parameters
leftLeft operand (a vector)
rightRight operand (a vector)
Returns
True if left is greater than right

This function returns true if the x member of left is greater than the x member of right AND the y member of left is greater than the y member of right, otherwise it returns false

◆ operator>=()

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

Overload of binary operator >=.

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

This function returns true if the x member of left is greater than or equal to the x member of right AND the y member of left is greater than or equal to the y member of right, otherwise it returns false Define the most common types

Member Data Documentation

◆ x

template<typename T >
T ime::Vector2< T >::x

X coordinate of the vector.

Definition at line 109 of file Vector2.h.

◆ y

template<typename T >
T ime::Vector2< T >::y

Y coordinate of the vector.

Definition at line 110 of file Vector2.h.


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