8#ifndef META_OCEAN_MATH_VECTOR3_H
9#define META_OCEAN_MATH_VECTOR3_H
119 inline explicit
VectorT3(const
bool setToHomogeneous) noexcept;
133 inline explicit
VectorT3(const T* valueArray) noexcept;
153 template <typename U>
278 inline const T&
x() const noexcept;
284 inline T&
x() noexcept;
290 inline const T&
y() const noexcept;
296 inline T&
y() noexcept;
302 inline const T&
z() const noexcept;
308 inline T&
z() noexcept;
320 inline const T*
data() const noexcept;
360 inline
bool operator==(const
VectorT3<T>& vector) const;
367 inline
bool operator!=(const
VectorT3<T>& vector) const;
408 inline T operator*(const
VectorT3<T>& vector) const;
415 inline
VectorT3<T> operator*(const T& value) const;
432 inline
VectorT3<T> operator/(const T& value) const;
450 inline
bool operator<(const
VectorT3<T>& vector) const;
457 inline const T& operator[](const
unsigned int index) const noexcept;
464 inline T& operator[](const
unsigned int index) noexcept;
471 inline const T& operator()(const
unsigned int index) const noexcept;
478 inline T& operator()(const
unsigned int index) noexcept;
484 inline const T* operator()() const noexcept;
490 inline T* operator()() noexcept;
497 inline
size_t operator()(const
VectorT3<T>& vector) const;
517 template <typename U>
526 template <typename U>
536 template <typename U>
548 static_assert(std::is_arithmetic<T>::value,
"VectorT3 only supports arithmetic types");
555 if (setToHomogeneous)
580 memcpy(
values_, valueArray,
sizeof(T) * 3);
614 ocean_assert(
false &&
"Division by zero!");
618 const T factor = T(1) / len;
632 const T factor = T(1) / len;
646 const T factor = T(1) / len;
659 const T factor = T(1) / len;
698 const T thisLength =
length();
699 const T rightLength = right.
length();
703 ocean_assert(
false &&
"Invalid vector!");
716 ocean_assert(*
this * normal >= 0);
719 const VectorT3<T> result(normal * ((normal * *
this) * 2) - *
this);
720 ocean_assert(
int(
angle(normal) * 100) ==
int(result.
angle(normal) * 100));
721 ocean_assert(result * normal >= 0);
725 return normal * ((normal * *
this) * 2) - *
this;
732 ocean_assert(*
this * normal >= 0);
733 ocean_assert(index > T(0));
735 const T dot = normal * *
this;
737 const T sqrtValue = T(1) - (index * index) * (T(1) - dot * dot);
740 if (sqrtValue < T(0))
747 const T angle0 =
angle(normal);
748 const T angle1 = result.
angle(-normal);
756 return normal * (index * dot -
NumericT<T>::sqrt(T(1) - (index * index) * (T(1) - dot * dot))) - *
this * index;
780 if (std::is_same<double, Scalar>::value)
785 const T dotProduct = normalizedThis * normalizedRight;
790 ocean_assert_accuracy(debugResult == (!
isNull() && !right.
isNull() && crossVector.
isNull()));
958 T factor = T(1) / value;
968 T factor = T(1) / value;
988 ocean_assert(index < 3u);
995 ocean_assert(index < 3u);
1002 ocean_assert(index < 3u);
1006template <
typename T>
1009 ocean_assert(index < 3u);
1013template <
typename T>
1019template <
typename T>
1025template <
typename T>
1028 size_t seed = std::hash<T>{}(vector.
x());
1029 seed ^= std::hash<T>{}(vector.
y()) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
1030 seed ^= std::hash<T>{}(vector.
z()) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
1035template <
typename T>
1041template <
typename T>
1051 return std::move(vectors);
1058 return std::move(vectors);
1061template <
typename T>
1062template <
typename U>
1065 std::vector<VectorT3<T>> result;
1066 result.reserve(vectors.size());
1068 for (
typename std::vector<
VectorT3<U>>::const_iterator i = vectors.cbegin(); i != vectors.cend(); ++i)
1070 result.emplace_back(*i);
1090template <
typename T>
1091template <
typename U>
1094 std::vector<VectorT3<T>> result;
1095 result.reserve(vectors.size());
1097 for (
typename std::vector<
VectorT3<U>>::const_iterator i = vectors.cbegin(); i != vectors.cend(); ++i)
1099 result.emplace_back(*i);
1105template <
typename T>
1106template <
typename U>
1109 std::vector< VectorT3<T>> result;
1110 result.reserve(size);
1112 for (
size_t n = 0; n < size; ++n)
1114 result.emplace_back(vectors[n]);
1120template <
typename T>
1123 stream <<
"[" << vector.
x() <<
", " << vector.
y() <<
", " << vector.
z() <<
"]";
1128template <
bool tActive,
typename T>
1129MessageObject<tActive>&
operator<<(MessageObject<tActive>& messageObject,
const VectorT3<T>& vector)
1131 return messageObject <<
"[" << vector.x() <<
", " << vector.y() <<
", " << vector.z() <<
"]";
1134template <
bool tActive,
typename T>
1135MessageObject<tActive>&
operator<<(MessageObject<tActive>&& messageObject,
const VectorT3<T>& vector)
1137 return messageObject <<
"[" << vector.x() <<
", " << vector.y() <<
", " << vector.z() <<
"]";
This class provides basic numeric functionalities.
Definition Numeric.h:57
static constexpr T minValue()
Returns the min scalar value.
Definition Numeric.h:3259
static T sin(const T value)
Returns the sine of a given value.
Definition Numeric.h:1572
static bool isWeakEqual(const T first, const T second)
Returns whether two values a equal up to a weak epsilon.
Definition Numeric.h:2581
static T sqrt(const T value)
Returns the square root of a given value.
Definition Numeric.h:1537
static bool isEqual(const T first, const T second)
Returns whether two values are equal up to a small epsilon.
Definition Numeric.h:2395
static constexpr T sqr(const T value)
Returns the square of a given value.
Definition Numeric.h:1499
static constexpr bool isEqualEps(const T value)
Returns whether a value is smaller than or equal to a small epsilon.
Definition Numeric.h:2096
static T acos(const T value)
Returns the arccosine of a given value.
Definition Numeric.h:2916
static constexpr bool isNotEqualEps(const T value)
Returns whether a value is not smaller than or equal to a small epsilon.
Definition Numeric.h:2246
static bool isNotEqual(const T first, const T second)
Returns whether two values are not equal up to a small epsilon.
Definition Numeric.h:2622
static constexpr T maxValue()
Returns the max scalar value.
Definition Numeric.h:3253
This class implements a vector with two elements.
Definition Vector2.h:96
This class implements a vector with three elements.
Definition Vector3.h:97
bool isUnit(const unsigned int eps=NumericT< unsigned int >::eps()) const
VectorT3< unsigned int > normalizedOrValue(const VectorT3< unsigned int > &value) const
const T * operator()() const noexcept
Access operator.
Definition Vector3.h:1014
VectorT3< unsigned int > perpendicular() const
bool operator!=(const VectorT3< T > &vector) const
Returns whether two vectors are not identical up to a small epsilon.
Definition Vector3.h:887
VectorT3< T > & operator*=(const T &value)
Multiplies and assigns this vector with a scalar.
Definition Vector3.h:945
const unsigned int & y() const noexcept
VectorT3< T > & operator-=(const VectorT3< T > &vector)
Subtracts and assigns two vectors.
Definition Vector3.h:917
T operator*(const VectorT3< T > &vector) const
Returns the dot product of two vectors.
Definition Vector3.h:933
VectorT3< unsigned int > cross(const VectorT3< unsigned int > &vector) const
bool isOrthogonal(const VectorT3< unsigned int > &right) const
const T & operator[](const unsigned int index) const noexcept
Element access operator.
Definition Vector3.h:986
const unsigned int & x() const noexcept
VectorT2< unsigned int > xy() const noexcept
VectorT3< unsigned int > normalizedOrZero() const
VectorT3< unsigned int > refract(const VectorT3< unsigned int > &normal, const unsigned int index) const
VectorT3< unsigned int > normalized() const
static VectorT3< unsigned int > minValue()
const unsigned int & z() const noexcept
VectorT3() noexcept
Creates a new 3D vector with undefined elements.
Definition Vector3.h:546
bool isEqual(const VectorT3< unsigned int > &vector, const unsigned int eps) const
unsigned int values_[3]
Definition Vector3.h:542
unsigned int Type
Definition Vector3.h:103
const unsigned int * data() const noexcept
VectorT3< T > & operator/=(const T &value)
Divides and assigns this vector by a scalar.
Definition Vector3.h:964
unsigned int distance(const VectorT3< unsigned int > &right) const
unsigned int sqrDistance(const VectorT3< unsigned int > &right) const
VectorT3< T > operator/(const T &value) const
Divides this vector by a scalar.
Definition Vector3.h:955
static VectorT3< unsigned int > maxValue()
VectorT3< T > operator-() const
Returns the negated vector.
Definition Vector3.h:927
unsigned int length() const
bool isParallel(const VectorT3< unsigned int > &right) const
VectorT3< T > operator+(const VectorT3< T > &vector) const
Adds two vectors.
Definition Vector3.h:895
VectorT3< unsigned int > reflect(const VectorT3< unsigned int > &normal) const
VectorT3< T > & operator+=(const VectorT3< T > &vector)
Adds and assigns two vectors.
Definition Vector3.h:901
bool operator==(const VectorT3< T > &vector) const
Returns whether two vectors are identical up to a small epsilon.
Definition Vector3.h:879
unsigned int angle(const VectorT3< unsigned int > &right) const
static std::vector< VectorT3< unsigned int > > vectors2vectors(std::vector< VectorT3< U > > &&vectors)
bool operator<(const VectorT3< T > &vector) const
Compares two vector objects and returns whether the left vector represents a smaller value than the r...
Definition Vector3.h:978
VectorT3< float > VectorF3
Definition of a 3D vector with float values.
Definition Vector3.h:43
std::vector< VectorT3< T > > VectorsT3
Definition of a typename alias for vectors with VectorT3 objects.
Definition Vector3.h:58
std::vector< VectorI3 > VectorsI3
Definition of a vector holding VectorI3 objects.
Definition Vector3.h:86
std::vector< VectorF3 > VectorsF3
Definition of a vector holding VectorF3 objects.
Definition Vector3.h:79
VectorT3< Scalar > Vector3
Definition of a 3D vector.
Definition Vector3.h:29
std::vector< Vector3 > Vectors3
Definition of a vector holding Vector3 objects.
Definition Vector3.h:65
VectorT3< int > VectorI3
Definition of a 3D vector with integer values.
Definition Vector3.h:50
VectorT3< double > VectorD3
Definition of a 3D vector with double values.
Definition Vector3.h:36
std::vector< VectorD3 > VectorsD3
Definition of a vector holding VectorD3 objects.
Definition Vector3.h:72
The namespace covering the entire Ocean framework.
Definition Accessor.h:15
std::ostream & operator<<(std::ostream &stream, const HighPerformanceStatistic &highPerformanceStatistic)
Definition HighPerformanceTimer.h:963