Cafu Engine
Vector2T< T > Class Template Reference

This class represents a 2-dimensional vector. More...

#include "Vector2.hpp"

Public Member Functions

 Vector2T ()
 The default constructor. It initializes all components to zero. More...
 
 Vector2T (T x_, T y_)
 This constructor initializes the components from x_ and y_ respectively. More...
 
template<class C >
 Vector2T (const C Values[])
 This constructor initializes the components from an array of (at least) two Ts. More...
 
bool IsValid () const
 Returns true if the vector is valid, that is, all components are non-NANs. More...
 
T & operator[] (unsigned int Index)
 Component access by index number (0 to 1) rather than by name. More...
 
const T & operator[] (unsigned int Index) const
 Component access by index number (0 to 1) rather than by name. More...
 
Vector2T< float > AsVectorOfFloat () const
 Gets this Vector2T<T> as a Vector2T<float>, so that the cast is explicitly visible in user code. More...
 
Vector2T< double > AsVectorOfDouble () const
 Gets this Vector2T<T> as a Vector2T<double>, so that the cast is explicitly visible in user code. More...
 
Group of const inspector methods. They are all const and thus do not modify this object.
GetLengthSqr () const
 Returns the square of the length of this vector. More...
 
bool IsEqual (const Vector2T< T > &B, const T Epsilon) const
 Returns whether this vector is equal to B within tolerance Epsilon, that is, whether it is geometrically closer to B than Epsilon. More...
 
Vector2T< T > GetScaled (const T s) const
 Returns a copy of this vector scaled by s, that is, the scalar product (Skalarmultiplikation) of this vector and s. More...
 
Vector2T< T > GetScaled (const Vector2T< T > &S) const
 Returns a copy of this vector non-uniformely scaled by S. More...
 
Group of (constructive) binary operators that do not modify their operands.
bool operator== (const Vector2T< T > &B) const
 Returns whether this vector and B are truly (bit-wise) identical. More...
 
bool operator!= (const Vector2T< T > &B) const
 Returns whether this vector and B are not equal (bit-wise). More...
 
Vector2T< T > operator+ (const Vector2T< T > &B) const
 Returns the sum of this Vector2T<T> and B. More...
 
Vector2T< T > operator- (const Vector2T< T > &B) const
 Returns the difference between this Vector2T<T> and B. More...
 
Vector2T< T > operator- () const
 The unary minus operator. B=-A is quasi identical with B=A.GetScaled(-1). More...
 
Vector2T< T > operator* (const T s) const
 Returns a copy of this vector scaled by s, that is, the scalar product (Skalarmultiplikation) of this vector and s. More...
 
Vector2T< T > operator/ (const T s) const
 Returns a copy of this vector divided by s, that is, the scalar product (Skalarmultiplikation) of this vector and 1/s. More...
 
dot (const Vector2T< T > &B) const
 Returns the dot product (Skalarprodukt) of this vector and B. More...
 
Group of operators that modify this vector.
Vector2T< T > & operator+= (const Vector2T< T > &B)
 Adds B to this vector. More...
 
Vector2T< T > & operator-= (const Vector2T< T > &B)
 Subtracts B from this vector. More...
 
Vector2T< T > & operator*= (const T s)
 Scales this vector by s. More...
 
Vector2T< T > & operator/= (const T s)
 Divides this vector by s. Assumes that s is not 0. More...
 

Public Attributes

x
 The x-component of this vector. More...
 
y
 The y-component of this vector. More...
 

Detailed Description

template<class T>
class Vector2T< T >

This class represents a 2-dimensional vector.

Constructor & Destructor Documentation

template<class T>
Vector2T< T >::Vector2T ( )
inline

The default constructor. It initializes all components to zero.

template<class T>
Vector2T< T >::Vector2T ( x_,
y_ 
)
inline

This constructor initializes the components from x_ and y_ respectively.

template<class T>
template<class C >
Vector2T< T >::Vector2T ( const C  Values[])
inlineexplicit

This constructor initializes the components from an array of (at least) two Ts.

Member Function Documentation

template<class T>
Vector2T<double> Vector2T< T >::AsVectorOfDouble ( ) const
inline

Gets this Vector2T<T> as a Vector2T<double>, so that the cast is explicitly visible in user code.

template<class T>
Vector2T<float> Vector2T< T >::AsVectorOfFloat ( ) const
inline

