14 template <
class T> T abs(
const T &t) {
18 template <
class T> T max0(
const T &t1,
const T &t2) {
22 template <
class T> T min0(
const T &t1,
const T &t2) {
39 #pragma warning(disable:26495) // Init warning- not initializing on purpose 48 explicit Vector2(
const T &t) : a_({t,t}) { }
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]; }
68 template <std::
size_t N> decltype(
auto) get()
const {
69 static_assert(N<2,
"Index out of range");
75 T
fsum()
const {
return (std::abs(
x())+std::abs(
y())); }
77 T
sum()
const {
return x() +
y(); }
81 T
mag()
const {
return to<T>(std::sqrt(to<Double>(
mag2()))); }
147 bool contains(
const T &t)
const {
if (t<
x())
return false;
if (t>
y())
return false;
return true; }
168 #pragma warning(push) 169 #pragma warning(disable:26495) // Init warning- not initializing on purpose 178 explicit Vector3(
const T &t) : a_({t,t,t}) { }
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]; }
201 template <std::
size_t N> T get()
const {
202 static_assert(N<3,
"Index out of range");
208 T
fsum()
const {
return (std::abs(
x())+std::abs(
y())+std::abs(
z())); }
214 T
mag()
const {
return to<T>(std::sqrt(to<Double>(
mag2()))); }
224 T
maxComp()
const {
return std::max(
x(),std::max(
y(),
z())); }
226 T
minComp()
const {
return std::min(
x(),std::min(
y(),
z())); }
313 DVect3 dv3(to<Double>(v.
x()),to<Double>(v.
y()),to<Double>(v.
z()));
319 FVect3 fv3(to<Float>(v.
x()),to<Float>(v.
y()),to<Float>(v.
z()));
325 IVect3 iv3(to<Int>(v.
x()),to<Int>(v.
y()),to<Int>(v.
z()));
331 UVect3 uv3(to<UInt>(v.
x()),to<UInt>(v.
y()),to<UInt>(v.
z()));
346 Vector2<T> out(std::max<T>(v1.
x(),v2.
x()),std::max<T>(v1.
y(),v2.
y()));
352 Vector2<T> out(std::min<T>(v1.
x(),v2.
x()),std::min<T>(v1.
y(),v2.
y()));
359 Vector2<T> out(v2.
x() < 0 ? -qAbs(v1.
x()) : qAbs(v1.
x()) ,v2.
y() < 0 ? -qAbs(v1.
y()) : qAbs(v1.
y()));
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()));
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()));
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()));
414 IVect2 out(qRound(v.
x()),qRound(v.
y()));
421 IVect3 out(qRound(v.
x()),qRound(v.
y()),qRound(v.
z()));
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; };
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