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=(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
134 bool operator==(const TVector3D&) const;
135
139 bool operator!=(const TVector3D&) const;
140
145 T& operator[](size_t);
146
151 const T& operator[](size_t) const;
152
156 constexpr T* data();
157
161 constexpr const T* data() const;
162
166 // ReSharper disable once CppNonExplicitConversionOperator
167 constexpr operator T*();
168
172 // ReSharper disable once CppNonExplicitConversionOperator
173 constexpr operator const T*() const;
174
178 constexpr T x() const;
179
183 constexpr T& x();
184
188 constexpr T y() const;
189
193 constexpr T& y();
194
198 constexpr T z() const;
199
203 constexpr T& z();
204
211 T length() const;
212
219 T length2D() const;
220
225 T lengthSqr() const;
226
231 T lengthSqr2D() const;
232
238
244
249 TVector3D& scale(T factor);
250
255 TVector3D scaled(T factor) const;
256
262
267 T dotProduct(const TVector3D&) const;
268
273 T dotProduct2D(const TVector3D&) const;
274
279 TVector3D operator*(const TVector3D& v) const;
280
285 T angle(const TVector3D&) const;
286
292
298 T distance(const TVector3D&) const;
299
305 T distance2D(const TVector3D&) const;
306
313 T distanceSqr(const TVector3D&) const;
314
321 T distanceSqr2D(const TVector3D&) const;
322
327 void updateMin(const TVector3D& vertex);
328
333 void updateMax(const TVector3D& vertex);
334
338 std::string toString() const;
339
345 TVector3D& fromString(const std::string& s) noexcept(false);
346
352
358 static constexpr auto tolerance = std::numeric_limits<T>::epsilon() * T(15.0);
359
363 void copyTo(T fa[3]) const;
364
373 template<typename F = T, size_t N = 3>
374 std::array<F, N> array(F value = 1) const;
375
385 template<typename F = float, size_t N = 4>
386 const F* floatPtr(F value = 1) const;
387
388 protected:
402};
403
404template<typename T>
406{
407 return {v.x() * c, v.y() * c, v.z() * c};
408}
409
410template<typename T>
412{
413 return {v.x() * c, v.y() * c, v.z() * c};
414}
415
419template<typename T>
420std::istream& operator>>(std::istream& is, TVector3D<T>& v) noexcept(false)
421{
422 std::string s;
423 constexpr auto delimiter = ')';
424 std::getline(is, s, delimiter);
425 v.fromString(s.append(1, delimiter));
426 return is;
427}
428
432template<typename T>
433std::ostream& operator<<(std::ostream& os, const TVector3D<T>& v)
434{
435 return os << v.toString();
436}
437
438}// namespace sf
439
440// Include all inlined functions and template implementations.
441#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.
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...
TVector3D & fromString(const std::string &s) noexcept(false)
Gets the vector value from the string representation formed like '(1.23,4.56,7.89)'....
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:358
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:396
value_type x
Definition TVector3D.h:397
value_type z
Definition TVector3D.h:399
value_type y
Definition TVector3D.h:398
Storage union of the 3D coordinate making the x,y,z accessible as an array.
Definition TVector3D.h:393