#include <Vector.h>
Public Member Functions | |
VectorGeneric () | |
create it null More... | |
template<typename... Args> | |
VectorGeneric (double first, Args... arg) | |
Constructor accepting n double parameters. More... | |
double | modulo () const |
Compute the modulo. More... | |
double | modulo2 () const |
compute the squared modulo More... | |
double & | operator() (unsigned i) |
parenthesis access (i) More... | |
const double & | operator() (unsigned i) const |
parenthesis access (i) More... | |
VectorGeneric & | operator*= (double s) |
multiply More... | |
VectorGeneric | operator+ () const |
sign + More... | |
VectorGeneric & | operator+= (const VectorGeneric &b) |
increment More... | |
VectorGeneric | operator- () const |
sign - More... | |
VectorGeneric & | operator-= (const VectorGeneric &b) |
decrement More... | |
VectorGeneric & | operator/= (double s) |
divide More... | |
double & | operator[] (unsigned i) |
array-like access [i] More... | |
const double & | operator[] (unsigned i) const |
array-like access [i] More... | |
void | zero () |
set it to zero More... | |
Private Member Functions | |
void | auxiliaryConstructor () |
Auxiliary private function for constructor. More... | |
template<typename... Args> | |
void | auxiliaryConstructor (double first, Args... arg) |
Auxiliary private function for constructor. More... | |
Private Attributes | |
std::array< double, n > | d |
Friends | |
VectorGeneric< 3 > | crossProduct (const VectorGeneric< 3 > &, const VectorGeneric< 3 > &) |
return v1 .vector. More... | |
template<unsigned m> | |
VectorGeneric< m > | delta (const VectorGeneric< m > &v1, const VectorGeneric< m > &v2) |
return v2-v1 More... | |
template<unsigned m> | |
double | dotProduct (const VectorGeneric< m > &, const VectorGeneric< m > &) |
return v1 .scalar. v2 More... | |
template<unsigned m> | |
double | modulo (const VectorGeneric< m > &) |
friend version of modulo (to simplify some syntax) More... | |
template<unsigned m> | |
double | modulo2 (const VectorGeneric< m > &) |
friend version of modulo2 (to simplify some syntax) More... | |
template<unsigned m> | |
VectorGeneric< m > | operator* (const VectorGeneric< m > &, double) |
return v*s More... | |
template<unsigned m> | |
VectorGeneric< m > | operator* (double, const VectorGeneric< m > &) |
return s*v More... | |
template<unsigned m> | |
VectorGeneric< m > | operator+ (const VectorGeneric< m > &, const VectorGeneric< m > &) |
return v1+v2 More... | |
template<unsigned m> | |
VectorGeneric< m > | operator- (const VectorGeneric< m > &, const VectorGeneric< m > &) |
return v1-v2 More... | |
template<unsigned m> | |
VectorGeneric< m > | operator/ (const VectorGeneric< m > &, double) |
return v/s More... | |
template<unsigned m> | |
std::ostream & | operator<< (std::ostream &os, const VectorGeneric< m > &) |
<< operator. More... | |
Class implementing fixed size vectors of doubles
n | The number of elements of the vector. |
This class implements a vector of doubles with size fixed at compile time. It is useful for small fixed size objects (e.g. 3d vectors) as it does not waste space to store the vector size. Moreover, as the compiler knows the size, it can be completely opimized inline. All the methods are inlined for better optimization and all the loops are explicitly unrolled using PLMD::LoopUnroller class. Vector elements are initialized to zero by default. Notice that this means that constructor is a bit slow. This point might change in future if we find performance issues. Accepts both [] and () syntax for access. Several functions are declared as friends even if not necessary so as to properly appear in Doxygen documentation.
Aliases are defined to simplify common declarations (Vector, Vector2d, Vector3d, Vector4d). Also notice that some operations are only available for 3 dimensional vectors.
Example of usage
#include "Vector.h" using namespace PLMD; int main(){ VectorGeneric<3> v1; v1[0]=3.0; // use equivalently () and [] syntax: v1(1)=5.0; // initialize with components VectorGeneric<3> v2=VectorGeneric<3>(1.0,2.0,3.0); VectorGeneric<3> v3=crossProduct(v1,v2); double d=dotProduct(v1,v2); v3+=v1; v2=v1+2.0*v3; }
PLMD::VectorGeneric< n >::VectorGeneric | ( | double | first, |
Args... | arg | ||
) |
Constructor accepting n double parameters.
Can be used as Vector<3>(1.0,2.0,3.0) or Vector<2>(2.0,3.0). In case a wrong number of parameters is given, a static assertion will fail.
PLMD::VectorGeneric< n >::VectorGeneric |
create it null
|
private |
Auxiliary private function for constructor.
|
private |
Auxiliary private function for constructor.
double PLMD::VectorGeneric< n >::modulo |
Compute the modulo.
Shortcut for sqrt(v.modulo2())
double PLMD::VectorGeneric< n >::modulo2 |
compute the squared modulo
double & PLMD::VectorGeneric< n >::operator() | ( | unsigned | i | ) |
parenthesis access (i)
const double & PLMD::VectorGeneric< n >::operator() | ( | unsigned | i | ) | const |
parenthesis access (i)
VectorGeneric< n > & PLMD::VectorGeneric< n >::operator*= | ( | double | s | ) |
multiply
VectorGeneric< n > PLMD::VectorGeneric< n >::operator+ |
sign +
VectorGeneric< n > & PLMD::VectorGeneric< n >::operator+= | ( | const VectorGeneric< n > & | b | ) |
increment
VectorGeneric< n > PLMD::VectorGeneric< n >::operator- |
sign -
VectorGeneric< n > & PLMD::VectorGeneric< n >::operator-= | ( | const VectorGeneric< n > & | b | ) |
decrement
VectorGeneric< n > & PLMD::VectorGeneric< n >::operator/= | ( | double | s | ) |
divide
double & PLMD::VectorGeneric< n >::operator[] | ( | unsigned | i | ) |
array-like access [i]
const double & PLMD::VectorGeneric< n >::operator[] | ( | unsigned | i | ) | const |
array-like access [i]
void PLMD::VectorGeneric< n >::zero |
set it to zero
|
friend |
return v1 .vector.
v2 Only available for size 3
|
friend |
return v2-v1
|
friend |
return v1 .scalar. v2
friend version of modulo (to simplify some syntax)
friend version of modulo2 (to simplify some syntax)
|
friend |
return v*s
|
friend |
return s*v
|
friend |
return v1+v2
|
friend |
return v1-v2
|
friend |
return v/s
|
friend |
<< operator.
Allows printing vector v
with std::cout<<v;
|
private |
Hosted by GitHub | 1.8.17 |