Gets this Vector2T<T> as a Vector2T<float>, so that the cast is explicitly visible in user code.

template<class T>
T Vector2T< T >::dot ( const Vector2T< T > &  B) const
inline

Returns the dot product (Skalarprodukt) of this vector and B.

template<class T>
T Vector2T< T >::GetLengthSqr ( ) const
inline

Returns the square of the length of this vector.

template<class T>
Vector2T<T> Vector2T< T >::GetScaled ( const T  s) const
inline

Returns a copy of this vector scaled by s, that is, the scalar product (Skalarmultiplikation) of this vector and s.

Parameters
sScale factor to scale this vector by.
See Also
Also see the operator *, which does exactly the same.
template<class T>
Vector2T<T> Vector2T< T >::GetScaled ( const Vector2T< T > &  S) const
inline

Returns a copy of this vector non-uniformely scaled by S.

template<class T>
bool Vector2T< T >::IsEqual ( const Vector2T< T > &  B,
const T  Epsilon 
) const
inline

Returns whether this vector is equal to B within tolerance Epsilon, that is, whether it is geometrically closer to B than Epsilon.

Parameters
BVector to compare to.
EpsilonTolerance value.
See Also
operator ==
template<class T>
bool Vector2T< T >::IsValid ( ) const
inline

Returns true if the vector is valid, that is, all components are non-NANs.

template<class T>
bool Vector2T< T >::operator!= ( const Vector2T< T > &  B) const
inline

Returns whether this vector and B are not equal (bit-wise).

Use this operator with care, as it comes without any epsilon threshold for taking rounding errors into account.

Parameters
BVector to compare to.
See Also
IsEqual()
template<class T>
Vector2T<T> Vector2T< T >::operator* ( const T  s) const
inline

Returns a copy of this vector scaled by s, that is, the scalar product (Skalarmultiplikation) of this vector and s.

Parameters
sFactor to multiply this vector with.
See Also
GetScaled(), which does exactly the same.
template<class T>
Vector2T<T>& Vector2T< T >::operator*= ( const T  s)
inline

Scales this vector by s.

template<class T>
Vector2T<T> Vector2T< T >::operator+ ( const Vector2T< T > &  B) const
inline

Returns the sum of this Vector2T<T> and B.

template<class T>
Vector2T<T>& Vector2T< T >::operator+= ( const Vector2T< T > &  B)
inline

Adds B to this vector.

template<class T>
Vector2T<T> Vector2T< T >::operator- ( const Vector2T< T > &  B) const
inline

Returns the difference between this Vector2T<T> and B.

template<class T>
Vector2T<T> Vector2T< T >::operator- ( ) const
inline

The unary minus operator. B=-A is quasi identical with B=A.GetScaled(-1).

template<class T>
Vector2T<T>& Vector2T< T >::operator-= ( const Vector2T< T > &  B)
inline

Subtracts B from this vector.

template<class T>
Vector2T<T> Vector2T< T >::operator/ ( const T  s) const
inline

Returns a copy of this vector divided by s, that is, the scalar product (Skalarmultiplikation) of this vector and 1/s.

template<class T>
Vector2T<T>& Vector2T< T >::operator/= ( const T  s)
inline

Divides this vector by s. Assumes that s is not 0.

template<class T>
bool Vector2T< T >::operator== ( const Vector2T< T > &  B) const
inline

Returns whether this vector and B are truly (bit-wise) identical.

Use this operator with care, as it comes without any epsilon threshold for taking rounding errors into account.

Parameters
BVector to compare to.
See Also
IsEqual()
template<class T>
T& Vector2T< T >::operator[] ( unsigned int  Index)
inline

Component access by index number (0 to 1) rather than by name.

Parameters
IndexIndex of the component to access. Can only be 0 or 1 (for x or y).
Exceptions
InvalidOperationEif Index is not 0 or 1.
template<class T>
const T& Vector2T< T >::operator[] ( unsigned int  Index) const
inline

Component access by index number (0 to 1) rather than by name.

Parameters
IndexIndex of the component to access. Can only be 0 or 1 (for x or y).
Exceptions
InvalidOperationEif Index is not 0 or 1.

Member Data Documentation

template<class T>
T Vector2T< T >::x

The x-component of this vector.

template<class T>
T Vector2T< T >::y

The y-component of this vector.


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