Main Page | Namespace List | Class Hierarchy | Class List | Namespace Members | Class Members

LinAlg::Vec2< T > Class Template Reference

#include <LinAlg/Vec2.h>

List of all members.


Detailed Description

template<typename T>
class LinAlg::Vec2< T >

A linear algebra vector class of fixed type and size 2.


Public Types

typedef Vec2< T > self_type
 This type.

typedef T value_type
 The underlying m_data type.

typedef T * iterator
 An iterator.

typedef const T * const_iterator
 A constant iterator.

enum  { num_dims = 2 }
 The number of dimensions.

enum  { num_elements = 2 }
 The number of elements.


Public Member Functions

 Vec2 ()
 Create an uninitialized vector.

 Vec2 (const T v0, const T v1)
 Create a vector from arguments.

template<typename Other>  Vec2 (const Vec2< Other > &v)
 Copy a vector of another type.

Vec2operator= (const Vec2 &v)
 Assign another vector to this one.

const T & operator() (const unsigned i) const
 Access an element read-only.

T & operator() (const unsigned i)
 Access an element read-write.

const T * data () const
 Get a read-only pointer to the first element.

T * data ()
 Get a read-write pointer to the first element.

const_iterator begin () const
 Get a read-only iterator to the first element.

iterator begin ()
 Get a read-write pointer to the first element.

const_iterator end () const
 Get a read-only iterator to past the last element.

iterator end ()
 Get a read-write iterator to past the last element.

unsigned size () const
 Return the number of elements in the vector.

void limit (const std::pair< T, T > &l)
 Limit each element of the vector to the range [l.first, l.second].

void limit (const T lower, const T upper)
 Limit each element of the vector to the range [lower, upper].

void limit (const Vec2 &lower, const Vec2 &upper)
 Limit element i of the vector to the range [lower[i], upper[i]].

sum () const
 Return the sum of all the elements.

prod () const
 Return the product of all the elements.

length () const
 Return the geometric length of the vector.

lengthSqr () const
 Return the geometric length squared of the vector.

bool equal (const Vec2 &v, const T eps) const
 Is this vector the same as another, within epsilon?

Vec2operator+= (const Vec2 &v)
 Add another vector to this one.

Vec2operator-= (const Vec2 &v)
 Subtract another vector from this one.

template<typename Scalar> Vec2operator *= (const Scalar d)
 Multiply this vector by a scalar.

template<typename Scalar> Vec2operator/= (const Scalar d)
 Divide this vector by a scalar. Does not check for zero.


Static Public Member Functions

const Vec2zero ()
 Return the zero vector.

const Vec2 unit (const unsigned index)
 Return the unit vector with v(i) == 0 and v(index) == 1.

std::string description ()
 Return a description like "2D float vector", useful for debugging and messages.


Protected Attributes

m_data [2]
 The element storage.


Friends

Vec2 operator- (const Vec2 &u)
 Negate a vector.

Vec2 operator+ (const Vec2 &u, const Vec2 &v)
 Add two vectors.

Vec2 operator- (const Vec2 &u, const Vec2 &v)
 Subtract two vectors.

Vec2 operator * (const Vec2< T > &u, const T s)
 Right-multiply a vector by a scalar.

Vec2 operator * (const T s, const Vec2< T > &u)
 Left-multiply a vector by a scalar.

Vec2 operator/ (const Vec2< T > &u, const T s)
 Right-divide a vector by a scalar.

bool operator== (const Vec2 &u, const Vec2 &v)
 Exact equality -- use with caution on floating-point base types.

bool operator!= (const Vec2 &u, const Vec2 &v)
 Exact inequality -- use with caution on floating-point base types.

inner (const Vec2 &u, const Vec2 &v)
 The inner (dot) product of u and v.

Vec2 proj (const Vec2 &u, const Vec2 &v)
 Return the projection of u onto v.

Vec2 min (const Vec2 &u, const Vec2 &v)
 Per-element minimum.

Vec2 max (const Vec2 &u, const Vec2 &v)
 Per-element maximum.

Vec2 normalized (const Vec2 &u)
 Unit vector in direction of u. Does not check for u.length() == 0.


Constructor & Destructor Documentation

template<typename T>
template<typename Other>
LinAlg::Vec2< T >::Vec2 const Vec2< Other > &  v  )  [inline]
 

Copy a vector of another type.

Note:
If the source and destination types are not the same, then the elements of v are cast into the appropriate type.


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

© 2005-2008 Adrian Secord.