XVec<int dim, class real_type>

XVec is a template class providing standard linear algebra functionality for vectors. The class is templated over int dim, the dimension of the vector, and class real_type, the type of data stored in the components. For convenience a few types of vectors have already been defined.

Convenience Types

XVec2d XVec2f XVec2i
XVec3d XVec3f XVec3i
XVec4d XVec4f XVec4i

Class Methods

Constructors

XVec(real_type f) Constructs a vector with every componenent having the value f.
XVec(real_type f0, real_type f1) Constructs a vector with components (f0,f1).
XVec(real_type f0, real_type f1, real_type f2) Constructs a vector with components (f0,f1,f2).
XVec(real_type f0, real_type f1, real_type f2, real_type f3) Constructs a vector with components (f0,f1,f2,f3).
XVec(const XVec& c) Constructs a vector. It is the copy constructor.
XVec(const real_type* a) Constructs a vector with components from the array a[].

Accessors

real_type& operator() (const int i) Returns the ith component.
real_type operator() (const int i) const Returns the ith component.
const real_type& ref() Returns a reference to the data.
real_type& x() Returns the first component.
real_type& y() Returns the second component.
real_type& z() Returns the third component.
real_type& w() Returns the fourth component.
real_type& red() Returns the first component.
real_type& green() Returns the second component.
real_type& blue() Returns the third component.
real_type& alpha() Returns the fourth component.
operator real_type*() Returns a pointer to the internal data of the vector.
operator const real_type*() Returns a constant pointer to the internal data of the vector.

Operators

XVec& operator=(const XVec& c) Assigns the components of c to this.
bool operator==(const XVec& c) Performs component-wise comparison between this and c.
bool operator!=(const XVec& c) Performs component-wise comparison between this and c.

XVec operator+(const XVec& c) Returns the sum of this and c.
XVec operator-(const XVec& c) Returns the difference of this and c.
XVec operator*(real_type s) Returns the product of this and the scalar s.
friend XVec operator*(real_type s, const XVec& c) Returns the product of this and the scalar s.
XVec operator/(real_type s) Returns the quotient of this and the scalar s.

XVec operator+=(const XVec& c)
XVec operator-=(const XVec& c)
XVec operator*=(real_type s)
XVec operator/=(real_type s)

XVec operator*(const XVec& c) Returns the element-wise multiplication of this and c.
XVec operator/(const XVec& c) Returns the element-wise quotient of this and c.

real_type dot(const XVec& c) Returns the dot product of this and c.
XVec cross(const XVec& c) Returns the cross product of this and c; it is only defined for 3-vectors.
XVec operator-() const Returns the negative of this.

Norm and Bounding Box

real_type dot() Returns this dotted with itself, its norm squared.
real_type norm() Returns the norm this.
int normalize() Normalizes this.
void bbox(XVec& cmin, XVec& cmax) const Updates the bounding box corners to include this.