Itasca C++ Interface
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
vect.h
Go to the documentation of this file.
1 #pragma once
2 
7 #include "basedef.h"
8 #include "to.h"
9 #include <cmath>
10 #include <array>
11 
12 #ifdef _LINUX
13 namespace std {
14  template <class T> T abs(const T &t) {
15  if (t<0) return -t;
16  return t;
17  }
18  template <class T> T max0(const T &t1,const T &t2) {
19  if (t2>t1) return t2;
20  return t1;
21  }
22  template <class T> T min0(const T &t1,const T &t2) {
23  if (t2<t1) return t1;
24  return t1;
25  }
26 } // namespace std
27 #endif
28 
31 template <class T> class Vector2 {
32 public:
33  // Creators
35 #ifdef _DEBUG
36  Vector2() { fill(initVal<T>()); }
37 #else
38 #pragma warning(push)
39 #pragma warning(disable:26495) // Init warning- not initializing on purpose
40  Vector2() { }
41 #pragma warning(pop)
42 #endif
43  Vector2(const Vector2<T> &v) : a_(v.a_) { }
46  Vector2(const T &x,const T &y) : a_({x,y}) { }
48  explicit Vector2(const T &t) : a_({t,t}) { }
50  static Vector2<T> nothing() { Vector2<T> v(limits<T>::max(),-limits<T>::max()); return v; }
51 
52  // Accessors
54  const T &x() const { return c_.x_; }
56  const T &y() const { return c_.y_; }
58  const T &dof(unsigned u) const { return a_[u]; }
60  T &rx() { return c_.x_; }
62  T &ry() { return c_.y_; }
64  T &rdof(unsigned u) { return a_[u]; }
66  const T &operator[](unsigned u) const { return dof(u); }
67  T & operator[](unsigned u) { return rdof(u); }
68  template <std::size_t N> decltype(auto) get() const {
69  static_assert(N<2,"Index out of range");
70  return a_[N];
71  }
72 
73  // Various norms
75  T fsum() const { return (std::abs(x())+std::abs(y())); }
77  T sum() const { return x() + y(); }
79  T mag2() const { return (x()*x()+y()*y()); }
81  T mag() const { return to<T>(std::sqrt(to<Double>(mag2()))); }
83  T area() const { return (x()*y()); }
85  T volume() const { return area(); }
87  T spread() const { return (y() -x()); }
89  Vector2<T> unit() const { Vector2<T> v(*this); T m(v.mag()); if (m) v/=m; return v; }
91  Vector2<T> abs() const { Vector2<T> v(std::abs(x()),std::abs(y())); return v; }
93  void fill(const T &d) { rx()=d; ry()=d; }
95  T maxComp() const { return std::max(x(),y()); }
97  T minComp() const { return std::min(x(),y()); }
99  unsigned maxCompIndex() const { return x() > y() ? 0 : 1; }
101  unsigned minCompIndex() const { return x() < y() ? 0 : 1; }
103  const Vector2<T> &safeDivE(const Vector2<T> &v) { rx()=::safeDiv(x(),v.x()); ry() = ::safeDiv(y(),v.y()); return *this; }
105  const Vector2<T> safeDiv(const Vector2<T> &v) { Vector2<T> ret(::safeDiv(x(),v.x()),::safeDiv(y(),v.y())); return ret; }
106 
108  bool operator==(const Vector2<T> &v) const { return ((x()==v.x())&&(y()==v.y())); }
110  bool operator!=(const Vector2<T> &v) const { return ((x()!=v.x())||(y()!=v.y())); }
112  bool operator<(const Vector2<T> &v) const { if (x()!=v.x()) return x()<v.x(); return y()<v.y(); }
114  bool operator>(const Vector2<T> &v) const { if (x()!=v.x()) return x()>v.x(); return y()>v.y(); }
115 
116  // In-place operators
118  const Vector2<T> &operator+=(const Vector2<T> &v) { rx()+=v.x(); ry()+=v.y(); return *this; }
119  const Vector2<T> &operator-=(const Vector2<T> &v) { rx()-=v.x(); ry()-=v.y(); return *this; }
120  const Vector2<T> &operator*=(const Vector2<T> &v) { rx()*=v.x(); ry()*=v.y(); return *this; }
121  const Vector2<T> &operator*=(const T &t) { rx()*=t; ry()*=t; return *this; }
122  const Vector2<T> &operator/=(const Vector2<T> &v) { rx()/=v.x(); ry()/=v.y(); return *this; }
123  const Vector2<T> &operator/=(const T &t) { rx()/=t; ry()/=t; return *this; }
124 
125  // Binary operators - require temp (ugh)
127  Vector2<T> operator+(const Vector2<T> &v) const { Vector2<T> out(x()+v.x(),y()+v.y()); return out; }
128  Vector2<T> operator-(const Vector2<T> &v) const { Vector2<T> out(x()-v.x(),y()-v.y()); return out; }
129  Vector2<T> operator*(const Vector2<T> &v) const { Vector2<T> out(x()*v.x(),y()*v.y()); return out; }
130  Vector2<T> operator*(const T &t) const { Vector2<T> out(x()*t,y()*t); return out; }
131  Vector2<T> operator/(const Vector2<T> &v) const { Vector2<T> out(x()/v.x(),y()/v.y()); return out; }
132  Vector2<T> operator/(const T &t) const { Vector2<T> out(x()/t,y()/t); return out; }
133  // Cross Product (see DAVect)
135  T operator|(const Vector2<T> &v) const { return (x()*v.x()+y()*v.y()); }
136 
137  // Support for use of a Vect2 as a range (min,max)
139  const Vector2<T> &expandToInclude(const T &t) { rx() = std::min(x(),t); ry() = std::max(y(),t); return *this; }
141  const Vector2<T> &expandToInclude(const Vector2<T> &v) { rx() = std::min(x(),v.minComp()); ry() = std::max(y(),v.maxComp()); return *this; }
143  Vector2<T> expandedToInclude(const T &t) const { Vector2<T> ret(*this); ret.expandToInclude(t); return ret; }
145  Vector2<T> expandedToInclude(const Vector2<T> &v) const { Vector2<T> ret(*this); ret.expandToInclude(v); return ret; }
147  bool contains(const T &t) const { if (t<x()) return false; if (t>y()) return false; return true; }
148 
149 private:
150  union {
151  struct {
152  T x_;
153  T y_;
154  } c_;
155  std::array<T,2> a_;
156  };
157 };
158 
161 template <class T> class Vector3 {
162 public:
163  // Creators
165 #ifdef _DEBUG
166  Vector3() { fill(initVal<T>()); }
167 #else
168 #pragma warning(push)
169 #pragma warning(disable:26495) // Init warning- not initializing on purpose
170  Vector3() { }
171 #pragma warning(pop)
172 #endif
173  Vector3(const Vector3<T> &v) : a_(v.a_) { }
176  Vector3(const T &x,const T &y,const T &z=0) : a_({x,y,z}) { }
178  explicit Vector3(const T &t) : a_({t,t,t}) { }
179 
180  // Accessors
182  const T &x() const { return c_.x_; }
184  const T &y() const { return c_.y_; }
186  const T &z() const { return c_.z_; }
188  const T &dof(unsigned u) const { return a_[u]; }
190  T &rx() { return c_.x_; }
192  T &ry() { return c_.y_; }
194  T &rz() { return c_.z_; }
196  T &rdof(unsigned u) { return a_[u]; }
198  const T &operator[](unsigned u) const { return dof(u); }
200  T &operator[](unsigned u) { return rdof(u); }
201  template <std::size_t N> T get() const {
202  static_assert(N<3,"Index out of range");
203  return a_[N];
204  }
205 
206  // Various norms
208  T fsum() const { return (std::abs(x())+std::abs(y())+std::abs(z())); }
210  T sum() const { return x()+y()+z(); }
212  T mag2() const { return (x()*x()+y()*y()+z()*z()); }
214  T mag() const { return to<T>(std::sqrt(to<Double>(mag2()))); }
216  T volume() const { return (x()*y()*z()); }
218  Vector3<T> unit() const { Vector3<T> v(*this); T m(v.mag()); if (m) v/=m; return v; }
220  Vector3<T> abs() const { Vector3<T> v(std::abs(x()),std::abs(y()),std::abs(z())); return v; }
222  void fill(const T &d) { rx()=d; ry()=d; rz()=d; }
224  T maxComp() const { return std::max(x(),std::max(y(),z())); }
226  T minComp() const { return std::min(x(),std::min(y(),z())); }
228  unsigned maxCompIndex() const { return x() > y() ? (x() > z() ? 0 : 2) : (y() > z() ? 1 : 2); }
230  unsigned minCompIndex() const { return x() < y() ? (x() < z() ? 0 : 2) : (y() < z() ? 1 : 2); }
232  const Vector3<T> &safeDivE(const Vector3<T> &v) { rx()=::safeDiv(x(),v.x()); ry() = ::safeDiv(y(),v.y()); rz() = ::safeDiv(z(),v.z()); return *this; }
234  const Vector3<T> safeDiv(const Vector3<T> &v) { Vector3<T> ret(::safeDiv(x(),v.x()),::safeDiv(y(),v.y()),::safeDiv(z(),v.z())); return ret; }
235 
237  bool operator==(const Vector3<T> &v) const { return ((x()==v.x())&&(y()==v.y())&&(z()==v.z())); }
239  bool operator!=(const Vector3<T> &v) const { return ((x()!=v.x())||(y()!=v.y())||(z()!=v.z())); }
241  bool operator<(const Vector3<T> &v) const { if (x()!=v.x()) return x()<v.x(); if (y()!=v.y()) return y()<v.y(); return z()<v.z(); }
243  bool operator>(const Vector3<T> &v) const { if (x()!=v.x()) return x()>v.x(); if (y()!=v.y()) return y()>v.y(); return z()>v.z(); }
244 
245  // In-place operators
247  const Vector3<T> &operator+=(const Vector3<T> &v) { rx()+=v.x(); ry()+=v.y(); rz()+=v.z(); return *this; }
248  const Vector3<T> &operator-=(const Vector3<T> &v) { rx()-=v.x(); ry()-=v.y(); rz()-=v.z(); return *this; }
249  const Vector3<T> &operator*=(const Vector3<T> &v) { rx()*=v.x(); ry()*=v.y(); rz()*=v.z(); return *this; }
250  const Vector3<T> &operator*=(const T &t) { rx()*=t; ry()*=t; rz()*=t; return *this; }
251  const Vector3<T> &operator/=(const Vector3<T> &v) { rx()/=v.x(); ry()/=v.y(); rz()/=v.z(); return *this; }
252  const Vector3<T> &operator/=(const T &t) { rx()/=t; ry()/=t; rz()/=t; return *this; }
253 
254  // Binary operators - require temp (ugh)
256  Vector3<T> operator+(const Vector3<T> &v) const { Vector3<T> out(x()+v.x(),y()+v.y(),z()+v.z()); return out; }
257  Vector3<T> operator-(const Vector3<T> &v) const { Vector3<T> out(x()-v.x(),y()-v.y(),z()-v.z()); return out; }
258  Vector3<T> operator*(const Vector3<T> &v) const { Vector3<T> out(x()*v.x(),y()*v.y(),z()*v.z()); return out; }
259  Vector3<T> operator*(const T &t) const { Vector3<T> out(x()*t,y()*t,z()*t); return out; }
260  Vector3<T> operator/(const Vector3<T> &v) const { Vector3<T> out(x()/v.x(),y()/v.y(),z()/v.z()); return out; }
261  Vector3<T> operator/(const T &t) const { Vector3<T> out(x()/t,y()/t,z()/t); return out; }
262  Vector3<T> operator&(const Vector3<T> &v) const {
264  Vector3<T> out((y()*v.z())-(z()*v.y()),(z()*v.x())-(x()*v.z()),(x()*v.y())-(y()*v.x()));
265  return out;
266  }
268  T operator|(const Vector3<T> &v) const { return (x()*v.x()+y()*v.y()+z()*v.z()); }
269 
270 private:
271  union {
272  struct {
273  T x_;
274  T y_;
275  T z_;
276  } c_;
277  std::array<T,3> a_;
278  };
279 };
280 
281 // Naming convention for most commonly used types.
288 
295 
296 // Conversion routines.
299 template <class T> inline DVect2 toDVect2(const Vector2<T> &v) { DVect2 dv2(to<Double>(v.x()),to<Double>(v.y())); return dv2; }
302 template <class T> inline FVect2 toFVect2(const Vector2<T> &v) { FVect2 fv2(to<Float>(v.x()),to<Float>(v.y())); return fv2; }
305 template <class T> inline IVect2 toIVect2(const Vector2<T> &v) { IVect2 iv2(to<Int>(v.x()),to<Int>(v.y())); return iv2; }
308 template <class T> inline UVect2 toUVect2(const Vector2<T> &v) { UVect2 uv2(to<UInt>(v.x()),to<UInt>(v.y())); return uv2; }
309 
312 template <class T> inline DVect3 toDVect3(const Vector3<T> &v) {
313  DVect3 dv3(to<Double>(v.x()),to<Double>(v.y()),to<Double>(v.z()));
314  return dv3;
315 }
318 template <class T> inline FVect3 toFVect3(const Vector3<T> &v) {
319  FVect3 fv3(to<Float>(v.x()),to<Float>(v.y()),to<Float>(v.z()));
320  return fv3;
321 }
324 template <class T> inline IVect3 toIVect3(const Vector3<T> &v) {
325  IVect3 iv3(to<Int>(v.x()),to<Int>(v.y()),to<Int>(v.z()));
326  return iv3;
327 }
330 template <class T> inline UVect3 toUVect3(const Vector3<T> &v) {
331  UVect3 uv3(to<UInt>(v.x()),to<UInt>(v.y()),to<UInt>(v.z()));
332  return uv3;
333 }
334 
335 
337 template <class T> inline const Vector2<T> &toVect2(const Vector2<T> &v) { return v; }
338 template <class T> inline Vector2<T> toVect2(const Vector3<T> &v) { return Vector2<T>(v.x(),v.y()); }
339 template <class T> inline Vector3<T> toVect3(const Vector2<T> &v,const T &t=0) { return Vector3<T>(v.x(),v.y(),t); }
340 template <class T> inline const Vector3<T> &toVect3(const Vector3<T> &v) { return v; }
341 
342 
345 template <class T> inline Vector2<T> vmax(const Vector2<T> &v1,const Vector2<T> &v2) {
346  Vector2<T> out(std::max<T>(v1.x(),v2.x()),std::max<T>(v1.y(),v2.y()));
347  return out;
348 }
351 template <class T> inline Vector2<T> vmin(const Vector2<T> &v1,const Vector2<T> &v2) {
352  Vector2<T> out(std::min<T>(v1.x(),v2.x()),std::min<T>(v1.y(),v2.y()));
353  return out;
354 }
355 
358 template <class T> inline Vector2<T> vsign(const Vector2<T> &v1,const Vector2<T> &v2) {
359  Vector2<T> out(v2.x() < 0 ? -qAbs(v1.x()) : qAbs(v1.x()) ,v2.y() < 0 ? -qAbs(v1.y()) : qAbs(v1.y()));
360  return out;
361 }
362 
365 template <class T> inline Vector3<T> vmax(const Vector3<T> &v1,const Vector3<T> &v2) {
366  Vector3<T> out(std::max<T>(v1.x(),v2.x()),std::max<T>(v1.y(),v2.y()),std::max<T>(v1.z(),v2.z()));
367  return out;
368 }
371 template <class T> inline Vector3<T> vmin(const Vector3<T> &v1,const Vector3<T> &v2) {
372  Vector3<T> out(std::min<T>(v1.x(),v2.x()),std::min<T>(v1.y(),v2.y()),std::min<T>(v1.z(),v2.z()));
373  return out;
374 }
375 
378 template <class T> inline Vector3<T> vsign(const Vector3<T> &v1,const Vector3<T> &v2) {
379  Vector3<T> out(v2.x() < 0 ? -qAbs(v1.x()) : qAbs(v1.x()), v2.y() < 0 ? -qAbs(v1.y()) : qAbs(v1.y()), v2.z() < 0 ? -qAbs(v1.z()) : qAbs(v1.z()));
380  return out;
381 }
382 
385 template <class T> inline Vector2<T> vceil(const Vector2<T> &v) {
386  Vector2<T> out(ceil(v.x()),ceil(v.y()));
387  return out;
388 }
389 
392 template <class T> inline Vector3<T> vceil(const Vector3<T> &v) {
393  Vector3<T> out(ceil(v.x()),ceil(v.y()),ceil(v.z()));
394  return out;
395 }
396 
399 template <class T> inline Vector2<T> vfloor(const Vector2<T> &v) {
400  Vector2<T> out(floor(v.x()),floor(v.y()));
401  return out;
402 }
403 
406 template <class T> inline Vector3<T> vfloor(const Vector3<T> &v) {
407  Vector3<T> out(floor(v.x()),floor(v.y()),floor(v.z()));
408  return out;
409 }
410 
413 template <class T> IVect2 vround(const Vector2<T> &v) {
414  IVect2 out(qRound(v.x()),qRound(v.y()));
415  return out;
416 }
417 
420 template <class T> IVect3 vround(const Vector3<T> &v) {
421  IVect3 out(qRound(v.x()),qRound(v.y()),qRound(v.z()));
422  return out;
423 }
424 
425 namespace std {
427  template <class T> Vector2<T> max(const Vector2<T> &v1,const Vector2<T> &v2) { return vmax(v1,v2); }
429  template <class T> Vector2<T> min(const Vector2<T> &v1,const Vector2<T> &v2) { return vmin(v1,v2); }
431  template <class T> Vector3<T> max(const Vector3<T> &v1,const Vector3<T> &v2) { return vmax(v1,v2); }
433  template <class T> Vector3<T> min(const Vector3<T> &v1,const Vector3<T> &v2) { return vmin(v1,v2); }
434 
436  template <class T> struct tuple_size<Vector2<T>> : std::integral_constant<std::size_t, 2> {};
437  template <class T> struct tuple_size<Vector3<T>> : std::integral_constant<std::size_t, 3> {};
438  template <std::size_t N,class T> struct tuple_element<N, Vector2<T>> { using type = T; };
439  template <std::size_t N,class T> struct tuple_element<N, Vector3<T>> { using type = T; };
440 }
441 
443 // EoF
444 
Vector2< T > operator-(const Vector2< T > &v) const
Binary mathematical operators using vectors and scalars – Note that * and / of Vector2 types are done...
Definition: vect.h:128
Vector2< Int > IVect2
Definition: vect.h:284
const Vector2< T > & operator-=(const Vector2< T > &v)
In place mathematical operators using vectors and scalars – Note that * and / of Vector2 types are do...
Definition: vect.h:119
Vector3< T > operator/(const T &t) const
Binary mathematical operators – * and / are done on a component basis.
Definition: vect.h:261
DVect3 toDVect3(const Vector3< T > &v)
Definition: vect.h:312
Vector3< T > operator+(const Vector3< T > &v) const
Binary mathematical operators – * and / are done on a component basis.
Definition: vect.h:256
DVect2 toDVect2(const Vector2< T > &v)
Definition: vect.h:299
T & operator[](unsigned u)
Definition: vect.h:67
bool contains(const T &t) const
True if value t falls inside this 1D range (inclusive).
Definition: vect.h:147
Vector3< Long > LVect3
Definition: vect.h:293
bool operator<(const Vector3< T > &v) const
Comparison operator, compare each DOF in order.
Definition: vect.h:241
unsigned minCompIndex() const
Returns the min component index.
Definition: vect.h:230
const T & operator[](unsigned u) const
Allow array like access by degree of freedom (0-1)
Definition: vect.h:66
Vector2(const T &x, const T &y)
Explicit constructor, from two components.
Definition: vect.h:46
const Vector3< T > & safeDivE(const Vector3< T > &v)
"Safe" division operation - checks for zero and overflow.
Definition: vect.h:232
const Vector2< T > & expandToInclude(const Vector2< T > &v)
Expands 1D range to include 1D range v.
Definition: vect.h:141
T volume() const
Volume of region represented by x*y*z - can be negative.
Definition: vect.h:216
Vector3< T > operator *(const Vector3< T > &v) const
Binary mathematical operators – * and / are done on a component basis.
Definition: vect.h:258
UVect2 toUVect2(const Vector2< T > &v)
Definition: vect.h:308
FVect2 toFVect2(const Vector2< T > &v)
Definition: vect.h:302
bool operator!=(const Vector2< T > &v) const
Comparison operator - no tolerance is used.
Definition: vect.h:110
Vector3< T > operator-(const Vector3< T > &v) const
Binary mathematical operators – * and / are done on a component basis.
Definition: vect.h:257
Vector2< T > vsign(const Vector2< T > &v1, const Vector2< T > &v2)
Definition: vect.h:358
Vector2< T > min(const Vector2< T > &v1, const Vector2< T > &v2)
Template specialization for max, min.
Definition: vect.h:429
IVect3 vround(const Vector3< T > &v)
Definition: vect.h:420
const Vector3< T > & operator/=(const T &t)
In-place mathematical operators – * and / are done on a component basis.
Definition: vect.h:252
T mag() const
The magnitude.
Definition: vect.h:81
Vector3< T > vceil(const Vector3< T > &v)
Definition: vect.h:392
Vector2< T > vceil(const Vector2< T > &v)
Definition: vect.h:385
IVect2 vround(const Vector2< T > &v)
Definition: vect.h:413
Vector2()
Default constructor, no data initialization.
Definition: vect.h:40
T maxComp() const
Returns the maximum component.
Definition: vect.h:224
Vector2< Long > LVect2
Definition: vect.h:286
T & rdof(unsigned u)
Reference accesss to degree-of-freedom u (0-1).
Definition: vect.h:64
Vector2< T > abs() const
Returns vector of absolute values of components.
Definition: vect.h:91
Vector3()
Default constructor - no data initialization.
Definition: vect.h:170
T fsum() const
Manhattan norm.
Definition: vect.h:75
Vector2< T > unit() const
Unit vector - be sure vector is nonzero.
Definition: vect.h:89
unsigned maxCompIndex() const
Returns the max component index.
Definition: vect.h:228
bool operator<(const Vector2< T > &v) const
Comparison operator, based on magnitude.
Definition: vect.h:112
Vector2< T > vmin(const Vector2< T > &v1, const Vector2< T > &v2)
Definition: vect.h:351
const Vector3< T > & operator/=(const Vector3< T > &v)
In-place mathematical operators – * and / are done on a component basis.
Definition: vect.h:251
debug checked shorthand for std::numeric_limits<T>::
Definition: limit.h:25
Vector3< Float > FVect3
Definition: vect.h:290
T & rx()
Reference access to the x-component of the vector.
Definition: vect.h:190
UVect3 toUVect3(const Vector3< T > &v)
Definition: vect.h:330
Vector2< T > operator *(const Vector2< T > &v) const
Binary mathematical operators using vectors and scalars – Note that * and / of Vector2 types are done...
Definition: vect.h:129
T mag2() const
Square of the magnitude, or the dot product with itself.
Definition: vect.h:79
Vector2< UInt > UVect2
Definition: vect.h:285
const Vector3< T > & operator-=(const Vector3< T > &v)
In-place mathematical operators – * and / are done on a component basis.
Definition: vect.h:248
bool operator==(const Vector2< T > &v) const
Comparison operator - no tolerance is used.
Definition: vect.h:108
Vector2< T > operator+(const Vector2< T > &v) const
Binary mathematical operators using vectors and scalars – Note that * and / of Vector2 types are done...
Definition: vect.h:127
T mag2() const
Square of the magnitude, or the vector dotted with itself.
Definition: vect.h:212
Vector2< ULong > ULVect2
Definition: vect.h:287
const T & operator[](unsigned u) const
Allows array like access to degrees-of-freedom.
Definition: vect.h:198
T & operator[](unsigned u)
Allows array like access to degrees-of-freedom.
Definition: vect.h:200
T minComp() const
Returns the minimum component.
Definition: vect.h:97
T area() const
Size of rectangle represented by x*y - can be negative.
Definition: vect.h:83
const T & y() const
Y component access.
Definition: vect.h:56
T mag() const
The vector magnitude.
Definition: vect.h:214
const Vector2< T > safeDiv(const Vector2< T > &v)
"Safe" division operation - checks for zero and overflow.
Definition: vect.h:105
T minComp() const
Returns the minimum component.
Definition: vect.h:226
Vector2< T > vmax(const Vector2< T > &v1, const Vector2< T > &v2)
Definition: vect.h:345
2D vector utility class.
Definition: vect.h:31
T sum() const
Sum of components.
Definition: vect.h:210
Vector2(const T &t)
Explicit contructor, each component is given value t.
Definition: vect.h:48
const T & z() const
The z-component of the vector.
Definition: vect.h:186
Vector3< T > vmin(const Vector3< T > &v1, const Vector3< T > &v2)
Definition: vect.h:371
Vector2< T > max(const Vector2< T > &v1, const Vector2< T > &v2)
Template specialization for max, min.
Definition: vect.h:427
unsigned minCompIndex() const
Returns the min component index.
Definition: vect.h:101
unsigned maxCompIndex() const
Returns the max component index.
Definition: vect.h:99
const Vector2< T > & operator/=(const T &t)
In place mathematical operators using vectors and scalars – Note that * and / of Vector2 types are do...
Definition: vect.h:123
const Vector3< T > safeDiv(const Vector3< T > &v)
"Safe" division operation - checks for zero and overflow.
Definition: vect.h:234
Vector3< T > vfloor(const Vector3< T > &v)
Definition: vect.h:406
Vector3< T > toVect3(const AVector2< T > &v)
Definition: avect.h:248
Vector3< T > abs() const
Returns vector of absolute values of components.
Definition: vect.h:220
Vector3< UInt > UVect3
Definition: vect.h:292
const Vector2< T > & safeDivE(const Vector2< T > &v)
"Safe" division operation - checks for zero and overflow.
Definition: vect.h:103
const Vector2< T > & operator/=(const Vector2< T > &v)
In place mathematical operators using vectors and scalars – Note that * and / of Vector2 types are do...
Definition: vect.h:122
void fill(const T &d)
Fills all three components with value d.
Definition: vect.h:222
T & ry()
Reference access to y-component.
Definition: vect.h:62
const Vector2< T > & operator+=(const Vector2< T > &v)
In place mathematical operators using vectors and scalars – Note that * and / of Vector2 types are do...
Definition: vect.h:118
const T & dof(unsigned u) const
Access to degree of freedom u (0-1).
Definition: vect.h:58
FVect3 toFVect3(const Vector3< T > &v)
Definition: vect.h:318
Vector2< T > toVect2(const AVector2< T > &)
Definition: avect.h:245
Vector2< T > expandedToInclude(const Vector2< T > &v) const
Returns 1D range expanded to include 1D range v.
Definition: vect.h:145
Vector3(const T &t)
Explicit constructor, all three components are inintialized to t.
Definition: vect.h:178
Vector3< ULong > ULVect3
Definition: vect.h:294
T spread() const
Assumes vector is being used to store a 1D extent– Returns max-min. (y-x).
Definition: vect.h:87
Vector3(const T &x, const T &y, const T &z=0)
Explicit constructor, by the three components of the vector.
Definition: vect.h:176
3D vector utility class.
Definition: vect.h:161
T & rdof(unsigned u)
Reference access to degree-of-freedom u (0-2) of the vector.
Definition: vect.h:196
Vector2< T > operator/(const Vector2< T > &v) const
Binary mathematical operators using vectors and scalars – Note that * and / of Vector2 types are done...
Definition: vect.h:131
IVect2 toIVect2(const Vector2< T > &v)
Definition: vect.h:305
Vector3< T > operator/(const Vector3< T > &v) const
Binary mathematical operators – * and / are done on a component basis.
Definition: vect.h:260
T sum() const
Sum of components.
Definition: vect.h:77
const Vector2< T > & operator *=(const Vector2< T > &v)
In place mathematical operators using vectors and scalars – Note that * and / of Vector2 types are do...
Definition: vect.h:120
T volume() const
Volume of the rectangle assuming unit depth – same as area(), provided for 2D/3D compile compatibilit...
Definition: vect.h:85
Vector2< T > vfloor(const Vector2< T > &v)
Definition: vect.h:399
Vector3< Double > DVect3
Definition: vect.h:289
Base type definitions - if QT is not in use.
const Vector2< T > & expandToInclude(const T &t)
Expands 1D range to include value t.
Definition: vect.h:139
Vector3< Int > IVect3
Definition: vect.h:291
bool operator>(const Vector2< T > &v) const
Comparison operator, based on magnitude.
Definition: vect.h:114
const T & x() const
X component access.
Definition: vect.h:54
A overflow checked shorthand for static_cast<T>().
bool operator==(const Vector3< T > &v) const
Comparison operator - no tolerance is used.
Definition: vect.h:237
IVect3 toIVect3(const Vector3< T > &v)
Definition: vect.h:324
Vector3< T > vmax(const Vector3< T > &v1, const Vector3< T > &v2)
Definition: vect.h:365
T & rz()
Reference access to the z-component of the vector.
Definition: vect.h:194
T operator|(const Vector3< T > &v) const
Dot Product.
Definition: vect.h:268
Vector2< Double > DVect2
Definition: vect.h:282
Vector3< T > operator &(const Vector3< T > &v) const
Cross Product.
Definition: vect.h:263
const T & dof(unsigned u) const
The degree-of-freedom u (0-2) component.
Definition: vect.h:188
Vector2< Float > FVect2
Definition: vect.h:283
bool operator!=(const Vector3< T > &v) const
Comparison operator - no tolerance is used.
Definition: vect.h:239
Vector2< T > operator/(const T &t) const
Binary mathematical operators using vectors and scalars – Note that * and / of Vector2 types are done...
Definition: vect.h:132
const Vector3< T > & operator+=(const Vector3< T > &v)
In-place mathematical operators – * and / are done on a component basis.
Definition: vect.h:247
T operator|(const Vector2< T > &v) const
Dot Product.
Definition: vect.h:135
static Vector2< T > nothing()
Creates an "empty" vector, useful when Vector2 is used as a 1D extent.
Definition: vect.h:50
Vector2< T > expandedToInclude(const T &t) const
Returns 1D range expanded to include value t;.
Definition: vect.h:143
bool operator>(const Vector3< T > &v) const
Comparison operator, compare each DOF in order.
Definition: vect.h:243
T fsum() const
Manhattan norm.
Definition: vect.h:208
const Vector3< T > & operator *=(const Vector3< T > &v)
In-place mathematical operators – * and / are done on a component basis.
Definition: vect.h:249
T & rx()
Reference access to x-component.
Definition: vect.h:60
Vector3< T > unit() const
Unit vector - be sure vector is nonzero.
Definition: vect.h:218
const T & y() const
The y-component of the vector.
Definition: vect.h:184
Vector3< T > vsign(const Vector3< T > &v1, const Vector3< T > &v2)
Definition: vect.h:378
T & ry()
Reference access to the y-component of the vector.
Definition: vect.h:192
const T & x() const
The x-component of the vector.
Definition: vect.h:182
void fill(const T &d)
Fills all three components with value d.
Definition: vect.h:93
T maxComp() const
Returns the maximum component.
Definition: vect.h:95