8#ifndef META_OCEAN_MATH_VECTOR4_H
9#define META_OCEAN_MATH_VECTOR4_H
22template <
typename T>
class VectorT4;
119 inline VectorT4(
const T&
x,
const T&
y,
const T&
z,
const T&
w)
noexcept;
139 inline explicit VectorT4(
const T* valueArray)
noexcept;
152 template <
typename U>
197 inline T
sqr()
const;
229 inline const T&
x() const noexcept;
235 inline T&
x() noexcept;
241 inline const T&
y() const noexcept;
247 inline T&
y() noexcept;
253 inline const T&
z() const noexcept;
259 inline T&
z() noexcept;
265 inline const T&
w() const noexcept;
271 inline T&
w() noexcept;
289 inline const T*
data() const noexcept;
295 inline T*
data() noexcept;
301 inline
bool isNull() const;
329 inline
bool operator==(const
VectorT4<T>& vector) const;
336 inline
bool operator!=(const
VectorT4<T>& vector) const;
370 inline
VectorT4<T> operator-() const;
377 inline T operator*(const
VectorT4<T>& vector) const;
384 inline
VectorT4<T> operator*(const T& value) const;
391 inline
VectorT4<T>& operator*=(const T& value);
401 inline
VectorT4<T> operator/(const T& value) const;
411 inline
VectorT4<T>& operator/=(const T& value);
419 inline
bool operator<(const
VectorT4<T>& vector) const;
426 inline const T& operator[](const
unsigned int index) const noexcept;
433 inline T& operator[](const
unsigned int index) noexcept;
440 inline const T& operator()(const
unsigned int index) const noexcept;
447 inline T& operator()(const
unsigned int index) noexcept;
453 inline const T* operator()() const noexcept;
459 inline T* operator()() noexcept;
466 inline
size_t operator()(const
VectorT4<T>& vector) const;
486 template <typename U>
495 template <typename U>
505 template <typename U>
526 memcpy(values_, vector(),
sizeof(T) * 3);
533 memcpy(values_, vector(),
sizeof(T) * 3);
540 memcpy(values_, valueArray,
sizeof(T) * 4);
547 values_[0] = T(vector[0]);
548 values_[1] = T(vector[1]);
549 values_[2] = T(vector[2]);
550 values_[3] = T(vector[3]);
559 ocean_assert(
false &&
"Division by zero!");
563 T factor = T(1) / len;
564 return VectorT4<T>(values_[0] * factor, values_[1] * factor, values_[2] * factor, values_[3] * factor);
570 const T len = length();
577 const T factor = T(1) / len;
578 return VectorT4<T>(values_[0] * factor, values_[1] * factor, values_[2] * factor, values_[3] * factor);
584 const T len = length();
591 const T factor = T(1) / len;
592 return VectorT4<T>(values_[0] * factor, values_[1] * factor, values_[2] * factor, values_[3] * factor);
598 const T len = length();
604 const T factor = T(1) / len;
605 values_[0] *= factor;
606 values_[1] *= factor;
607 values_[2] *= factor;
608 values_[3] *= factor;
615 return NumericT<T>::sqrt(values_[0] * values_[0] + values_[1] * values_[1] + values_[2] * values_[2] + values_[3] * values_[3]);
621 return values_[0] * values_[0] + values_[1] * values_[1] + values_[2] * values_[2] + values_[3] * values_[3];
631 const T thisLength = length();
632 const T rightLength = right.
length();
636 ocean_assert(
false &&
"Invalid vector!");
640 const T dot = values_[0] * right.
values_[0] + values_[1] * right.
values_[1] + values_[2] * right.
values_[2] + values_[3] * right.
values_[3];
648 const VectorT4<T> normalizedThis(normalizedOrZero());
651 const T dotProduct = normalizedThis * normalizedRight;
719 return VectorT3<T>(values_[0], values_[1], values_[2]);
783 values_[0] += vector.
values_[0];
784 values_[1] += vector.
values_[1];
785 values_[2] += vector.
values_[2];
786 values_[3] += vector.
values_[3];
800 values_[0] -= vector.
values_[0];
801 values_[1] -= vector.
values_[1];
802 values_[2] -= vector.
values_[2];
803 values_[3] -= vector.
values_[3];
811 return VectorT4<T>(-values_[0], -values_[1], -values_[2], -values_[3]);
817 return values_[0] * vector.
values_[0] + values_[1] * vector.
values_[1] + values_[2] * vector.
values_[2] + values_[3] * vector.
values_[3];
823 return VectorT4<T>(values_[0] * value, values_[1] * value, values_[2] * value, values_[3] * value);
841 const T factor = T(1) / value;
843 return VectorT4<T>(values_[0] * factor, values_[1] * factor, values_[2] * factor, values_[3] * factor);
851 const T factor = T(1) / value;
853 values_[0] *= factor;
854 values_[1] *= factor;
855 values_[2] *= factor;
856 values_[3] *= factor;
864 return values_[0] < right.
values_[0]
865 || (values_[0] == right.
values_[0] && (values_[1] < right.
values_[1]
866 || (values_[1] == right.
values_[1] && (values_[2] < right.
values_[2]
867 || (values_[2] == right.
values_[2] && values_[3] < right.
values_[3])))));
873 ocean_assert(index < 4u);
874 return values_[index];
880 ocean_assert(index < 4u);
881 return values_[index];
887 ocean_assert(index < 4u);
888 return values_[index];
894 ocean_assert(index < 4u);
895 return values_[index];
913 size_t seed = std::hash<T>{}(vector.
x());
914 seed ^= std::hash<T>{}(vector.
y()) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
915 seed ^= std::hash<T>{}(vector.
z()) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
916 seed ^= std::hash<T>{}(vector.
w()) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
937 return std::move(vectors);
944 return std::move(vectors);
951 std::vector<VectorT4<T>> result;
952 result.reserve(vectors.size());
954 for (
typename std::vector<
VectorT4<U>>::const_iterator i = vectors.cbegin(); i != vectors.cend(); ++i)
956 result.emplace_back(*i);
980 std::vector<VectorT4<T>> result;
981 result.reserve(vectors.size());
983 for (
typename std::vector<
VectorT4<U>>::const_iterator i = vectors.begin(); i != vectors.end(); ++i)
985 result.emplace_back(*i);
995 std::vector<VectorT4<T>> result;
996 result.reserve(size);
998 for (
size_t n = 0; n < size; ++n)
1000 result.emplace_back(vectors[n]);
1006template <
typename T>
1009 stream <<
"[" << vector.
x() <<
", " << vector.
y() <<
", " << vector.
z() <<
", " << vector.
w() <<
"]";
1014template <
bool tActive,
typename T>
1015MessageObject<tActive>&
operator<<(MessageObject<tActive>& messageObject,
const VectorT4<T>& vector)
1017 return messageObject <<
"[" << vector.x() <<
", " << vector.y() <<
", " << vector.z() <<
", " << vector.w() <<
"]";
1020template <
bool tActive,
typename T>
1021MessageObject<tActive>&
operator<<(MessageObject<tActive>&& messageObject,
const VectorT4<T>& vector)
1023 return messageObject <<
"[" << vector.x() <<
", " << vector.y() <<
", " << vector.z() <<
", " << vector.w() <<
"]";
This class provides basic numeric functionalities.
Definition Numeric.h:57
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 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 bool isNotEqual(const T first, const T second)
Returns whether two values are not equal up to a small epsilon.
Definition Numeric.h:2622
This class implements a vector with two elements.
Definition Vector2.h:96
This class implements a vector with three elements.
Definition Vector3.h:97
This class implements a vector with four elements.
Definition Vector4.h:97
VectorT4< T > operator/(const T &value) const
Divides this vector by a scalar.
Definition Vector4.h:838
VectorT3< T > xyz() const noexcept
Returns the x, y and z component of the vector as new 3D vector.
Definition Vector4.h:717
bool isOrthogonal(const VectorT4< T > &right) const
Returns whether two vectors are orthogonal.
Definition Vector4.h:657
static std::vector< VectorT4< T > > vectors2vectors(std::vector< VectorT4< U > > &&vectors)
Converts vectors with specific data type to vectors with different data type.
Definition Vector4.h:949
const T * operator()() const noexcept
Access operator.
Definition Vector4.h:899
VectorT4< T > normalizedOrZero() const
Returns the normalized vector.
Definition Vector4.h:568
bool operator==(const VectorT4< T > &vector) const
Returns whether two vectors are identical up to a small epsilon.
Definition Vector4.h:757
T length() const
Returns the length of the vector.
Definition Vector4.h:613
const T & y() const noexcept
Returns the y value.
Definition Vector4.h:675
const T & x() const noexcept
Returns the x value.
Definition Vector4.h:663
bool operator!=(const VectorT4< T > &vector) const
Returns whether two vectors are not identical up to a small epsilon.
Definition Vector4.h:766
VectorT4< T > & operator+=(const VectorT4< T > &vector)
Adds and assigns two vectors.
Definition Vector4.h:781
bool isEqual(const VectorT4< T > &vector, const T eps) const
Returns whether two vectors are equal up to a specified epsilon.
Definition Vector4.h:748
const T * data() const noexcept
Returns an pointer to the vector elements.
Definition Vector4.h:723
const T & z() const noexcept
Returns the z value.
Definition Vector4.h:687
VectorT4()=default
Creates a new 2D vector with zeros as default values.
T Type
Definition of the used data type.
Definition Vector4.h:103
bool isNull() const
Returns whether this vector is a null vector up to a small epsilon.
Definition Vector4.h:735
VectorT4< T > normalized() const
Returns the normalized vector.
Definition Vector4.h:554
VectorT4< T > & operator/=(const T &value)
Divides and assigns this vector by a scalar.
Definition Vector4.h:847
VectorT4< T > & operator*=(const T &value)
Multiplies and assigns this vector with a scalar.
Definition Vector4.h:827
static VectorT4< T > maxValue()
Returns a 4D vector with all elements set to NumericT::maxValue().
Definition Vector4.h:928
bool isUnit(const T eps=NumericT< T >::eps()) const
Returns whether this vector is a unit vector (whether the vector has the length 1).
Definition Vector4.h:742
VectorT4< T > normalizedOrValue(const VectorT4< T > &value) const
Returns the normalized vector.
Definition Vector4.h:582
T values_[4]
The four values of the vector, with element order x, y, z, w.
Definition Vector4.h:511
const T & operator[](const unsigned int index) const noexcept
Element access operator.
Definition Vector4.h:871
T operator*(const VectorT4< T > &vector) const
Returns the dot product of two vectors.
Definition Vector4.h:815
static VectorT4< T > minValue()
Returns a 4D vector with all elements set to NumericT::minValue().
Definition Vector4.h:922
VectorT4(const VectorT4< T > &vector) noexcept=default
Copies a vector.
VectorT4< T > operator+(const VectorT4< T > &vector) const
Adds two vectors.
Definition Vector4.h:775
T sqr() const
Returns the square of the vector length.
Definition Vector4.h:619
const T & w() const noexcept
Returns the w value.
Definition Vector4.h:699
bool normalize()
Normalizes this vector.
Definition Vector4.h:596
VectorT4< T > & operator-=(const VectorT4< T > &vector)
Subtracts and assigns two vectors.
Definition Vector4.h:798
VectorT2< T > xy() const noexcept
Returns the x and y component of the vector as new 2D vector.
Definition Vector4.h:711
VectorT4< T > operator-() const
Returns the negated vector.
Definition Vector4.h:809
bool operator<(const VectorT4< T > &vector) const
Compares two vector objects and returns whether the left vector represents a smaller value than the r...
Definition Vector4.h:862
T angle(const VectorT4< T > &right) const
Returns the angle between this vector and a second vectors.
Definition Vector4.h:625
bool isParallel(const VectorT4< T > &right) const
Returns whether two vectors are parallel.
Definition Vector4.h:646
std::vector< VectorI4 > VectorsI4
Definition of a vector holding VectorI4 objects.
Definition Vector4.h:86
std::vector< VectorF4 > VectorsF4
Definition of a vector holding VectorF4 objects.
Definition Vector4.h:79
std::vector< VectorT4< T > > VectorsT4
Definition of a typename alias for vectors with VectorT4 objects.
Definition Vector4.h:58
std::vector< Vector4 > Vectors4
Definition of a vector holding Vector4 objects.
Definition Vector4.h:65
std::vector< VectorD4 > VectorsD4
Definition of a vector holding VectorD4 objects.
Definition Vector4.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