DynVectorKernel.h
Go to the documentation of this file.
1#ifndef GfxTL__DYNVECTORKERNEL_HEADER__
2#define GfxTL__DYNVECTORKERNEL_HEADER__
3
4namespace GfxTL
5{
6 template <class T>
8 {
9 public:
10 DynVectorKernel(unsigned int dim);
11
12 void Add(const T a[], const T b[], T* r) const;
13 T Dot(const T a[], const T b[]) const;
14 T SqrDistance(const T a[], const T b[]) const;
15
16 private:
17 unsigned int m_dim;
18 };
19
20 template <class T>
21 DynVectorKernel<T>::DynVectorKernel(unsigned int dim) : m_dim(dim)
22 {
23 }
24
25 template <class T>
26 void
27 DynVectorKernel<T>::Add(const T a[], const T b[], T* r) const
28 {
29 for (unsigned int i = 0; i < m_dim; ++i)
30 {
31 r[i] = a[i] + b[i];
32 }
33 }
34
35 template <class T>
36 T
37 DynVectorKernel<T>::Dot(const T a[], const T b[]) const
38 {
39 T r = a[0] * b[0];
40 for (size_t i = 1; i < m_dim; ++i)
41 {
42 r += a[i] * b[i];
43 }
44 return r;
45 }
46
47 template <class T>
48 T
49 DynVectorKernel<T>::SqrDistance(const T a[], const T b[]) const
50 {
51 T r = 0, d;
52 for (size_t i = 0; i < m_dim; ++i)
53 {
54 d = a[i] - b[i];
55 r += d * d;
56 }
57 return r;
58 }
59}; // namespace GfxTL
60
61#endif
DynVectorKernel(unsigned int dim)
T Dot(const T a[], const T b[]) const
void Add(const T a[], const T b[], T *r) const
T SqrDistance(const T a[], const T b[]) const
Definition AABox.h:10