28 template <
class T,
unsigned N=0>
41 for (
unsigned i=0; i < N; ++i)
49 T
const&
operator()(
unsigned i)
const {
return (*
this)[i];}
53 for (
unsigned i=0; i < N; ++i)
61 for (
unsigned i=0; i < N; ++i)
62 r[i] = (*
this)[i] + b[i];
68 for (
unsigned i=0; i < N; ++i)
76 for (
unsigned i=0; i < N; ++i)
77 r[i] = (*
this)[i] - b[i];
87 for (
unsigned i=0; i < N; ++i)
88 r[i] = (*
this)[i] * s;
96 for (
unsigned i=0; i < N; ++i)
97 r[i] = (*
this)[i] / s;
107 for (
unsigned i=0; i < N; ++i)
108 r += (*
this)[i] * b[i];
118 for (
unsigned i=0; i < N; ++i)
148 for (
unsigned i=0; i < this->sz; ++i)
155 for (
unsigned i=0; i < this->sz; ++i)
162 for (
unsigned i=0; i < this->sz; ++i)
169 for (
unsigned i=0; i < this->sz; ++i)
178 for (
unsigned i=0; i < this->sz; ++i)
184 for (
unsigned i=0; i < this->sz; ++i)
185 s += (*
this)[i] * b[i];
231 T&
x() {
return (*
this[0]);}
233 T&
y() {
return (*
this[1]);}
235 T&
z() {
return (*
this[2]);}
237 T
const&
x()
const {
return (*
this)[0];}
239 T
const&
y()
const {
return (*
this)[1];}
241 T
const&
z()
const {
return (*
this)[2];}
246 template <
class T,
unsigned N>
247 std::ostream& operator<<(std::ostream& s, mth::Vector<T,N>
const& a)
249 for (
unsigned i=0; i < a.size(); ++i)
Vector< T, N > normalize() const
divide the vector by its magnitude
T getLength() const
get the vector magnitude
T & y()
mutable y component
void zero()
zero the vector
T const & x() const
immutable x component
Vector< T, 0 > & operator+=(Vector< T, 0 > const &b)
add a vector to this vector
T getLength() const
get the vector magnitude
compile-time (static) vector of size N
Vector< T, 0 > & operator-=(Vector< T, 0 > const &b)
subtract a vector from this vector
Vector< T, N > operator*(T const &s) const
multiply a vector times a scalar
convenience wrapper over apf::Vector<3>
Vector()
default constructor - no allocation
Array()
default constructor - necessary
T const & operator()(unsigned i) const
immutable index operator
T & x()
mutable x component
T operator*(Vector< T, N > const &b) const
vector dot product
Vector< T, N > operator+(Vector< T, N > const &b) const
add two vectors
void fromArray(T const *abc)
read vector from array
Vector3(Vector< T, 3 > const &other)
copy constructor
Vector< T, N > & operator-=(Vector< T, N > const &b)
subtract a vector from this vector
Vector< T, N > operator/(T const &s) const
divide a vector by a scalar
compile-time (static) array of size N
Vector< T, 0 > & operator*=(T const &s)
multiply this vector by a scalar
Vector< T, N > operator-(Vector< T, N > const &b) const
subtract two vectors
Vector3()
default constructor
T & z()
mutable z component
Vector< T, N > & operator+=(Vector< T, N > const &b)
add a vector to this vector
void zero()
zero the vector
double sqrt(double A)
wrapper for standard sqrt function
T const & operator()(unsigned i) const
immutable index operator
T const & y() const
immutable y component
Vector(T const *v)
construct from an array
T & operator()(unsigned i)
mutable index operator
Vector(unsigned n)
construct with n elems
T const & z() const
immutable z component
Vector< T, 0 > & operator/=(T const &s)
divide this vector by a scalar
Vector3(T const *abc)
construct from an array
Vector()
default constructor
run-time (dynamic) vector
T & operator()(unsigned i)
mutable index operator
Vector(unsigned n)
construct with n elements
void toArray(T *abc) const
write vector to array
Vector3(T const &a, T const &b, T const &c)
construct from 3 values