g4tools  5.4.0
Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
tools::vec3< T > Class Template Reference

Public Types

typedef T elem_t
 
typedef unsigned int size_type
 

Public Member Functions

unsigned int dimension () const
 
 vec3 ()
 
 vec3 (const T a_vec[3])
 
 vec3 (const T &a0, const T &a1, const T &a2)
 
virtual ~vec3 ()
 
 vec3 (const vec3 &a_from)
 
vec3operator= (const vec3 &a_from)
 
const T & v0 () const
 
const T & v1 () const
 
const T & v2 () const
 
void v0 (const T &a_value)
 
void v1 (const T &a_value)
 
void v2 (const T &a_value)
 
const T & x () const
 
const T & y () const
 
const T & z () const
 
T & x ()
 
T & y ()
 
T & z ()
 
void set_value (const T &a0, const T &a1, const T &a2)
 
void set_value (const T aV[3])
 
void value (T &a0, T &a1, T &a2) const
 
length (T(*a_sqrt)(T)) const
 
normalize (T(*a_sqrt)(T))
 
dot (const vec3 &aV) const
 
void cross (const vec3< T > &aV, vec3< T > &a_value) const
 
bool equal (const vec3 &aV) const
 
template<class PREC >
bool equal_prec (const vec3 &a_v, PREC a_prec, PREC(*a_fabs)(const T &)) const
 
vec3< T > _cross (const vec3< T > &aV) const
 
bool divide (const T &a_T)
 
void multiply (const T &a_T)
 
void add (const vec3 &a_v)
 
void add (const T &a0, const T &a1, const T &a2)
 
void subtract (const vec3 &a_v)
 
void subtract (const T &a0, const T &a1, const T &a2)
 
bool cos_angle (const vec3 &a_v, T &a_cos, T(*a_sqrt)(T)) const
 
bool theta_phi (T &a_theta, T &a_phi, T(*a_sqrt)(T), T(*a_atan2)(T, T)) const
 
T & operator[] (size_t a_index)
 
const T & operator[] (size_t a_index) const
 
vec3operator*= (const T &a_v)
 
vec3 operator+ (const vec3 &a_v) const
 
vec3 operator- (const vec3 &a_v) const
 
vec3 operator* (const T &a_v) const
 
vec3 operator/ (const T &a_v) const
 
bool operator== (const vec3 &a_v) const
 
bool operator!= (const vec3 &a_v) const
 
size_type size () const
 
const T * data () const
 
size_type data_size () const
 
const T * getValue () const
 
void setValue (const T &a0, const T &a1, const T &a2)
 
void getValue (T &a0, T &a1, T &a2) const
 
void setValue (const vec3 &a_v)
 
void setValue (const T aV[3])
 
vec3setValue (const vec3 &a_bary, const vec3 &a_v0, const vec3 &a_v1, const vec3 &a_v2)
 

Static Public Member Functions

static const vec3< T > & s_x ()
 
static const vec3< T > & s_y ()
 
static const vec3< T > & s_z ()
 

Protected Attributes

m_data [3]
 

Detailed Description

template<class T>
class tools::vec3< T >

Definition at line 16 of file vec3.

Member Typedef Documentation

◆ elem_t

template<class T >
typedef T tools::vec3< T >::elem_t

Definition at line 24 of file vec3.

◆ size_type

template<class T >
typedef unsigned int tools::vec3< T >::size_type

Definition at line 264 of file vec3.

Constructor & Destructor Documentation

◆ vec3() [1/4]

template<class T >
tools::vec3< T >::vec3 ( )
inline

Definition at line 27 of file vec3.

27  {
28 #ifdef TOOLS_MEM
29  mem::increment(s_class().c_str());
30 #endif
31  m_data[0] = T();
32  m_data[1] = T();
33  m_data[2] = T();
34  }

◆ vec3() [2/4]

template<class T >
tools::vec3< T >::vec3 ( const T  a_vec[3])
inline

Definition at line 35 of file vec3.

35  {
36 #ifdef TOOLS_MEM
37  mem::increment(s_class().c_str());
38 #endif
39  m_data[0] = a_vec[0];
40  m_data[1] = a_vec[1];
41  m_data[2] = a_vec[2];
42  }

◆ vec3() [3/4]

template<class T >
tools::vec3< T >::vec3 ( const T &  a0,
const T &  a1,
const T &  a2 
)
inline

