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);
546 values_[0] = vector.values_[0];
547 values_[1] = vector.values_[1];
548 values_[2] = vector.values_[2];
549 values_[3] = vector.values_[3];
556 values_[0] = T(vector[0]);
557 values_[1] = T(vector[1]);
558 values_[2] = T(vector[2]);
559 values_[3] = T(vector[3]);
568 ocean_assert(
false &&
"Division by zero!");
572 T factor = T(1) / len;
573 return VectorT4<T>(values_[0] * factor, values_[1] * factor, values_[2] * factor, values_[3] * factor);
579 const T len = length();
586 const T factor = T(1) / len;
587 return VectorT4<T>(values_[0] * factor, values_[1] * factor, values_[2] * factor, values_[3] * factor);
593 const T len = length();
600 const T factor = T(1) / len;
601 return VectorT4<T>(values_[0] * factor, values_[1] * factor, values_[2] * factor, values_[3] * factor);
607 const T len = length();
613 const T factor = T(1) / len;
614 values_[0] *= factor;
615 values_[1] *= factor;
616 values_[2] *= factor;
617 values_[3] *= factor;
624 return NumericT<T>::sqrt(values_[0] * values_[0] + values_[1] * values_[1] + values_[2] * values_[2] + values_[3] * values_[3]);
630 return values_[0] * values_[0] + values_[1] * values_[1] + values_[2] * values_[2] + values_[3] * values_[3];
640 const T thisLength = length();
641 const T rightLength = right.
length();
645 ocean_assert(
false &&
"Invalid vector!");
649 const T dot = values_[0] * right.
values_[0] + values_[1] * right.
values_[1] + values_[2] * right.
values_[2] + values_[3] * right.
values_[3];
657 const VectorT4<T> normalizedThis(normalizedOrZero());
660 const T dotProduct = normalizedThis * normalizedRight;
728 return VectorT3<T>(values_[0], values_[1], values_[2]);
773 values_[0] = vector.
values_[0];
774 values_[1] = vector.
values_[1];
775 values_[2] = vector.
values_[2];
776 values_[3] = vector.
values_[3];
808 values_[0] += vector.
values_[0];
809 values_[1] += vector.
values_[1];
810 values_[2] += vector.
values_[2];
811 values_[3] += vector.
values_[3];
825 values_[0] -= vector.
values_[0];
826 values_[1] -= vector.
values_[1];
827 values_[2] -= vector.
values_[2];
828 values_[3] -= vector.
values_[3];
836 return VectorT4<T>(-values_[0], -values_[1], -values_[2], -values_[3]);
842 return values_[0] * vector.
values_[0] + values_[1] * vector.
values_[1] + values_[2] * vector.
values_[2] + values_[3] * vector.
values_[3];
848 return VectorT4<T>(values_[0] * value, values_[1] * value, values_[2] * value, values_[3] * value);
866 const T factor = T(1) / value;
868 return VectorT4<T>(values_[0] * factor, values_[1] * factor, values_[2] * factor, values_[3] * factor);
876 const T factor = T(1) / value;
878 values_[0] *= factor;
879 values_[1] *= factor;
880 values_[2] *= factor;
881 values_[3] *= factor;
889 return values_[0] < right.
values_[0]
890 || (values_[0] == right.
values_[0] && (values_[1] < right.
values_[1]
891 || (values_[1] == right.
values_[1] && (values_[2] < right.
values_[2]
892 || (values_[2] == right.
values_[2] && values_[3] < right.
values_[3])))));
898 ocean_assert(index < 4u);
899 return values_[index];
905 ocean_assert(index < 4u);
906 return values_[index];
912 ocean_assert(index < 4u);
913 return values_[index];
919 ocean_assert(index < 4u);
920 return values_[index];
938 size_t seed = std::hash<T>{}(vector.
x());
939 seed ^= std::hash<T>{}(vector.
y()) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
940 seed ^= std::hash<T>{}(vector.
z()) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
941 seed ^= std::hash<T>{}(vector.
w()) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
962 return std::move(vectors);
969 return std::move(vectors);
976 std::vector<VectorT4<T>> result;
977 result.reserve(vectors.size());
979 for (
typename std::vector<
VectorT4<U>>::const_iterator i = vectors.cbegin(); i != vectors.cend(); ++i)
981 result.emplace_back(*i);
1001template <
typename T>
1002template <
typename U>
1005 std::vector<VectorT4<T>> result;
1006 result.reserve(vectors.size());
1008 for (
typename std::vector<
VectorT4<U>>::const_iterator i = vectors.begin(); i != vectors.end(); ++i)
1010 result.emplace_back(*i);
1016template <
typename T>
1017template <
typename U>
1020 std::vector<VectorT4<T>> result;
1021 result.reserve(size);
1023 for (
size_t n = 0; n < size; ++n)
1025 result.emplace_back(vectors[n]);
1031template <
typename T>
1034 stream <<
"[" << vector.
x() <<
", " << vector.
y() <<
", " << vector.
z() <<
", " << vector.
w() <<
"]";
1039template <
bool tActive,
typename T>
1040MessageObject<tActive>&
operator<<(MessageObject<tActive>& messageObject,
const VectorT4<T>& vector)
1042 return messageObject <<
"[" << vector.x() <<
", " << vector.y() <<
", " << vector.z() <<
", " << vector.w() <<
"]";
1045template <
bool tActive,
typename T>
1046MessageObject<tActive>&
operator<<(MessageObject<tActive>&& messageObject,
const VectorT4<T>& vector)
1048 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:1533
static bool isEqual(const T first, const T second)
Returns whether two values are equal up to a small epsilon.
Definition Numeric.h:2386
static constexpr bool isEqualEps(const T value)
Returns whether a value is smaller than or equal to a small epsilon.
Definition Numeric.h:2087
static T acos(const T value)
Returns the arccosine of a given value.
Definition Numeric.h:2907
static bool isNotEqual(const T first, const T second)
Returns whether two values are not equal up to a small epsilon.
Definition Numeric.h:2613
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:863
VectorT3< T > xyz() const noexcept
Returns the x, y and z component of the vector as new 3D vector.
Definition Vector4.h:726
bool isOrthogonal(const VectorT4< T > &right) const
Returns whether two vectors are orthogonal.
Definition Vector4.h:666
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:974
const T * operator()() const noexcept
Access operator.
Definition Vector4.h:924
T Type
Definition of the used data type.
Definition Vector4.h:103
VectorT4< T > normalizedOrZero() const
Returns the normalized vector.
Definition Vector4.h:577
bool operator==(const VectorT4< T > &vector) const
Returns whether two vectors are identical up to a small epsilon.
Definition Vector4.h:782
T length() const
Returns the length of the vector.
Definition Vector4.h:622
const T & y() const noexcept
Returns the y value.
Definition Vector4.h:684
const T & x() const noexcept
Returns the x value.
Definition Vector4.h:672
bool operator!=(const VectorT4< T > &vector) const
Returns whether two vectors are not identical up to a small epsilon.
Definition Vector4.h:791
VectorT4< T > & operator+=(const VectorT4< T > &vector)
Adds and assigns two vectors.
Definition Vector4.h:806
bool isEqual(const VectorT4< T > &vector, const T eps) const
Returns whether two vectors are equal up to a specified epsilon.
Definition Vector4.h:757
const T * data() const noexcept
Returns an pointer to the vector elements.
Definition Vector4.h:732
const T & z() const noexcept
Returns the z value.
Definition Vector4.h:696
VectorT4()=default
Creates a new 2D vector with zeros as default values.
bool isNull() const
Returns whether this vector is a null vector up to a small epsilon.
Definition Vector4.h:744
VectorT4< T > normalized() const
Returns the normalized vector.
Definition Vector4.h:563
VectorT4< T > & operator/=(const T &value)
Divides and assigns this vector by a scalar.
Definition Vector4.h:872
VectorT4< T > & operator*=(const T &value)
Multiplies and assigns this vector with a scalar.
Definition Vector4.h:852
static VectorT4< T > maxValue()
Returns a 4D vector with all elements set to NumericT::maxValue().
Definition Vector4.h:953
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:751
VectorT4< T > normalizedOrValue(const VectorT4< T > &value) const
Returns the normalized vector.
Definition Vector4.h:591
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:896
T operator*(const VectorT4< T > &vector) const
Returns the dot product of two vectors.
Definition Vector4.h:840
static VectorT4< T > minValue()
Returns a 4D vector with all elements set to NumericT::minValue().
Definition Vector4.h:947
VectorT4< T > operator+(const VectorT4< T > &vector) const
Adds two vectors.
Definition Vector4.h:800
T sqr() const
Returns the square of the vector length.
Definition Vector4.h:628
VectorT4< T > & operator=(const VectorT4< T > &vector)
Copy assigns a vector.
Definition Vector4.h:766
const T & w() const noexcept
Returns the w value.
Definition Vector4.h:708
bool normalize()
Normalizes this vector.
Definition Vector4.h:605
VectorT4< T > & operator-=(const VectorT4< T > &vector)
Subtracts and assigns two vectors.
Definition Vector4.h:823
VectorT2< T > xy() const noexcept
Returns the x and y component of the vector as new 2D vector.
Definition Vector4.h:720
VectorT4< T > operator-() const
Returns the negated vector.
Definition Vector4.h:834
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:887
T angle(const VectorT4< T > &right) const
Returns the angle between this vector and a second vectors.
Definition Vector4.h:634
bool isParallel(const VectorT4< T > &right) const
Returns whether two vectors are parallel.
Definition Vector4.h:655
std::vector< VectorI4 > VectorsI4
Definition of a vector holding VectorI4 objects.
Definition Vector4.h:86
std::vector< Vector4 > Vectors4
Definition of a vector holding Vector4 objects.
Definition Vector4.h:65
VectorT4< int > VectorI4
Definition of a 4D vector with integer values.
Definition Vector4.h:50
VectorT4< Scalar > Vector4
Definition of a 4D vector.
Definition Vector4.h:29
std::vector< VectorT4< T > > VectorsT4
Definition of a typename alias for vectors with VectorT4 objects.
Definition Vector4.h:58
std::vector< VectorD4 > VectorsD4
Definition of a vector holding VectorD4 objects.
Definition Vector4.h:72
VectorT4< float > VectorF4
Definition of a 4D vector with float values.
Definition Vector4.h:43
VectorT4< double > VectorD4
Definition of a 4D vector with double values.
Definition Vector4.h:36
std::vector< VectorF4 > VectorsF4
Definition of a vector holding VectorF4 objects.
Definition Vector4.h:79
The namespace covering the entire Ocean framework.
Definition Accessor.h:15
std::ostream & operator<<(std::ostream &stream, const HighPerformanceStatistic &highPerformanceStatistic)
Definition HighPerformanceTimer.h:963