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

Public Types

typedef T elem_t
 
typedef unsigned int size_type
 

Public Member Functions

unsigned int dimension () const
 
 vec2 ()
 
 vec2 (const T a_vec[2])
 
 vec2 (const T &a0, const T &a1)
 
virtual ~vec2 ()
 
 vec2 (const vec2 &a_from)
 
vec2operator= (const vec2 &a_from)
 
const T & v0 () const
 
const T & v1 () const
 
void v0 (const T &a_value)
 
void v1 (const T &a_value)
 
const T & x () const
 
const T & y () const
 
T & x ()
 
T & y ()
 
void set_value (const T &a0, const T &a1)
 
void set_value (const T aV[2])
 
void value (T &a0, T &a1) const
 
length (T(*a_sqrt)(T)) const
 
normalize (T(*a_sqrt)(T))
 
dot (const vec2 &aV) const
 
cross (const vec2 &aV) const
 
bool equal (const vec2 &aV) const
 
bool divide (const T &a_T)
 
void add (const vec2 &a_v)
 
void add (const T &a0, const T &a1)
 
void subtract (const vec2 &a_v)
 
void subtract (const T &a0, const T &a1)
 
T & operator[] (size_t a_index)
 
const T & operator[] (size_t a_index) const
 
vec2 operator+ (const vec2 &a_v) const
 
vec2 operator- (const vec2 &a_v) const
 
vec2 operator* (const T &a_v) const
 
bool operator== (const vec2 &a_v) const
 
bool operator!= (const vec2 &a_v) const
 
size_type size () const
 
const T * data () const
 
const T * getValue () const
 
void getValue (T &a0, T &a1) const
 
void setValue (const T &a0, const T &a1)
 
void setValue (const T aV[2])
 

Protected Attributes

m_data [2]
 

Detailed Description

template<class T>
class tools::vec2< T >

Definition at line 16 of file vec2.

Member Typedef Documentation

◆ elem_t

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

Definition at line 24 of file vec2.

◆ size_type

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

Definition at line 179 of file vec2.

Constructor & Destructor Documentation

◆ vec2() [1/4]

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

Definition at line 27 of file vec2.

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  }

◆ vec2() [2/4]

template<class T >
tools::vec2< T >::vec2 ( const T  a_vec[2])
inline

Definition at line 34 of file vec2.

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

◆ vec2() [3/4]

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

Definition at line 41 of file vec2.

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

◆ ~vec2()

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

Definition at line 48 of file vec2.

48  {
49 #ifdef TOOLS_MEM
50  mem::decrement(s_class().c_str());
51 #endif
52  }

◆ vec2() [4/4]

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

Definition at line 54 of file vec2.

54  {
55 #ifdef TOOLS_MEM
56  mem::increment(s_class().c_str());
57 #endif
58  m_data[0] = a_from.m_data[0];
59  m_data[1] = a_from.m_data[1];
60  }

Member Function Documentation

◆ add() [1/2]

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

Definition at line 135 of file vec2.

135  {
136  m_data[0] += a0;
137  m_data[1] += a1;
138  }

◆ add() [2/2]

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

Definition at line 130 of file vec2.

130  {
131  m_data[0] += a_v.m_data[0];
132  m_data[1] += a_v.m_data[1];
133  }

◆ cross()

template<class T >
T tools::vec2< T >::cross ( const vec2< T > &  aV) const
inline

Definition at line 113 of file vec2.

113  {
114  return (m_data[0] * aV.m_data[1] - m_data[1] * aV.m_data[0]);
115  }

◆ data()

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

Definition at line 181 of file vec2.

181 {return m_data;}

◆ dimension()

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

Definition at line 25 of file vec2.

25 {return 2;}

◆ divide()

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

Definition at line 123 of file vec2.

123  {
124  if(a_T==T()) return false;
125  m_data[0] /= a_T;
126  m_data[1] /= a_T;
127  return true;
128  }

◆ dot()

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

Definition at line 108 of file vec2.

108  {
109  return (m_data[0] * aV.m_data[0] +
110  m_data[1] * aV.m_data[1]);
111  }

◆ equal()

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

Definition at line 117 of file vec2.

117  {
118  if(m_data[0]!=aV.m_data[0]) return false;
119  if(m_data[1]!=aV.m_data[1]) return false;
120  return true;
121  }

◆ getValue() [1/2]

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

Definition at line 183 of file vec2.

183 {return m_data;}

◆ getValue() [2/2]

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

Definition at line 184 of file vec2.

