VR-Forces 4.8 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) 2020 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 {
20 
23  template <class T>
24  class DtVector2
25  {
26  public:
28  DtVector2() : x(0), y(0) {}
30  DtVector2(T _x, T _y) : x(_x), y (_y) {}
31 
34  template <class T1>
35  DtVector2(const T1& v) : x(v.x), y(v.y) {}
36 
39 
40  const void* ptr(void) const {return &x;}
41 
42  T operator[](size_t index) const;
43 
44  T length(void) const;
45  T squaredLength(void) const;
46 
47  bool isEqual(const DtVector2& rhs, T tolerance) const;
48 
49  DtVector2 operator+(const DtVector2& rhs) const;
50  DtVector2 operator-(const DtVector2& rhs) const;
51 
52  DtVector2 operator+(T fScalar) const;
53  DtVector2 operator-(T fScalar) const;
54  DtVector2 operator*(T fScalar) const;
55  DtVector2 operator/(T fScalar) const;
56 
57  DtVector2 operator/(const DtVector2& rhs) const;
58 
59  DtVector2 getNormalizedCopy(void) const;
60 
61  T getDotProduct(const DtVector2& rhs) const;
62 
63  T x, y;
64 
67 
68  static size_t sizeInBytes(void);
69  };
70 
71  template <class T>
73  template <class T>
75 
76  template <class T>
78  {
79  return DtVector2<T>(x+rhs.x, y+rhs.y);
80  }
81 
82  template <class T>
83  DtVector2<T> DtVector2<T>::operator-(const DtVector2<T>& rhs) const
84  {
85  return DtVector2<T>(x-rhs.x, y-rhs.y);
86  }
87 
88  template <class T>
90  {
91  return DtVector2<T>(x+fScalar, y+fScalar);
92  }
93 
94  template <class T>
96  {
97  return DtVector2<T>(x-fScalar, y-fScalar);
98  }
99 
100  template <class T>
102  {
103  return DtVector2<T>(x*fScalar, y*fScalar);
104  }
105 
106  template <class T>
108  {
109  T OneByfScalar = T(1.0)/fScalar;
110  return DtVector2<T>(x*OneByfScalar, y*OneByfScalar);
111  }
112 
113  template <class T>
115  {
116  return DtVector2<T>(x/rhs.x, y/rhs.y);
117  }
118 
119  template <class T>
120  bool DtVector2<T>::isEqual(const DtVector2<T>& rhs, T tolerance) const
121  {
122  return DtMath::isEqual(this->x, rhs.x,tolerance)
123  && DtMath::isEqual(this->y, rhs.y,tolerance)
124  ;
125  }
126 
127 
128  template <class T>
130  {
131  return x*rhs.x + y*rhs.y;
132  }
133 
134  template <class T>
136  {
137  T vecLength = length();
138  if (vecLength<std::numeric_limits<T>::epsilon())
139  return DtVector2::ZERO_VECTOR;
140 
141  T one_by_length = T(1.0)/vecLength;
142  return (DtVector2<T>(x,y)*one_by_length);
143  }
144 
145  template <class T>
146  T DtVector2<T>::operator[](size_t index) const
147  {
149  const T* ptrT = static_cast<const T*>(ptr());
150  return ptrT[index];
151  }
152 
153  template <class T>
154  T DtVector2<T>::length(void) const
155  {
156  return DtMath::Sqrt(x*x+y*y);
157  }
158 
159  template <class T>
161  {
162  return x*x+y*y;
163  }
164 
165  template <class T>
167  {
168  return 2*sizeof(T);
169  }
170 
171 } //namespace makVrv
172 
bool isEqual(const DtVector2 &rhs, T tolerance) const
Definition: DtVector2.h:120
DtVector2(T _x, T _y)
CTOR.
Definition: DtVector2.h:30
DtVector2 operator*(T fScalar) const
Definition: DtVector2.h:101
static size_t sizeInBytes(void)
Definition: DtVector2.h:166
T squaredLength(void) const
Definition: DtVector2.h:160
DtVector2 operator+(const DtVector2 &rhs) const
T getDotProduct(const DtVector2 &rhs) const
Definition: DtVector2.h:129
DtVector2 getNormalizedCopy(void) const
Definition: DtVector2.h:135
DtVector2 operator-(const DtVector2 &rhs) const
static T Sqrt(T val)
Standard math routines.
Definition: DtMath.h:54
T y
Definition: DtVector2.h:63
T length(void) const
Definition: DtVector2.h:154
DtVector2(const T1 &v)
CTOR construct from type with constructable components.
Definition: DtVector2.h:35
DtVector2 operator/(T fScalar) const
Definition: DtVector2.h:107
static DtVector2 ZERO_VECTOR
Definition: DtVector2.h:65
~DtVector2()
DTOR.
Definition: DtVector2.h:38
Math utilities.
static DtVector2 UNIT_SCALE
Definition: DtVector2.h:66
static bool isEqual(int32 lhs, int32 rhs, int32 tolerance=std::numeric_limits< int32 >::epsilon())
Test equality with tolerance.
#define ASSERT_PREDICATE_RETURN_DEFAULT_CONSTRUCTOR(V, p)
Definition: DtAssert.h:45
DtVector2()
CTOR.
Definition: DtVector2.h:28
T x
Definition: DtVector2.h:63
T operator[](size_t index) const
Definition: DtVector2.h:146
assert macros
const void * ptr(void) const
Definition: DtVector2.h:40
2 dimensional vector
Definition: DtVector2.h:24

Document ID: Generated on Thu Aug 27 10:56:05 EDT 2020 from SVN revision 217100
Copyright © 2005-2020 MAK Technologies. All Rights Reserved (www.mak.com)