Definition at line 43 of file vec3.

47  {
48 #ifdef TOOLS_MEM
49  if(a_inc) mem::increment(s_class().c_str());
50 #endif
51  m_data[0] = a0;
52  m_data[1] = a1;
53  m_data[2] = a2;
54  }

◆ ~vec3()

template<class T >
virtual tools::vec3< T >::~vec3 ( )
inlinevirtual

Definition at line 55 of file vec3.

55  {
56 #ifdef TOOLS_MEM
57  mem::decrement(s_class().c_str());
58 #endif
59  }

◆ vec3() [4/4]

template<class T >
tools::vec3< T >::vec3 ( const vec3< T > &  a_from)
inline

Definition at line 61 of file vec3.

61  {
62 #ifdef TOOLS_MEM
63  mem::increment(s_class().c_str());
64 #endif
65  m_data[0] = a_from.m_data[0];
66  m_data[1] = a_from.m_data[1];
67  m_data[2] = a_from.m_data[2];
68  }

Member Function Documentation

◆ _cross()

template<class T >
vec3<T> tools::vec3< T >::_cross ( const vec3< T > &  aV) const
inline

Definition at line 154 of file vec3.

154  {
155  //not effective.
156  return vec3<T>(m_data[1] * aV.m_data[2] - m_data[2] * aV.m_data[1],
157  m_data[2] * aV.m_data[0] - m_data[0] * aV.m_data[2],
158  m_data[0] * aV.m_data[1] - m_data[1] * aV.m_data[0]);
159  }

◆ add() [1/2]

template<class T >
void tools::vec3< T >::add ( const T &  a0,
const T &  a1,
const T &  a2 
)
inline

Definition at line 181 of file vec3.

181  {
182  m_data[0] += a0;
183  m_data[1] += a1;
184  m_data[2] += a2;
185  }

◆ add() [2/2]

template<class T >
void tools::vec3< T >::add ( const vec3< T > &  a_v)
inline

Definition at line 175 of file vec3.

175  {
176  m_data[0] += a_v.m_data[0];
177  m_data[1] += a_v.m_data[1];
178  m_data[2] += a_v.m_data[2];
179  }

◆ cos_angle()

template<class T >
bool tools::vec3< T >::cos_angle ( const vec3< T > &  a_v,
T &  a_cos,
T(*)(T)  a_sqrt 
) const
inline

Definition at line 199 of file vec3.

199  {
200  //WARNING : if ret false, a_cos is not set.
201  T this_length = length(a_sqrt);
202  if(this_length==T()) return false;
203  T a_v_length = a_v.length(a_sqrt);
204  if(a_v_length==T()) return false;
205  a_cos = dot(a_v)/(this_length*a_v_length);
206  return true;
207  }

◆ cross()

template<class T >
void tools::vec3< T >::cross ( const vec3< T > &  aV,
vec3< T > &  a_value 
) const
inline

Definition at line 131 of file vec3.

131  {
132  a_value.set_value(m_data[1] * aV.m_data[2] - m_data[2] * aV.m_data[1],
133  m_data[2] * aV.m_data[0] - m_data[0] * aV.m_data[2],
134  m_data[0] * aV.m_data[1] - m_data[1] * aV.m_data[0]);
135  }

◆ data()

template<class T >
const T* tools::vec3< T >::data ( ) const
inline

Definition at line 266 of file vec3.

266 {return m_data;}

◆ data_size()

template<class T >
size_type tools::vec3< T >::data_size ( ) const
inline

Definition at line 267 of file vec3.

267 {return 3;} //for eqT.

◆ dimension()

template<class T >
unsigned int tools::vec3< T >::dimension ( ) const
inline

Definition at line 25 of file vec3.

25 {return 3;}

◆ divide()

template<class T >
bool tools::vec3< T >::divide ( const T &  a_T)
inline

Definition at line 161 of file vec3.

161  {
162  if(a_T==T()) return false;
163  m_data[0] /= a_T;
164  m_data[1] /= a_T;
165  m_data[2] /= a_T;
166  return true;
167  }

◆ dot()

template<class T >
T tools::vec3< T >::dot ( const vec3< T > &  aV) const
inline

Definition at line 125 of file vec3.

125  {
126  return (m_data[0] * aV.m_data[0] +
127  m_data[1] * aV.m_data[1] +
128  m_data[2] * aV.m_data[2]);
129  }