184  {
185  a0 = m_data[0];
186  a1 = m_data[1];
187  }

◆ length()

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

Definition at line 97 of file vec2.

97  {
98  return a_sqrt(m_data[0]*m_data[0]+m_data[1]*m_data[1]);
99  }

◆ normalize()

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

Definition at line 101 of file vec2.

101  {
102  T norme = length(a_sqrt);
103  if(norme==T()) return T();
104  divide(norme);
105  return norme;
106  }

◆ operator!=()

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

Definition at line 176 of file vec2.

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

◆ operator*()

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

Definition at line 170 of file vec2.

170  {
171  return vec2(m_data[0]*a_v,
172  m_data[1]*a_v);
173  }

◆ operator+()

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

Definition at line 160 of file vec2.

160  {
161  return vec2(m_data[0]+a_v.m_data[0],
162  m_data[1]+a_v.m_data[1]);
163  }

◆ operator-()

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

Definition at line 165 of file vec2.

165  {
166  return vec2(m_data[0]-a_v.m_data[0],
167  m_data[1]-a_v.m_data[1]);
168  }

◆ operator=()

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

Definition at line 61 of file vec2.

61  {
62  m_data[0] = a_from.m_data[0];
63  m_data[1] = a_from.m_data[1];
64  return *this;
65  }

◆ operator==()

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

Definition at line 175 of file vec2.

175 {return equal(a_v);}

◆ operator[]() [1/2]

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

Definition at line 151 of file vec2.

151  {
152  //WARNING : no check on a_index.
153  return m_data[a_index];
154  }

◆ operator[]() [2/2]

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

Definition at line 155 of file vec2.

155  {
156  //WARNING : no check on a_index.
157  return m_data[a_index];
158  }

◆ set_value() [1/2]

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

Definition at line 78 of file vec2.

78  {
79  m_data[0] = a0;
80  m_data[1] = a1;
81  }

◆ set_value() [2/2]

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

Definition at line 82 of file vec2.

82  {
83  m_data[0] = aV[0];
84  m_data[1] = aV[1];
85  }

◆ setValue() [1/2]

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

Definition at line 188 of file vec2.

188  {
189  m_data[0] = a0;
190  m_data[1] = a1;
191  }

◆ setValue() [2/2]

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

Definition at line 192 of file vec2.

192  {
193  m_data[0] = aV[0];
194  m_data[1] = aV[1];
195  }

◆ size()

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

Definition at line 180 of file vec2.

180 {return 2;}

◆ subtract() [1/2]

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

Definition at line 145 of file vec2.

145  {
146  m_data[0] -= a0;
147  m_data[1] -= a1;
148  }

◆ subtract() [2/2]

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

Definition at line 140 of file vec2.

140  {
141  m_data[0] -= a_v.m_data[0];
142  m_data[1] -= a_v.m_data[1];
143  }

◆ v0() [1/2]

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

Definition at line 67 of file vec2.

67 { return m_data[0];}

◆ v0() [2/2]

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

Definition at line 70 of file vec2.

70 { m_data[0] = a_value;}

◆ v1() [1/2]

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

Definition at line 68 of file vec2.

68 { return m_data[1];}

◆ v1() [2/2]

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

Definition at line 71 of file vec2.

71 { m_data[1] = a_value;}

◆ value()

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

Definition at line 86 of file vec2.

86  {
87  a0 = m_data[0];
88  a1 = m_data[1];
89  }

◆ x() [1/2]

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

Definition at line 75 of file vec2.

75 {return m_data[0];}

◆ x() [2/2]

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

Definition at line 73 of file vec2.

73 {return m_data[0];}

◆ y() [1/2]

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

Definition at line 76 of file vec2.

76 {return m_data[1];}

◆ y() [2/2]

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

Definition at line 74 of file vec2.

74 {return m_data[1];}

Member Data Documentation

◆ m_data

template<class T >
T tools::vec2< T >::m_data[2]
protected

Definition at line 197 of file vec2.


The documentation for this class was generated from the following file:
tools::vec2::m_data
T m_data[2]
Definition: vec2:197
tools::vec2::operator==
bool operator==(const vec2 &a_v) const
Definition: vec2:175
tools::vec2::vec2
vec2()
Definition: vec2:27
tools::vec2::length
T length(T(*a_sqrt)(T)) const
Definition: vec2:97
tools::vec2::divide
bool divide(const T &a_T)
Definition: vec2:123
tools::vec2::equal
bool equal(const vec2 &aV) const
Definition: vec2:117