VR-Forces 4.6 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DtVector2.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2017 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
9 #pragma once
10 
14 
15 #include <list>
16 #include <vector>
17 
18 namespace makVrv {
19 
22  template <class T>
23  class DtVector2
24  {
25  public:
29  DtVector2(T _x, T _y): x(_x), y (_y){}
30 
33 
34  const void* ptr(void) const{return &x;}
35 
36  T operator[](size_t index) const;
37 
38  T length(void) const;
39 
40  bool isEqual(const DtVector2& rhs, T tolerance) const;
41 
42  DtVector2 operator+(const DtVector2& rhs) const;
43  DtVector2 operator-(const DtVector2& rhs) const;
44 
45  DtVector2 operator+(T fScalar) const;
46  DtVector2 operator-(T fScalar) const;
47  DtVector2 operator*(T fScalar) const;
48  DtVector2 operator/(T fScalar) const;
49 
50  DtVector2 operator/(const DtVector2& rhs) const;
51 
52  DtVector2 getNormalizedCopy(void) const;
53 
54  T getDotProduct(const DtVector2& rhs) const;
55 
56  T x, y;
57 
60 
61  static size_t sizeInBytes(void);
62  };
63 
64  template <class T>
66  template <class T>
68 
69  template <class T>
71  {
72  return DtVector2<T>(x+rhs.x, y+rhs.y);
73  }
74  template <class T>
75  DtVector2<T> DtVector2<T>::operator-(const DtVector2<T>& rhs) const
76  {
77  return DtVector2<T>(x-rhs.x, y-rhs.y);
78  }
79 
80  template <class T>
82  {
83  return DtVector2<T>(x+fScalar, y+fScalar);
84  }
85 
86  template <class T>
88  {
89  return DtVector2<T>(x-fScalar, y-fScalar);
90  }
91 
92  template <class T>
94  {
95  return DtVector2<T>(x*fScalar, y*fScalar);
96  }
97 
98  template <class T>
100  {
101  T OneByfScalar = T(1.0)/fScalar;
102  return DtVector2<T>(x*OneByfScalar, y*OneByfScalar);
103  }
104 
105  template <class T>
107  {
108  return DtVector2<T>(x/rhs.x, y/rhs.y);
109  }
110 
111  template <class T>
112  bool DtVector2<T>::isEqual(const DtVector2<T>& rhs, T tolerance) const
113  {
114  return DtMath::isEqual(this->x, rhs.x,tolerance)
115  && DtMath::isEqual(this->y, rhs.y,tolerance)
116  ;
117  }
118 
119 
120  template <class T>
122  {
123  return x*rhs.x + y*rhs.y;
124  }
125 
126  template <class T>
128  {
129  T vecLength = length();
130  if (vecLength<std::numeric_limits<T>::epsilon())
131  return DtVector2::ZERO_VECTOR;
132 
133  T one_by_length = T(1.0)/vecLength;
134  return (DtVector2<T>(x,y)*one_by_length);
135  }
136 
137  template <class T>
138  T DtVector2<T>::operator[](size_t index) const
139  {
141  const T* ptrT = static_cast<const T*>(ptr());
142  return ptrT[index];
143  }
144 
145  template <class T>
146  T DtVector2<T>::length(void) const
147  {
148  return DtMath::Sqrt(x*x+y*y);
149  }
150 
151  template <class T>
153  {
154  return 2*sizeof(T);
155  }
156 
157 } //namespace makVrv
158 

Document ID: Generated on Thu Apr 12 03:15:37 EDT 2018 from SVN revision 187986
Copyright © 2005-2018 VT MÄK. All Rights Reserved (www.mak.com)