v1.1.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Modules Pages
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
Sifteo::Vector2< T > Struct Template Reference

Generalized two-element cartesian coordinate vector. More...

#include <sifteo/math.h>

Public Member Functions

template<typename R >
Vector2< R > cast () const
 Explicitly cast this vector to another vector type, using default C++ truncation or extension rules.
 
Vector2< T > cmul (Vector2< T > u) const
 Complex multiplication. More...
 
len () const
 Calculate the scalar length (magnitude) of this vector.
 
len2 () const
 Calculate the scalar length (magnitude) of this vector, squared. More...
 
lenManhattan () const
 Calculate the manhattan (city block) distance of this vector.
 
Vector2< T > normalize () const
 Return a normalized version of this vector. More...
 
Vector2< T > rotate (float angle) const
 Rotate this vector about the origin counterclockwise by 'angle' radians.
 
Vector2< T > rotateI (int angle) const
 Rotate this vector about the origin counterclockwise by an integer multiple of 90 degrees. More...
 
Vector2< int > round () const
 Round a floating point vector to the nearest integer.
 
void set (T _x, T _y)
 Modify this vector's value in-place.
 
void setPolar (float angle, float magnitude)
 Set this vector to a new cartesian value, given a value in polar coordinates.
 
Vector2< double > toDouble () const
 Explicit cast to double.
 
Vector2< float > toFloat () const
 Explicit cast to float.
 
Vector2< int > toInt () const
 Explicit cast to int.
 

Static Public Member Functions

static Vector2< T > unit (int side)
 Create a unit vector corresponding to the given integer 'side'. More...
 

Public Attributes

x
 Vector component X.
 
y
 Vector component Y.
 

Detailed Description

template<typename T>
struct Sifteo::Vector2< T >

Generalized two-element cartesian coordinate vector.

Member Function Documentation

template<typename T>
Vector2<T> Sifteo::Vector2< T >::cmul ( Vector2< T >  u) const
inline

Complex multiplication.

Treat this vector as a complex number, and multiply it with another vector equivalently interpreted.

template<typename T>
T Sifteo::Vector2< T >::len2 ( ) const
inline

Calculate the scalar length (magnitude) of this vector, squared.

This avoids the costly square root calculation.

template<typename T>
Vector2<T> Sifteo::Vector2< T >::normalize ( ) const
inline

Return a normalized version of this vector.

The returned vector will have a magnitude of 1.0.

template<typename T>
Vector2<T> Sifteo::Vector2< T >::rotateI ( int  angle) const
inline

Rotate this vector about the origin counterclockwise by an integer multiple of 90 degrees.

The angle must be 0, 1, 2, or 3. If you must pass larger angles, you can use umod(a, 4) to fold them into this range.

template<typename T>
static Vector2<T> Sifteo::Vector2< T >::unit ( int  side)
inlinestatic

Create a unit vector corresponding to the given integer 'side'.

0 = -Y (Up) 1 = -X (Left) 2 = +Y (Down) 3 = +X (Right)


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