Public Member Functions | Private Types | Private Attributes | Friends | List of all members
WireCell::D3Vector< T > Class Template Reference

#include <D3Vector.h>

Public Member Functions

 D3Vector (const T &a=0, const T &b=0, const T &c=0)
 Construct from elements. More...
 
 D3Vector (const D3Vector &o)
 
 D3Vector (const T d[3])
 
D3Vectoroperator= (const D3Vector &o)
 
void set (const T &a=0, const T &b=0, const T &c=0)
 Set vector from elements;. More...
 
x (const T &val)
 
y (const T &val)
 
z (const T &val)
 
template<class TT >
 D3Vector (const D3Vector< TT > &o)
 Convert from other typed vector. More...
 
x () const
 Access elements by name. More...
 
y () const
 
z () const
 
operator[] (std::size_t index) const
 Access elements by copy. More...
 
T & operator[] (std::size_t index)
 Access elements by reference. More...
 
dot (const D3Vector &rhs) const
 Return the dot product of this vector and the other. More...
 
magnitude () const
 Return the magnitude of this vector. More...
 
D3Vector norm () const
 Return a normalized vector in the direction of this vector. More...
 
D3Vector cross (const D3Vector &rhs) const
 Return the cross product of this vector and the other. More...
 
D3Vector triplevec (D3Vector &a, D3Vector &b) const
 Return the triple cross product of this vector and the other two. More...
 
triplescal (D3Vector &a, D3Vector &b) const
 Return the dot-cross product of this vector and the other two. More...
 
bool operator< (const D3Vector &rhs) const
 
D3Vectoroperator+= (const D3Vector &other)
 
bool operator! () const
 
 operator bool () const
 
void invalidate ()
 

Private Types

typedef std::vector< T > D3VectorStore
 

Private Attributes

D3VectorStore m_v
 

Friends

template<class U >
std::ostream & operator<< (std::ostream &, const D3Vector< U > &)
 

Detailed Description

template<class T>
class WireCell::D3Vector< T >

Dimension-3 vector class.

Adapted in laziness from: http://rosettacode.org/wiki/Vector_products#C.2B.2B

Definition at line 23 of file D3Vector.h.

Member Typedef Documentation

template<class T>
typedef std::vector<T> WireCell::D3Vector< T >::D3VectorStore
private

Definition at line 28 of file D3Vector.h.

Constructor & Destructor Documentation

template<class T>
WireCell::D3Vector< T >::D3Vector ( const T &  a = 0,
const T &  b = 0,
const T &  c = 0 
)
inline

Construct from elements.

Definition at line 35 of file D3Vector.h.

35 : m_v(3) { this->set(a,b,c); }
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1124
static bool * b
Definition: config.cpp:1043
D3VectorStore m_v
Definition: D3Vector.h:29
template<class T>
WireCell::D3Vector< T >::D3Vector ( const D3Vector< T > &  o)
inline

Definition at line 38 of file D3Vector.h.

38 : m_v(3) { this->set(o.x(), o.y(), o.z()); }
D3VectorStore m_v
Definition: D3Vector.h:29
template<class T>
WireCell::D3Vector< T >::D3Vector ( const T  d[3])
inline

Definition at line 40 of file D3Vector.h.

40 : m_v(3) { this->set(d[0], d[1], d[2]); }
D3VectorStore m_v
Definition: D3Vector.h:29
template<class T>
template<class TT >
WireCell::D3Vector< T >::D3Vector ( const D3Vector< TT > &  o)
inline

Convert from other typed vector.

Definition at line 62 of file D3Vector.h.

62 : m_v(3) { this->set(o.x(), o.y(), o.z()); }
D3VectorStore m_v
Definition: D3Vector.h:29

Member Function Documentation

template<class T>
D3Vector WireCell::D3Vector< T >::cross ( const D3Vector< T > &  rhs) const
inline

Return the cross product of this vector and the other.

Definition at line 100 of file D3Vector.h.

