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

LinAlg::Vec3< T > Class Template Reference

#include <LinAlg/Vec3.h>

List of all members.


Detailed Description

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

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


Public Types

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

enum  { num_elements = 3 }
 The number of elements.


Public Member Functions

 Vec3 ()
 Create an uninitialized vector.

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

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

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

Vec3operator+= (const Vec3 &v)
 Add another vector to this one.

Vec3operator-= (const Vec3 &v)
 Subtract another vector from this one.

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

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


Static Public Member Functions

const Vec3zero ()
 Return the zero vector.

const Vec3 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 [3]
 The element storage.


Friends

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

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

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

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

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

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

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

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

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

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

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

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

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


Constructor & Destructor Documentation

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