◆ equal()

template<class T >
bool tools::vec3< T >::equal ( const vec3< T > &  aV) const
inline

Definition at line 137 of file vec3.

137  {
138  if(m_data[0]!=aV.m_data[0]) return false;
139  if(m_data[1]!=aV.m_data[1]) return false;
140  if(m_data[2]!=aV.m_data[2]) return false;
141  return true;
142  }

◆ equal_prec()

template<class T >
template<class PREC >
bool tools::vec3< T >::equal_prec ( const vec3< T > &  a_v,
PREC  a_prec,
PREC(*)(const T &)  a_fabs 
) const
inline

Definition at line 145 of file vec3.

145  {
146  if(&a_v==this) return true;
147  for(unsigned int index=0;index<3;index++) {
148  T diff = m_data[index]-a_v.m_data[index];
149  if(a_fabs(diff)>=a_prec) return false;
150  }
151  return true;
152  }

◆ getValue() [1/2]

template<class T >
const T* tools::vec3< T >::getValue ( ) const
inline

Definition at line 269 of file vec3.

269 {return m_data;}

◆ getValue() [2/2]

template<class T >
void tools::vec3< T >::getValue ( T &  a0,
T &  a1,
T &  a2 
) const
inline

Definition at line 275 of file vec3.

275  {
276  a0 = m_data[0];
277  a1 = m_data[1];
278  a2 = m_data[2];
279  }

◆ length()

template<class T >
T tools::vec3< T >::length ( T(*)(T)  a_sqrt) const
inline

Definition at line 114 of file vec3.

114  {
115  return a_sqrt(m_data[0]*m_data[0]+m_data[1]*m_data[1]+m_data[2]*m_data[2]);
116  }

◆ multiply()

template<class T >
void tools::vec3< T >::multiply ( const T &  a_T)
inline

Definition at line 169 of file vec3.

169  {
170  m_data[0] *= a_T;
171  m_data[1] *= a_T;
172  m_data[2] *= a_T;
173  }

◆ normalize()

template<class T >
T tools::vec3< T >::normalize ( T(*)(T)  a_sqrt)
inline

Definition at line 118 of file vec3.

118  {
119  T norme = length(a_sqrt);
120  if(norme==T()) return T();
121  divide(norme);
122  return norme;
123  }

◆ operator!=()

template<class T >
bool tools::vec3< T >::operator!= ( const vec3< T > &  a_v) const
inline

Definition at line 261 of file vec3.

261 {return !operator==(a_v);}

◆ operator*()

template<class T >
vec3 tools::vec3< T >::operator* ( const T &  a_v) const
inline

Definition at line 247 of file vec3.

247  {
248  return vec3(m_data[0]*a_v,
249  m_data[1]*a_v,
250  m_data[2]*a_v);
251  }

◆ operator*=()

template<class T >
vec3& tools::vec3< T >::operator*= ( const T &  a_v)
inline

Definition at line 228 of file vec3.

228  {
229  m_data[0] *= a_v;
230  m_data[1] *= a_v;
231  m_data[2] *= a_v;
232  return *this;
233  }

◆ operator+()

template<class T >
vec3 tools::vec3< T >::operator+ ( const vec3< T > &  a_v) const
inline

Definition at line 235 of file vec3.

235  {
236  return vec3(m_data[0]+a_v.m_data[0],
237  m_data[1]+a_v.m_data[1],
238  m_data[2]+a_v.m_data[2]);
239  }

◆ operator-()

template<class T >
vec3 tools::vec3< T >::operator- ( const vec3< T > &  a_v) const
inline

Definition at line 241 of file vec3.

241  {
242  return vec3(m_data[0]-a_v.m_data[0],
243  m_data[1]-a_v.m_data[1],
244  m_data[2]-a_v.m_data[2]);
245  }

◆ operator/()

template<class T >
vec3 tools::vec3< T >::operator/ ( const T &  a_v) const
inline

Definition at line 253 of file vec3.

253  {
254  if(a_v==T()) return vec3();
255  return vec3(m_data[0]/a_v,
256  m_data[1]/a_v,
257  m_data[2]/a_v);
258  }

◆ operator=()

template<class T >
vec3& tools::vec3< T >::operator= ( const vec3< T > &  a_from)
inline

Definition at line 69 of file vec3.

69  {
70  m_data[0] = a_from.m_data[0];
71  m_data[1] = a_from.m_data[1];
72  m_data[2] = a_from.m_data[2];
73  return *this;
74  }

◆ operator==()

template<class T >
bool tools::vec3< T >::operator== ( const vec3< T > &  a_v) const
inline

Definition at line 260 of file vec3.

260 {return equal(a_v);}

◆ operator[]() [1/2]

template<class T >
T& tools::vec3< T >::operator[] ( size_t  a_index)
inline

Definition at line 219 of file vec3.

219  {
220  //WARNING : no check on a_index.
221  return m_data[a_index];
222  }

◆ operator[]() [2/2]

template<class T >
const T& tools::vec3< T >::operator[] ( size_t  a_index) const
inline

Definition at line 223 of file vec3.

223  {
224  //WARNING : no check on a_index.
225  return m_data[a_index];
226  }

◆ s_x()

template<class T >
static const vec3<T>& tools::vec3< T >::s_x ( )
inlinestatic

Definition at line 305 of file vec3.

305 {static const vec3<T> s_v(1,0,0);return s_v;}

◆ s_y()

template<class T >
static const vec3<T>& tools::vec3< T >::s_y ( )
inlinestatic

Definition at line 306 of file vec3.

306 {static const vec3<T> s_v(0,1,0);return s_v;}

◆ s_z()

template<class T >
static const vec3<T>& tools::vec3< T >::s_z ( )
inlinestatic

Definition at line 307 of file vec3.

307 {static const vec3<T> s_v(0,0,1);return s_v;}

◆ set_value() [1/2]

template<class T >
void tools::vec3< T >::set_value ( const T &  a0,
const T &  a1,
const T &  a2 
)
inline

Definition at line 92 of file vec3.

92  {
93  m_data[0] = a0;
94  m_data[1] = a1;
95  m_data[2] = a2;
96  }

◆ set_value() [2/2]

template<class T >
void tools::vec3< T >::set_value ( const T  aV[3])
inline

Definition at line 97 of file vec3.

97  {
98  m_data[0] = aV[0];
99  m_data[1] = aV[1];
100  m_data[2] = aV[2];
101  }

◆ setValue() [1/4]

template<class T >
void tools::vec3< T >::setValue ( const T &  a0,
const T &  a1,
const T &  a2 
)
inline

Definition at line 270 of file vec3.

270  {
271  m_data[0] = a0;
272  m_data[1] = a1;
273  m_data[2] = a2;
274  }

◆ setValue() [2/4]

template<class T >
void tools::vec3< T >::setValue ( const T  aV[3])
inline

Definition at line 285 of file vec3.

285  {
286  m_data[0] = aV[0];
287  m_data[1] = aV[1];
288  m_data[2] = aV[2];
289  }

◆ setValue() [3/4]

template<class T >
vec3& tools::vec3< T >::setValue ( const vec3< T > &  a_bary,
const vec3< T > &  a_v0,
const vec3< T > &  a_v1,
const vec3< T > &  a_v2 
)
inline

Definition at line 291 of file vec3.

292  {
293  m_data[0] = a_bary[0]*a_v0[0]+a_bary[1]*a_v1[0]+a_bary[2]*a_v2[0];
294  m_data[1] = a_bary[0]*a_v0[1]+a_bary[1]*a_v1[1]+a_bary[2]*a_v2[1];
295  m_data[2] = a_bary[0]*a_v0[2]+a_bary[1]*a_v1[2]+a_bary[2]*a_v2[2];
296  return *this;
297  }

◆ setValue() [4/4]

template<class T >
void tools::vec3< T >::setValue ( const vec3< T > &  a_v)
inline

Definition at line 280 of file vec3.

280  {
281  m_data[0] = a_v.m_data[0];
282  m_data[1] = a_v.m_data[1];
283  m_data[2] = a_v.m_data[2];
284  }

◆ size()

template<class T >
size_type tools::vec3< T >::size ( ) const
inline

Definition at line 265 of file vec3.

265 {return 3;}

◆ subtract() [1/2]

template<class T >
void tools::vec3< T >::subtract ( const T &  a0,
const T &  a1,
const T &  a2 
)
inline

Definition at line 193 of file vec3.

193  {
194  m_data[0] -= a0;
195  m_data[1] -= a1;
196  m_data[2] -= a2;
197  }

