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

Document ID: Generated on Tue Mar 8 22:13:38 EST 2016 from SVN revision 162938
Copyright © 2005-2015 VT MÄK. All Rights Reserved (www.mak.com)