All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
Nimble::Vector2T< T > Class Template Reference

Two-dimensional vector class for 2D mathematics. More...

#include <Nimble/Vector2.hpp>

Public Types

enum  { ELEMENTS = 2 }
 
typedef T type
 Data type of the vector.
 

Public Member Functions

double angle (void) const
 Returns atan2(y/x)
 
template<typename S >
Nimble::Vector2T< S > cast () const
 Cast the vector to another type.
 
Vector2Tclamp (T low, T high)
 Clamps both components to the range [low, high].
 
Vector2TclampUnit (void)
 Clamps both components to the range [0,1].
 
void clear (void)
 Fill the vector with zeroes.
 
T * data ()
 Returns a pointer to the first element.
 
const T * data () const
 Returns a pointer to the first element.
 
Vector2Tdescale (const Vector2T &v)
 Scales the vector with inverse of v.
 
T & get (size_t i)
 Returns the ith component.
 
const T & get (size_t i) const
 Returns the ith component.
 
bool isFinite () const
 Check that vector elements are finite. More...
 
bool isOne (void) const
 Checks if both components are one.
 
bool isZero (void) const
 Checks if both components are zero.
 
Decltype< T, float >::mul length () const
 Returns the length of the vector.
 
lengthSqr (void) const
 Returns the squared length of the vector.
 
Vector2TlimitLength (T len)
 Normalizes the vector to the given length if it is longer.
 
Vector2T< T > & make (T cx, T cy)
 Set the vector to given values.
 
Vector2T< T > & make (T xy)
 Set both components to the given value.
 
maximum (void) const
 Returns the larger component.
 
minimum (void) const
 Returns the smaller component.
 
Vector2Tnegate (void)
 Negates the vector.
 
Vector2Tnormalize (T len=T(1))
 Normalizes the vector to the given length. More...
 
Vector2T normalized (T len=T(1)) const
 Get a vector normalized to given length. More...
 
bool operator!= (const Vector2T &src) const
 Compares if two vectors differ.
 
Vector2Toperator*= (T s)
 Multiplies a vector with a scalar.
 
Vector2Toperator+= (const Vector2T &v)
 Adds two vectors.
 
Vector2T operator- () const
 Returns the negation of a vector.
 
Vector2Toperator-= (const Vector2T &v)
 Subtracts two vectors.
 
Vector2T operator/ (T s) const
 Divide a vector by scalar.
 
Vector2Toperator/= (T s)
 Divides a vector with a scalar.
 
bool operator< (const Vector2T< T > &v2) const
 Less-than operator, with arbitrary internal logic. More...
 
bool operator== (const Vector2T &src) const
 Compares if two vectors are equal.
 
const T & operator[] (size_t i) const
 Returns the ith component.
 
T & operator[] (size_t i)
 Returns the ith component.
 
Vector2T perpendicular () const
 Returns a perpendicular vector.
 
Vector2Trotate (double s, double c)
 Rotates the vector given the sine and cosine of the rotation angle.
 
Vector2Trotate (double angle)
 Rotate the vector by given radians.
 
Vector2Tscale (const Vector2T &v)
 Scales the vector.
 
Vector2Tscale (const T &xs, const T &ys)
 Scales the vector.
 
void set (size_t i, T v)
 Sets the ith component.
 
Vector2T shuffle (int i1=1, int i2=0) const
 Returns a vector with components reordered.
 
sum (void) const
 Returns the sum of components.
 
 Vector2T ()
 Default constructor, does not initialize the values. More...
 
 Vector2T (T cx, T cy)
 Constructs a vector initializing it to given values.
 
 Vector2T (const SizeT< T > &s)
 Constructs vector from the size. More...
 

Static Public Member Functions

static Vector2T< T > null ()
 Zero vector. More...
 

Public Attributes

x
 X-component of the vector.
 
y
 Y-component of the vector.
 

Detailed Description

template<typename T>
class Nimble::Vector2T< T >

Two-dimensional vector class for 2D mathematics.

Like all classed in Nimble Vector2T has been optimized for speed. In general, there are no safety checks in any functions.

Constructor & Destructor Documentation

template<typename T>
Nimble::Vector2T< T >::Vector2T ( )
inline

Default constructor, does not initialize the values.

template<typename T>
Nimble::Vector2T< T >::Vector2T ( const SizeT< T > &  s)
inlineexplicit

Constructs vector from the size.

Parameters
sSize which width and height are copied to x and y values of vector.

Member Function Documentation

template<typename T>
bool Nimble::Vector2T< T >::isFinite ( ) const
inline

Check that vector elements are finite.

This function can be useful if you suspect that contents of the vector might be corrupt floating point numbers.

Returns
True if the vector elements are finite, false if are non-finite (i.e. infinite or nan).
template<typename T>
Vector2T& Nimble::Vector2T< T >::normalize ( len = T(1))
inline

Normalizes the vector to the given length.

Parameters
lenlength to normalize to
Returns
reference to this
template<typename T>
Vector2T Nimble::Vector2T< T >::normalized ( len = T(1)) const
inline

Get a vector normalized to given length.

Parameters
lenlength to normalize to
Returns
normalized vector
template<typename T>
static Vector2T<T> Nimble::Vector2T< T >::null ( )
inlinestatic

Zero vector.

Returns
a zero vector
template<typename T>
bool Nimble::Vector2T< T >::operator< ( const Vector2T< T > &  v2) const
inline

Less-than operator, with arbitrary internal logic.

This method is used if you want to sort vectors.

Parameters
v2Other vector to compare to
Returns
True if this vector should be sorted before v2