Scanframe Modular Application 0.1.0
Loading...
Searching...
No Matches
TVector3D.h
Go to the documentation of this file.
1#pragma once
2#include <limits>
3#include <string>
4
5namespace sf
6{
7
8// Forward declaration.
9template<typename T>
10class TMatrix44;
11
15template<typename T>
17{
18 public:
22 typedef T value_type;
23
27 TVector3D() = default;
28
33
37 TVector3D(TVector3D&&) noexcept;
38
45 TVector3D(T xp, T yp, T zp);
46
54 TVector3D& assign(T xp, T yp, T zp);
55
62
66 TVector3D& operator=(const TVector3D& v) noexcept;
67
71 TVector3D& operator=(TVector3D&& v) noexcept;
72
77 TVector3D& operator^=(const TMatrix44<T>& mtx);
78
83 TVector3D& operator*=(const TMatrix44<T>& mtx);
84
88 TVector3D operator^(const TMatrix44<T>& mtx);
89
93 TVector3D operator*(const TMatrix44<T>& mtx);
94
98 TVector3D operator-() const;
99
103 TVector3D& operator+=(const TVector3D&);
104
108 TVector3D& operator-=(const TVector3D&);
109
113 TVector3D& operator*=(T c);
114
118 TVector3D& operator/=(T);
119
123 TVector3D operator+(const TVector3D&) const;
124
128 TVector3D operator-(const TVector3D&) const;
129
133 TVector3D operator/(T c) const;
134
141 bool isEqual(const TVector3D& v, T tol = tolerance) const;
142
149 bool isEqual(const TVector3D& v, const TVector3D& tol) const;
150
154 bool operator==(const TVector3D&) const;
155
159 bool operator!=(const TVector3D&) const;
160
165 T& operator[](size_t);
166
171 const T& operator[](size_t) const;
172
176 constexpr T* data();
177
181 constexpr const T* data() const;
182
186 // ReSharper disable once CppNonExplicitConversionOperator
187 constexpr operator T*();
188
192 // ReSharper disable once CppNonExplicitConversionOperator
193 constexpr operator const T*() const;
194
198 constexpr T x() const;
199
203 constexpr T& x();
204
208 constexpr T y() const;
209
213 constexpr T& y();
214
218 constexpr T z() const;
219
223 constexpr T& z();
224
231 T length() const;
232
239 T length2D() const;
240
245 T lengthSqr() const;
246
251 T lengthSqr2D() const;
252
258
264
269 TVector3D& scale(T factor);
270
275 TVector3D scaled(T factor) const;
276
282
287 T dotProduct(const TVector3D&) const;
288
293 T dotProduct2D(const TVector3D&) const;
294
299 TVector3D operator*(const TVector3D& v) const;
300
305 T angle(const TVector3D&) const;
306
312
318 T distance(const TVector3D&) const;
319
325 T distance2D(const TVector3D&) const;
326
333 T distanceSqr(const TVector3D&) const;
334
341 T distanceSqr2D(const TVector3D&) const;
342
347 void updateMin(const TVector3D& vertex);
348
353 void updateMax(const TVector3D& vertex);
354
358 std::string toString(int digits = 0) const;
359
368 TVector3D& fromString(const std::string& s, bool ignore_err = false) noexcept(false);
369
375
381 static constexpr auto tolerance = std::numeric_limits<T>::epsilon() * T(15.0);
382
386 void copyTo(T fa[3]) const;
387
396 template<typename F = T, size_t N = 3>
397 std::array<F, N> array(F value = 1) const;
398
408 template<typename F = float, size_t N = 4>
409 const F* floatPtr(F value = 1) const;
410
411 protected:
426};
427
431template<typename T>
433
437template<typename T>
439
443template<typename T>
445
449template<typename T>
451
455template<typename T>
457
461template<typename T>
462std::istream& operator>>(std::istream& is, TVector3D<T>& v) noexcept(false);
463
467template<typename T>
468std::ostream& operator<<(std::ostream& os, const TVector3D<T>& v)
469{
470 return os << v.toString();
471}
472
473}// namespace sf
474
475#ifndef __JETBRAINS_IDE__
476 // Include all inlined functions and template implementations.
477 #include <math/TVector3D.hpp>
478#endif
Generic 4 x 4 matrix template.
Definition TMatrix44.h:37
3-dimensional vector for math operations.
Definition TVector3D.h:17
T distance(const TVector3D &) const
Gets the distance between this and the passed vector. Note that this has to return a double because i...
constexpr T * data()
Gets a const pointer to the data.
std::array< F, N > array(F value=1) const
Gets a std::array of type F of the X, Y and Z axis. Allows the size of the array to be specified so i...
TVector3D & assign(T xp, T yp, T zp)
Assignment of new coordinate values.
T distanceSqr2D(const TVector3D &) const
Gets the squared distance between 2 given points in 2D only (z is ignored). Avoids taking an expensiv...
constexpr T x() const
Gets the x-coordinate value.
TVector3D & fromString(const std::string &s, bool ignore_err=false) noexcept(false)
Gets the vector value from the string representation formed like '(1.23,4.56,7.89)'....
void copyTo(T fa[3]) const
Copies the X, Y and Z values to an array of type 'T' or type 'TVector3D<T>::value_type'.
int dominantAxis()
Gets the dominant axis where x=0, y=1 and z=2.
T angle(const TVector3D &) const
Gets the angle between the two vectors.
TVector3D(TVector3D &&) noexcept
Move constructor.
union sf::TVector3D::data_type _data
T lengthSqr2D() const
Gets the squared length or magnitude of the vector for only the X and Y axis.
const F * floatPtr(F value=1) const
Gets an array pointer of floating point type F of the X, Y and Z axis. Used to pass to OpenGL where a...
void updateMin(const TVector3D &vertex)
Copy only those values of x,y or z which are smaller.
T distance2D(const TVector3D &) const
Gets the distance between this and the passed vector for only the X and Y axis. Note that this has to...
TVector3D scaled(T factor) const
Scales the vector by multiplying all axes with the passed factor.
TVector3D & normalize()
Normalizes the vector also called a unit-vector, set to length 1.
T length2D() const
Gets the length or magnitude of the vector for only X and Y axis.
TVector3D normalized() const
Gets a normalized vector also called a unit-vector, made of length 1.
bool isEqual(const TVector3D &v, T tol=tolerance) const
Compares the passed vector within the set tolerance.
constexpr T y() const
Gets the y-coordinate value.
TVector3D()=default
Default constructor.
T distanceSqr(const TVector3D &) const
Gets the squared distance between 2 given points. Avoids taking an expensive sqrt call....
T length() const
Gets the length or magnitude of the vector.
T lengthSqr() const
Gets the squared length or magnitude of the vector.
static constexpr auto tolerance
Tolerance for when comparing in the equal operator. Empirical chosen epsilon multiplier to make it wo...
Definition TVector3D.h:381
TVector3D(const TVector3D &v)
Copy constructor.
T angleNormalized() const
Returns a normalized positive angle of function angle().
void updateMax(const TVector3D &vertex)
Copy only those values of x,y or z which are larger.
T dotProduct2D(const TVector3D &) const
Gets the dot (in) product of 2 vectors for only the X and Y axis.
TVector3D crossProduct(const TVector3D &) const
Gets the cross (out) product of 2 vectors.
std::string toString(int digits=0) const
Gets the string representation of the 2D vector formed like '(1.23,4.56)'.
T value_type
Type declaration of the coordinate storage values.
Definition TVector3D.h:22
constexpr T z() const
Gets the z-coordinate value.
TVector3D & scale(T factor)
Scales the vector by multiplying all axes with the passed factor.
T dotProduct(const TVector3D &) const
Gets the dot (in) product of 2 vectors.
Definition Application.h:10
_GII_FUNC std::istream & operator>>(std::istream &is, ResultData &)
Stream operator for setting up this instance with a setup std::string.
TMatrix44< T > operator*(const TMatrix44< T > &lm, const TMatrix44< T > &rm)
Multiplies to matrices into a single one.
TQuaternion< T > operator/(const TQuaternion< T > &lhs, const TQuaternion< T > &rhs)
Divides two quaternions.
Definition TQuaternion.h:420
_GII_FUNC std::ostream & operator<<(std::ostream &os, const ResultData &)
Stream operator for the setup std::string.
_MISC_FUNC int digits(double value)
Returns the amount of digits which are significant for the value. When the value is 12300....
Definition TVector3D.h:420
value_type x
Definition TVector3D.h:421
value_type z
Definition TVector3D.h:423
value_type y
Definition TVector3D.h:422
Storage union of the 3D coordinate making the x,y,z accessible as an array.
Definition TVector3D.h:416