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
76 TVector3D& operator*=(const TMatrix44<T>& mtx);
77
81 TVector3D operator*(const TMatrix44<T>& mtx);
82
86 TVector3D operator-() const;
87
91 TVector3D& operator+=(const TVector3D&);
92
96 TVector3D& operator-=(const TVector3D&);
97
101 TVector3D& operator*=(T c);
102
106 TVector3D& operator/=(T);
107
111 TVector3D operator+(const TVector3D&) const;
112
116 TVector3D operator-(const TVector3D&) const;
117
121 TVector3D operator/(T c) const;
122
129 bool isEqual(const TVector3D& v, T tol = tolerance) const;
130
137 bool isEqual(const TVector3D& v, const TVector3D& tol) const;
138
142 bool operator==(const TVector3D&) const;
143
147 bool operator!=(const TVector3D&) const;
148
153 T& operator[](size_t);
154
159 const T& operator[](size_t) const;
160
164 constexpr T* data();
165
169 constexpr const T* data() const;
170
174 // ReSharper disable once CppNonExplicitConversionOperator
175 constexpr operator T*();
176
180 // ReSharper disable once CppNonExplicitConversionOperator
181 constexpr operator const T*() const;
182
186 constexpr T x() const;
187
191 constexpr T& x();
192
196 constexpr T y() const;
197
201 constexpr T& y();
202
206 constexpr T z() const;
207
211 constexpr T& z();
212
219 T length() const;
220
227 T length2D() const;
228
233 T lengthSqr() const;
234
239 T lengthSqr2D() const;
240
246
252
257 TVector3D& scale(T factor);
258
263 TVector3D scaled(T factor) const;
264
270
275 T dotProduct(const TVector3D&) const;
276
281 T dotProduct2D(const TVector3D&) const;
282
287 TVector3D operator*(const TVector3D& v) const;
288
293 T angle(const TVector3D&) const;
294
300
306 T distance(const TVector3D&) const;
307
313 T distance2D(const TVector3D&) const;
314
321 T distanceSqr(const TVector3D&) const;
322
329 T distanceSqr2D(const TVector3D&) const;
330
335 void updateMin(const TVector3D& vertex);
336
341 void updateMax(const TVector3D& vertex);
342
346 std::string toString() const;
347
356 TVector3D& fromString(const std::string& s, bool ignore_err = false) noexcept(false);
357
363
369 static constexpr auto tolerance = std::numeric_limits<T>::epsilon() * T(15.0);
370
374 void copyTo(T fa[3]) const;
375
384 template<typename F = T, size_t N = 3>
385 std::array<F, N> array(F value = 1) const;
386
396 template<typename F = float, size_t N = 4>
397 const F* floatPtr(F value = 1) const;
398
399 protected:
414};
415
416template<typename T>
418{
419 return {v.x() * c, v.y() * c, v.z() * c};
420}
421
422template<typename T>
424{
425 return {v.x() * c, v.y() * c, v.z() * c};
426}
427
431template<typename T>
432std::istream& operator>>(std::istream& is, TVector3D<T>& v) noexcept(false)
433{
434 std::string s;
435 constexpr auto delimiter = ')';
436 std::getline(is, s, delimiter);
437 v.fromString(s.append(1, delimiter));
438 return is;
439}
440
444template<typename T>
445std::ostream& operator<<(std::ostream& os, const TVector3D<T>& v)
446{
447 return os << v.toString();
448}
449
450}// namespace sf
451
452// Include all inlined functions and template implementations.
453#include <math/TVector3D.hpp>
Generic 4 x 4 matrix template.
Definition TMatrix44.h:38
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 axis 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:369
TVector3D(const TVector3D &v)
Copy constructor.
T angleNormalized() const
Returns a normalized positive angle of function angle().
std::string toString() const
Gets the string representation of the 2D vector formed like '(1.23,4.56)'.
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.
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 axis 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.
_GII_FUNC std::ostream & operator<<(std::ostream &os, const ResultData &)
Stream operator for the setup std::string.
Definition TVector3D.h:408
value_type x
Definition TVector3D.h:409
value_type z
Definition TVector3D.h:411
value_type y
Definition TVector3D.h:410
Storage union of the 3D coordinate making the x,y,z accessible as an array.
Definition TVector3D.h:404