Files Class List
Vec< T, N > Class Template Reference

Detailed Description

template<typename T, int N>
class cy::Vec< T, N >

A general class for N-dimensional vectors.

#include <cyVector.h>

Public Member Functions

Constructors
 Vec (T const *p)
 
 Vec (T v)
 
template<typename S >
 Vec (Vec< S, N > const &p)
 
template<int M>
 Vec (Vec< T, M > const &p)
 
template<typename S , int M>
 Vec (Vec< S, M > const &p)
 
 Vec (Vec2< T > const &p)
 
 Vec (Vec3< T > const &p)
 
 Vec (Vec4< T > const &p)
 
template<typename S >
 Vec (Vec2< S > const &p)
 
template<typename S >
 Vec (Vec3< S > const &p)
 
template<typename S >
 Vec (Vec4< S > const &p)
 
template<typename P >
 Vec (P const &p)
 
Set & Get value methods
void Zero ()
 Sets the coordinates as zero.
 
void Get (T *p) const
 Puts the coordinate values into the array.
 
void Set (T const *p)
 Sets the coordinates using the values in the given array.
 
void Set (T v)
 Sets all coordinates using the given value.
 
template<int M>
void CopyData (T *p)
 Sets the coordinates as zero.
 
template<typename S , int M>
void ConvertData (S *p)
 Sets the coordinates as zero.
 
void Normalize ()
 Normalizes the vector, such that its length becomes 1.
 
General methods
Vec GetNormalized () const
 Returns a normalized copy of the vector.
 
LengthSquared () const
 Returns the square of the length. Effectively, this is the dot product of the vector with itself.
 
Length () const
 Returns the length of the vector.
 
Sum () const
 Returns the sum of its components.
 
bool IsZero () const
 Returns true if all components are exactly zero.
 
Min () const
 Returns the minimum component of the vector.
 
Max () const
 Returns the maximum component of the vector.
 
int MinComp () const
 Returns the index of the minimum component of the vector.
 
int MaxComp () const
 Returns the index of the maximum component of the vector.
 
bool IsFinite () const
 Returns true if all components are finite real numbers.
 
bool IsUnit () const
 Returns true if the length of the vector is close to 1.
 
Vec Sqrt () const
 Returns the square root of the vector.
 
Vec Abs () const
 Returns a vector containing the absolute values of all components.
 
Limit methods
void Clamp (T minLimit, T maxLimit)
 Ensures that all components of the vector are within the given limits.
 
void ClampMin (T v)
 Ensures that all components of the vector are greater than or equal to the given limit.
 
void ClampMax (T v)
 Ensures that all components of the vector are smaller than or equal to the given limit.
 
void SetAbs ()
 Converts all negative components to positive values.
 
Unary operators
Vec operator- () const
 
Binary operators
Vec operator+ (Vec const &p) const
 
Vec operator- (Vec const &p) const
 
Vec operator* (Vec const &p) const
 
Vec operator/ (Vec const &p) const
 
Vec operator+ (T const v) const
 
Vec operator- (T const v) const
 
Vec operator* (T const v) const
 
Vec operator/ (T const v) const
 
Assignment operators
Vec const & operator+= (Vec const &p)
 
Vec const & operator-= (Vec const &p)
 
Vec const & operator*= (Vec const &p)
 
Vec const & operator/= (Vec const &p)
 
Vec const & operator+= (T const v)
 
Vec const & operator-= (T const v)
 
Vec const & operator*= (T const v)
 
Vec const & operator/= (T const v)
 
Test operators
bool operator== (Vec const &p) const
 
bool operator!= (Vec const &p) const
 
Access operators
T & operator[] (int i)
 
operator[] (int i) const
 
T & Element (int i)
 
T const & Element (int i) const
 
T * Elements ()
 
T const * Elements () const
 
Dot product
Dot (Vec const &p) const
 Dot product.
 
operator% (Vec const &p) const
 Dot product operator.
 

Public Attributes

Components of the vector
elem [N]
 

Friends

Vec operator- (T v, Vec const &p)
 Subtraction from a constant.
 
Vec operator+ (T v, Vec const &p)
 Addition with a constant.
 
Vec operator* (T v, Vec const &p)
 Multiplication with a constant.