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

Public Types

typedef T elem_t
 
typedef unsigned int size_type
 

Public Member Functions

unsigned int dimension () const
 
 vec4 ()
 
 vec4 (const T a_vec[4])
 
 vec4 (const T &a0, const T &a1, const T &a2, const T &a3)
 
virtual ~vec4 ()
 
 vec4 (const vec4 &a_from)
 
vec4operator= (const vec4 &a_from)
 
const T & v0 () const
 
const T & v1 () const
 
const T & v2 () const
 
const T & v3 () const
 
void v0 (const T &a_value)
 
void v1 (const T &a_value)
 
void v2 (const T &a_value)
 
void v3 (const T &a_value)
 
const T & x () const
 
const T & y () const
 
const T & z () const
 
const T & t () const
 
void set_value (const T &a0, const T &a1, const T &a2, const T &a3)
 
void set_value (const T aV[4])
 
void value (T &a0, T &a1, T &a2, T &a3) const
 
bool set_value (unsigned int a_index, const T &a_value)
 
length (T(*a_sqrt)(T)) const
 
normalize (T(*a_sqrt)(T))
 
bool equal (const vec4 &a_vec) const
 
bool equal (const vec4 &a_vec, const T &a_epsil) const
 
bool is_proportional (const vec4 &a_vec, T &a_factor) const
 
void multiply (const T &a_T)
 
bool divide (const T &a_T)
 
void add (const vec4 &a_v)
 
void add (const T &a0, const T &a1, const T &a2, const T &a3)
 
void subtract (const vec4 &a_v)
 
void subtract (const T &a0, const T &a1, const T &a2, const T &a3)
 
T & operator[] (size_t a_index)
 
const T & operator[] (size_t a_index) const
 
vec4 operator+ (const vec4 &a_v) const
 
vec4 operator- (const vec4 &a_v) const
 
vec4 operator* (const T &a_v) const
 
bool operator== (const vec4 &a_v) const
 
bool operator!= (const vec4 &a_v) const
 
size_type size () const
 
const T * data () const
 

Static Protected Member Functions

static T zero ()
 
static T minus_one ()
 

Protected Attributes

m_data [4]
 

Detailed Description

template<class T>
class tools::vec4< T >

Definition at line 16 of file vec4.

Member Typedef Documentation

◆ elem_t

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

Definition at line 28 of file vec4.

◆ size_type

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

Definition at line 258 of file vec4.

Constructor & Destructor Documentation

◆ vec4() [1/4]

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

Definition at line 31 of file vec4.

31  {
32 #ifdef TOOLS_MEM
33  mem::increment(s_class().c_str());
34 #endif
35  m_data[0] = T();
36  m_data[1] = T();
37  m_data[2] = T();
38  m_data[3] = T();
39  }

◆ vec4() [2/4]

template<class T >
tools::vec4< T >::vec4 ( const T  a_vec[4])
inline

Definition at line 40 of file vec4.

40  {
41 #ifdef TOOLS_MEM
42  mem::increment(s_class().c_str());
43 #endif
44  m_data[0] = a_vec[0];
45  m_data[1] = a_vec[1];
46  m_data[2] = a_vec[2];
47  m_data[3] = a_vec[3];
48  }

◆ vec4() [3/4]

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

Definition at line 49 of file vec4.

53  {
54 #ifdef TOOLS_MEM
55  if(a_inc) mem::increment(s_class().c_str());
56 #endif
57  m_data[0] = a0;
58  m_data[1] = a1;
59  m_data[2] = a2;
60  m_data[3] = a3;
61  }

◆ ~vec4()

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

Definition at line 62 of file vec4.

62  {
63 #ifdef TOOLS_MEM
64  mem::decrement(s_class().c_str());
65 #endif
66  }

◆ vec4() [4/4]

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

Definition at line 68 of file vec4.

68  {
69 #ifdef TOOLS_MEM
70  mem::increment(s_class().c_str());
71 #endif
72  m_data[0] = a_from.m_data[0];
73  m_data[1] = a_from.m_data[1];
74  m_data[2] = a_from.m_data[2];
75  m_data[3] = a_from.m_data[3];
76  }

Member Function Documentation

◆ add() [1/2]

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

Definition at line 202 of file vec4.

202  {
203  m_data[0] += a0;
204  m_data[1] += a1;
205  m_data[2] += a2;
206  m_data[3] += a3;
207  }

