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

LinAlg::Vec4< T > Class Template Reference

#include <LinAlg/Vec4.h>

List of all members.


Detailed Description

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

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


Public Types

typedef Vec4< 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 = 4 }
 The number of dimensions.

enum  { num_elements = 4 }
 The number of elements.


Public Member Functions

 Vec4 ()
 Create an uninitialized vector.

 Vec4 (const T v0, const T v1, const T v2, const T v3)
 Create a vector from arguments.

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

Vec4operator= (const Vec4 &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 Vec4 &lower, const Vec4 &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 Vec4 &v, const T eps) const
 Is this vector the same as another, within epsilon?

Vec4operator+= (const Vec4 &v)
 Add another vector to this one.

Vec4operator-= (const Vec4 &v)
 Subtract another vector from this one.

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

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


Static Public Member Functions

const Vec4zero ()
 Return the zero vector.

const Vec4 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 [4]
 The element storage.


Friends

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

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

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

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

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

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

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

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

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

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

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

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

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


Constructor & Destructor Documentation

template<typename T>
template<typename Other>
LinAlg::Vec4< T >::Vec4 const Vec4< 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.