100  {
101  T a = y() * rhs.z() - z() * rhs.y() ;
102  T b = z() * rhs.x() - x() * rhs.z() ;
103  T c = x() * rhs.y() - y() * rhs.x() ;
104  D3Vector product( a , b , c ) ;
105  return product ;
106  }
D3Vector(const T &a=0, const T &b=0, const T &c=0)
Construct from elements.
Definition: D3Vector.h:35
T z() const
Definition: D3Vector.h:67
T x() const
Access elements by name.
Definition: D3Vector.h:65
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1124
T y() const
Definition: D3Vector.h:66
static bool * b
Definition: config.cpp:1043
template<class T>
T WireCell::D3Vector< T >::dot ( const D3Vector< T > &  rhs) const
inline

Return the dot product of this vector and the other.

Definition at line 80 of file D3Vector.h.

80  {
81  T scalar = x() * rhs.x() + y() * rhs.y() + z() * rhs.z() ;
82  return scalar;
83  }
T z() const
Definition: D3Vector.h:67
T x() const
Access elements by name.
Definition: D3Vector.h:65
T y() const
Definition: D3Vector.h:66
template<class T>
void WireCell::D3Vector< T >::invalidate ( )
inline

Definition at line 136 of file D3Vector.h.

136  {
137  m_v.clear();
138  m_v.shrink_to_fit();
139  }
D3VectorStore m_v
Definition: D3Vector.h:29
template<class T>
T WireCell::D3Vector< T >::magnitude ( ) const
inline

Return the magnitude of this vector.

Definition at line 86 of file D3Vector.h.

86  {
87  return std::sqrt(x()*x()+y()*y()+z()*z());
88  }
T z() const
Definition: D3Vector.h:67
T x() const
Access elements by name.
Definition: D3Vector.h:65
T y() const
Definition: D3Vector.h:66
template<class T>
D3Vector WireCell::D3Vector< T >::norm ( ) const
inline

Return a normalized vector in the direction of this vector.

Definition at line 91 of file D3Vector.h.

91  {
92  T m = this->magnitude();
93  if (m <= 0) {
94  return D3Vector();
95  }
96  return D3Vector(x()/m, y()/m, z()/m);
97  }
static const double m
Definition: Units.h:79
D3Vector(const T &a=0, const T &b=0, const T &c=0)
Construct from elements.
Definition: D3Vector.h:35
T magnitude() const
Return the magnitude of this vector.
Definition: D3Vector.h:86
T z() const
Definition: D3Vector.h:67
T x() const
Access elements by name.
Definition: D3Vector.h:65
T y() const
Definition: D3Vector.h:66
template<class T>
WireCell::D3Vector< T >::operator bool ( ) const
inline

Definition at line 132 of file D3Vector.h.

132  {
133  return m_v.size() == 3;
134  }
D3VectorStore m_v
Definition: D3Vector.h:29
template<class T>
bool WireCell::D3Vector< T >::operator! ( ) const
inline

Definition at line 129 of file D3Vector.h.

129  {
130  return m_v.size() != 3;
131  }
D3VectorStore m_v
Definition: D3Vector.h:29
template<class T>
D3Vector& WireCell::D3Vector< T >::operator+= ( const D3Vector< T > &  other)
inline

Definition at line 124 of file D3Vector.h.

124  {
125  this->set(x()+other.x(), y()+other.y(), z()+other.z());
126  return *this;
127  }
T z() const
Definition: D3Vector.h:67
T x() const
Access elements by name.
Definition: D3Vector.h:65
T y() const
Definition: D3Vector.h:66
template<class T>
bool WireCell::D3Vector< T >::operator< ( const D3Vector< T > &  rhs) const
inline

Definition at line 117 of file D3Vector.h.

117  {
118  if (z() < rhs.z()) return true;
119  if (y() < rhs.y()) return true;
120  if (x() < rhs.x()) return true;
121  return false;
122  }
T z() const
Definition: D3Vector.h:67
T x() const
Access elements by name.
Definition: D3Vector.h:65
T y() const
Definition: D3Vector.h:66
template<class T>
D3Vector& WireCell::D3Vector< T >::operator= ( const D3Vector< T > &  o)
inline