◆ add() [2/2]

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

Definition at line 195 of file vec4.

195  {
196  m_data[0] += a_v.m_data[0];
197  m_data[1] += a_v.m_data[1];
198  m_data[2] += a_v.m_data[2];
199  m_data[3] += a_v.m_data[3];
200  }

◆ data()

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

Definition at line 260 of file vec4.

260 {return m_data;}

◆ dimension()

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

Definition at line 29 of file vec4.

29 {return 4;}

◆ divide()

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

Definition at line 186 of file vec4.

186  {
187  if(a_T==T()) return false;
188  m_data[0] /= a_T;
189  m_data[1] /= a_T;
190  m_data[2] /= a_T;
191  m_data[3] /= a_T;
192  return true;
193  }

◆ equal() [1/2]

template<class T >
bool tools::vec4< T >::equal ( const vec4< T > &  a_vec) const
inline

Definition at line 136 of file vec4.

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

◆ equal() [2/2]

template<class T >
bool tools::vec4< T >::equal ( const vec4< T > &  a_vec,
const T &  a_epsil 
) const
inline

Definition at line 143 of file vec4.

143  {
144  T* tp = (T*)m_data;
145  T* ap = (T*)a_vec.m_data;
146  for(unsigned int i=0;i<4;i++,tp++,ap++) {
147  T diff = (*tp) - (*ap);
148  if(diff<zero()) diff *= minus_one();
149  if(diff>=a_epsil) return false;
150  }
151  return true;
152  }

◆ is_proportional()

template<class T >
bool tools::vec4< T >::is_proportional ( const vec4< T > &  a_vec,
T &  a_factor 
) const
inline

Definition at line 154 of file vec4.

154  {
155  // If true, then : a_vec = a_factor * this.
156  a_factor = zero();
157  bool first = true;
158  T* tp = (T*)m_data;
159  T* ap = (T*)a_vec.m_data;
160  for(unsigned int i=0;i<4;i++,tp++,ap++) {
161  if( ((*tp)==zero()) && ((*ap)==zero())) {
162  continue;
163  } else if( ((*tp)!=zero()) && ((*ap)==zero())) {
164  return false;
165  } else if( ((*tp)==zero()) && ((*ap)!=zero())) {
166  return false;
167  } else {
168  if(first) {
169  a_factor = (*ap)/(*tp);
170  first = false;
171  } else {
172  if((*ap)!=(*tp)*a_factor) return false;
173  }
174  }
175  }
176  return true;
177  }

◆ length()

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

Definition at line 125 of file vec4.

125  {
126  return a_sqrt(m_data[0]*m_data[0]+m_data[1]*m_data[1]+m_data[2]*m_data[2]+m_data[3]*m_data[3]);
127  }

◆ minus_one()

template<class T >
static T tools::vec4< T >::minus_one ( )
inlinestaticprotected

Definition at line 26 of file vec4.

26 {return T(-1);}

◆ multiply()

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

Definition at line 179 of file vec4.

179  {
180  m_data[0] *= a_T;
181  m_data[1] *= a_T;
182  m_data[2] *= a_T;
183  m_data[3] *= a_T;
184  }

◆ normalize()

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

Definition at line 129 of file vec4.

129  {
130  T norme = length(a_sqrt);
131  if(norme==T()) return T();
132  divide(norme);
133  return norme;
134  }

◆ operator!=()

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

Definition at line 255 of file vec4.

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

◆ operator*()

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

Definition at line 247 of file vec4.

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

◆ operator+()

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

Definition at line 233 of file vec4.

233  {
234  return vec4(m_data[0]+a_v.m_data[0],
235  m_data[1]+a_v.m_data[1],
236  m_data[2]+a_v.m_data[2],
237  m_data[3]+a_v.m_data[3]);
238  }

◆ operator-()

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

Definition at line 240 of file vec4.

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

◆ operator=()

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

Definition at line 77 of file vec4.

77  {
78  m_data[0] = a_from.m_data[0];
79  m_data[1] = a_from.m_data[1];
80  m_data[2] = a_from.m_data[2];
81  m_data[3] = a_from.m_data[3];
82  return *this;
83  }

◆ operator==()

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

Definition at line 254 of file vec4.

254 {return equal(a_v);}

◆ operator[]() [1/2]

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

Definition at line 224 of file vec4.

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

◆ operator[]() [2/2]

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

Definition at line 228 of file vec4.

228  {
229  //WARNING : no check on a_index.
230  return m_data[a_index];
231  }

◆ set_value() [1/3]

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

Definition at line 100 of file vec4.

100  {
101  m_data[0] = a0;
102  m_data[1] = a1;
103  m_data[2] = a2;
104  m_data[3] = a3;
105  }

◆ set_value() [2/3]

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

Definition at line 106 of file vec4.

106  {
107  m_data[0] = aV[0];
108  m_data[1] = aV[1];
109  m_data[2] = aV[2];
110  m_data[3] = aV[3];
111  }

◆ set_value() [3/3]

template<class T >
bool tools::vec4< T >::set_value ( unsigned int  a_index,
const T &  a_value 
)
inline

Definition at line 119 of file vec4.

119  {
120  if(a_index>=4) return false;
121  m_data[a_index] = a_value;
122  return true;
123  }

◆ size()

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

Definition at line 259 of file vec4.

259 {return 4;}

◆ subtract() [1/2]

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

Definition at line 216 of file vec4.

216  {
217  m_data[0] -= a0;
218  m_data[1] -= a1;
219  m_data[2] -= a2;
220  m_data[3] -= a3;
221  }

◆ subtract() [2/2]

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

Definition at line 209 of file vec4.

209  {
210  m_data[0] -= a_v.m_data[0];
211  m_data[1] -= a_v.m_data[1];
212  m_data[2] -= a_v.m_data[2];
213  m_data[3] -= a_v.m_data[3];
214  }

◆ t()

template<class T >
const T& tools::vec4< T >::t ( ) const
inline

Definition at line 98 of file vec4.

98 { return m_data[3];}

◆ v0() [1/2]

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

Definition at line 85 of file vec4.

85 { return m_data[0];}

◆ v0() [2/2]

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

Definition at line 90 of file vec4.

90 { m_data[0] = a_value;}

◆ v1() [1/2]

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

Definition at line 86 of file vec4.

86 { return m_data[1];}

◆ v1() [2/2]

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

Definition at line 91 of file vec4.

91 { m_data[1] = a_value;}

◆ v2() [1/2]

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

Definition at line 87 of file vec4.

87 { return m_data[2];}

◆ v2() [2/2]

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

Definition at line 92 of file vec4.

92 { m_data[2] = a_value;}

◆ v3() [1/2]

template<class T >
const T& tools::vec4< T >::v3 ( ) const
inline

Definition at line 88 of file vec4.

88 { return m_data[3];}

◆ v3() [2/2]

template<class T >
void tools::vec4< T >::v3 ( const T &  a_value)
inline

Definition at line 93 of file vec4.

93 { m_data[3] = a_value;}

◆ value()

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

Definition at line 112 of file vec4.

112  {
113  a0 = m_data[0];
114  a1 = m_data[1];
115  a2 = m_data[2];
116  a3 = m_data[3];
117  }

◆ x()

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

Definition at line 95 of file vec4.

95 { return m_data[0];}

◆ y()

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

Definition at line 96 of file vec4.

96 { return m_data[1];}

◆ z()

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

Definition at line 97 of file vec4.

97 { return m_data[2];}

◆ zero()

template<class T >
static T tools::vec4< T >::zero ( )
inlinestaticprotected

Definition at line 25 of file vec4.

25 {return T();}

Member Data Documentation

◆ m_data

template<class T >
T tools::vec4< T >::m_data[4]
protected

Definition at line 262 of file vec4.


The documentation for this class was generated from the following file:
tools::vec4::divide
bool divide(const T &a_T)
Definition: vec4:186
tools::vec4::m_data
T m_data[4]
Definition: vec4:262
tools::vec4::equal
bool equal(const vec4 &a_vec) const
Definition: vec4:136
tools::vec4::zero
static T zero()
Definition: vec4:25
tools::vec4::length
T length(T(*a_sqrt)(T)) const
Definition: vec4:125
tools::vec4::operator==
bool operator==(const vec4 &a_v) const
Definition: vec4:254
tools::vec4::minus_one
static T minus_one()
Definition: vec4:26
tools::vec4::vec4
vec4()
Definition: vec4:31
tools::diff
void diff(std::ostream &a_out, const array< T > &aA, const array< T > &aB, T a_epsilon)
Definition: array:529