◆ subtract() [2/2]

template<class T >
void tools::vec3< T >::subtract ( const vec3< T > &  a_v)
inline

Definition at line 187 of file vec3.

187  {
188  m_data[0] -= a_v.m_data[0];
189  m_data[1] -= a_v.m_data[1];
190  m_data[2] -= a_v.m_data[2];
191  }

◆ theta_phi()

template<class T >
bool tools::vec3< T >::theta_phi ( T &  a_theta,
T &  a_phi,
T(*)(T)  a_sqrt,
T(*)(T, T)  a_atan2 
) const
inline

Definition at line 209 of file vec3.

209  {
210  //WARNING : if ret false, a_theta, a_phi are not set.
211  if(length(a_sqrt)==T()) return false;
212  a_phi = a_atan2(m_data[1],m_data[0]);
213  T xy = a_sqrt(m_data[0]*m_data[0]+m_data[1]*m_data[1]);
214  a_theta = a_atan2(xy,m_data[2]);
215  return true;
216  }

◆ v0() [1/2]

template<class T >
const T& tools::vec3< T >::v0 ( ) const
inline

Definition at line 76 of file vec3.

76 { return m_data[0];}

◆ v0() [2/2]

template<class T >
void tools::vec3< T >::v0 ( const T &  a_value)
inline

Definition at line 80 of file vec3.

80 { m_data[0] = a_value;}

◆ v1() [1/2]

template<class T >
const T& tools::vec3< T >::v1 ( ) const
inline

Definition at line 77 of file vec3.

77 { return m_data[1];}

◆ v1() [2/2]

template<class T >
void tools::vec3< T >::v1 ( const T &  a_value)
inline

Definition at line 81 of file vec3.

81 { m_data[1] = a_value;}

◆ v2() [1/2]

template<class T >
const T& tools::vec3< T >::v2 ( ) const
inline

Definition at line 78 of file vec3.

78 { return m_data[2];}

◆ v2() [2/2]

template<class T >
void tools::vec3< T >::v2 ( const T &  a_value)
inline

Definition at line 82 of file vec3.

82 { m_data[2] = a_value;}

◆ value()

template<class T >
void tools::vec3< T >::value ( T &  a0,
T &  a1,
T &  a2 
) const
inline

Definition at line 102 of file vec3.

102  {
103  a0 = m_data[0];
104  a1 = m_data[1];
105  a2 = m_data[2];
106  }

◆ x() [1/2]

template<class T >
T& tools::vec3< T >::x ( )
inline

Definition at line 88 of file vec3.

88 {return m_data[0];}

◆ x() [2/2]

template<class T >
const T& tools::vec3< T >::x ( ) const
inline

Definition at line 84 of file vec3.

84 {return m_data[0];}

◆ y() [1/2]

template<class T >
T& tools::vec3< T >::y ( )
inline

Definition at line 89 of file vec3.

89 {return m_data[1];}

◆ y() [2/2]

template<class T >
const T& tools::vec3< T >::y ( ) const
inline

Definition at line 85 of file vec3.

85 {return m_data[1];}

◆ z() [1/2]

template<class T >
T& tools::vec3< T >::z ( )
inline

Definition at line 90 of file vec3.

90 {return m_data[2];}

◆ z() [2/2]

template<class T >
const T& tools::vec3< T >::z ( ) const
inline

Definition at line 86 of file vec3.

86 {return m_data[2];}

Member Data Documentation

◆ m_data

template<class T >
T tools::vec3< T >::m_data[3]
protected

Definition at line 310 of file vec3.


The documentation for this class was generated from the following file:
tools::vec3::length
T length(T(*a_sqrt)(T)) const
Definition: vec3:114
tools::vec3::vec3
vec3()
Definition: vec3:27
tools::vec3::divide
bool divide(const T &a_T)
Definition: vec3:161
tools::vec3::operator==
bool operator==(const vec3 &a_v) const
Definition: vec3:260
tools::diff
void diff(std::ostream &a_out, const array< T > &aA, const array< T > &aB, T a_epsilon)
Definition: array:529
tools::vec3::equal
bool equal(const vec3 &aV) const
Definition: vec3:137
tools::vec3::m_data
T m_data[3]
Definition: vec3:310
tools::vec3::dot
T dot(const vec3 &aV) const
Definition: vec3:125