Definition at line 43 of file D3Vector.h.

43  {
44  this->set(o.x(), o.y(), o.z());
45  return *this;
46  }
template<class T>
T WireCell::D3Vector< T >::operator[] ( std::size_t  index) const
inline

Access elements by copy.

Definition at line 70 of file D3Vector.h.

70  {
71  return m_v.at(index);
72  }
D3VectorStore m_v
Definition: D3Vector.h:29
template<class T>
T& WireCell::D3Vector< T >::operator[] ( std::size_t  index)
inline

Access elements by reference.

Definition at line 75 of file D3Vector.h.

75  {
76  return m_v.at(index); // throw if out of bounds
77  }
D3VectorStore m_v
Definition: D3Vector.h:29
template<class T>
void WireCell::D3Vector< T >::set ( const T &  a = 0,
const T &  b = 0,
const T &  c = 0 
)
inline

Set vector from elements;.

Definition at line 49 of file D3Vector.h.

49  {
50  m_v.resize(3);
51  m_v[0] = a;
52  m_v[1] = b;
53  m_v[2] = c;
54  }
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1124
static bool * b
Definition: config.cpp:1043
D3VectorStore m_v
Definition: D3Vector.h:29
template<class T>
T WireCell::D3Vector< T >::triplescal ( D3Vector< T > &  a,
D3Vector< T > &  b 
) const
inline

Return the dot-cross product of this vector and the other two.

Definition at line 113 of file D3Vector.h.

113  {
114  return dot( a.cross( b ) ) ;
115  }
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1124
T dot(const D3Vector &rhs) const
Return the dot product of this vector and the other.
Definition: D3Vector.h:80
static bool * b
Definition: config.cpp:1043
template<class T>
D3Vector WireCell::D3Vector< T >::triplevec ( D3Vector< T > &  a,
D3Vector< T > &  b 
) const
inline

Return the triple cross product of this vector and the other two.

Definition at line 109 of file D3Vector.h.

109  {
110  return cross ( a.cross( b ) ) ;
111  }
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1124
static bool * b
Definition: config.cpp:1043
D3Vector cross(const D3Vector &rhs) const
Return the cross product of this vector and the other.
Definition: D3Vector.h:100
template<class T>
T WireCell::D3Vector< T >::x ( const T &  val)
inline

Definition at line 55 of file D3Vector.h.

55 { return m_v[0] = val; }
D3VectorStore m_v
Definition: D3Vector.h:29
template<class T>
T WireCell::D3Vector< T >::x ( ) const
inline

Access elements by name.

Definition at line 65 of file D3Vector.h.

65 { return m_v[0]; }
D3VectorStore m_v
Definition: D3Vector.h:29
template<class T>
T WireCell::D3Vector< T >::y ( const T &  val)
inline

Definition at line 56 of file D3Vector.h.

56 { return m_v[1] = val; }
D3VectorStore m_v
Definition: D3Vector.h:29
template<class T>
T WireCell::D3Vector< T >::y ( ) const
inline

Definition at line 66 of file D3Vector.h.

66 { return m_v[1]; }
D3VectorStore m_v
Definition: D3Vector.h:29
template<class T>
T WireCell::D3Vector< T >::z ( const T &  val)
inline

Definition at line 57 of file D3Vector.h.

57 { return m_v[2] = val; }
D3VectorStore m_v
Definition: D3Vector.h:29
template<class T>
T WireCell::D3Vector< T >::z ( ) const
inline

Definition at line 67 of file D3Vector.h.

67 { return m_v[2]; }
D3VectorStore m_v
Definition: D3Vector.h:29

Friends And Related Function Documentation

template<class T>
template<class U >
std::ostream& operator<< ( std::ostream &  ,
const D3Vector< U > &   
)
friend

Member Data Documentation

template<class T>
D3VectorStore WireCell::D3Vector< T >::m_v
private

Definition at line 29 of file D3Vector.h.


The documentation for this class was generated from the following file: