8#ifndef META_OCEAN_MATH_VECTOR2_H
9#define META_OCEAN_MATH_VECTOR2_H
21template <
typename T>
class VectorT2;
118 inline explicit
VectorT2(const
bool setToHomogeneous) noexcept;
131 inline explicit
VectorT2(const T* valueArray) noexcept;
144 template <typename U>
255 inline const T&
x() const noexcept;
261 inline T&
x() noexcept;
267 inline const T&
y() const noexcept;
273 inline T&
y() noexcept;
279 inline const T*
data() const noexcept;
319 inline
bool operator==(const
VectorT2<T>& vector) const;
326 inline
bool operator!=(const
VectorT2<T>& vector) const;
367 inline T operator*(const
VectorT2<T>& vector) const;
374 inline
VectorT2<T> operator*(const T& value) const;
391 inline
VectorT2<T> operator/(const T& value) const;
409 inline
bool operator<(const
VectorT2<T>& vector) const;
416 inline const T& operator[](const
unsigned int index) const noexcept;
423 inline T& operator[](const
unsigned int index) noexcept;
430 inline const T& operator()(const
unsigned int index) const noexcept;
437 inline T& operator()(const
unsigned int index) noexcept;
443 inline const T* operator()() const noexcept;
449 inline T* operator()() noexcept;
456 inline
size_t operator()(const
VectorT2<T>& vector) const;
476 template <typename U>
485 template <typename U>
495 template <typename U>
507 static_assert(std::is_arithmetic<T>::value,
"VectorT2 only supports arithmetic types");
514 if (setToHomogeneous)
543 values_[0] = vector.values_[0];
544 values_[1] = vector.values_[1];
575 ocean_assert(
false &&
"Devision by zero!");
579 const T factor = T(1) / len;
593 const T factor = T(1) / len;
607 const T factor = T(1) / len;
620 const T factor = T(1) / len;
674 const T thisLength =
length();
675 const T rightLength = right.
length();
679 ocean_assert(
false &&
"Invalid vector!");
691 ocean_assert(epsilon >= T(0));
696 const T dotProduct = normalizedThis * normalizedRight;
704 ocean_assert(epsilon >= T(0));
853 const T factor = T(1) / value;
862 const T factor = T(1) / value;
879 ocean_assert(index < 2u);
886 ocean_assert(index < 2u);
893 ocean_assert(index < 2u);
900 ocean_assert(index < 2u);
919 size_t seed = std::hash<T>{}(vector.
x());
920 seed ^= std::hash<T>{}(vector.
y()) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
941 return std::move(vectors);
948 return std::move(vectors);
955 std::vector<VectorT2<T>> result;
956 result.reserve(vectors.size());
958 for (
typename std::vector<
VectorT2<U>>::const_iterator i = vectors.cbegin(); i != vectors.cend(); ++i)
960 result.emplace_back(*i);
984 std::vector<VectorT2<T>> result;
985 result.reserve(vectors.size());
987 for (
typename std::vector<
VectorT2<U>>::const_iterator i = vectors.cbegin(); i != vectors.cend(); ++i)
989 result.emplace_back(*i);
999 std::vector<VectorT2<T>> result;
1000 result.reserve(size);
1002 for (
size_t n = 0; n < size; ++n)
1004 result.emplace_back(vectors[n]);
1010template <
typename T>
1013 stream <<
"[" << vector.
x() <<
", " << vector.
y() <<
"]";
1018template <
bool tActive,
typename T>
1019MessageObject<tActive>&
operator<<(MessageObject<tActive>& messageObject,
const VectorT2<T>& vector)
1021 return messageObject <<
"[" << vector.x() <<
", " << vector.y() <<
"]";
1024template <
bool tActive,
typename T>
1025MessageObject<tActive>&
operator<<(MessageObject<tActive>&& messageObject,
const VectorT2<T>& vector)
1027 return messageObject <<
"[" << vector.x() <<
", " << vector.y() <<
"]";
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 T sqr(const T value)
Returns the square of a given value.
Definition Numeric.h:1495
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
T Type
Definition of the signed data type, if existing.
Definition DataType.h:294
This class implements a vector with two elements.
Definition Vector2.h:96
const T & x() const noexcept
Returns the x value.
Definition Vector2.h:710
VectorT2< T > & operator*=(const T &value)
Multiplies and assigns this vector with a scalar.
Definition Vector2.h:841
const T & y() const noexcept
Returns the y value.
Definition Vector2.h:722
VectorT2< T > operator+(const VectorT2< T > &vector) const
Adds two vectors.
Definition Vector2.h:793
VectorT2< T > & operator+=(const VectorT2< T > &vector)
Adds and assigns two vectors.
Definition Vector2.h:799
static VectorT2< T > minValue()
Returns a 2D vector with all elements set to NumericT::minValue().
Definition Vector2.h:926
VectorT2< T > & operator-=(const VectorT2< T > &vector)
Subtracts and assigns two vectors.
Definition Vector2.h:814
const T * operator()() const noexcept
Access operator.
Definition Vector2.h:905
bool isOrthogonal(const VectorT2< T > &right, const T epsilon=NumericT< T >::eps()) const
Returns whether two vectors are orthogonal.
Definition Vector2.h:702
VectorT2< T > & operator/=(const T &value)
Divides and assigns this vector by a scalar.
Definition Vector2.h:859
T operator*(const VectorT2< T > &vector) const
Returns the dot product of two vectors.
Definition Vector2.h:829
const T & operator[](const unsigned int index) const noexcept
Element access operator.
Definition Vector2.h:877
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 Vector2.h:752
static VectorT2< T > maxValue()
Returns a 2D vector with all elements set to NumericT::maxValue().
Definition Vector2.h:932
static std::vector< VectorT2< T > > vectors2vectors(std::vector< VectorT2< U > > &&vectors)
Converts vectors with specific data type to vectors with different data type.
Definition Vector2.h:953
VectorT2< T > operator-() const
Returns the negated vector.
Definition Vector2.h:823
const T * data() const noexcept
Returns an pointer to the vector elements.
Definition Vector2.h:734
bool operator==(const VectorT2< T > &vector) const
Returns whether two vectors are identical up to a small epsilon.
Definition Vector2.h:779
T Type
Definition of the used data type.
Definition Vector2.h:102
VectorT2< T > normalized() const
Returns the normalized vector.
Definition Vector2.h:570
bool isEqual(const VectorT2< T > &vector, const T eps) const
Returns whether two vectors are equal up to a specified epsilon.
Definition Vector2.h:758
T distance(const VectorT2< T > &right) const
Returns the distance between this 2D position and a second 2D position.
Definition Vector2.h:639
VectorT2< T > normalizedOrZero() const
Returns the normalized vector.
Definition Vector2.h:584
T angle(const VectorT2< T > &right) const
Returns the angle between this vector and a second vectors.
Definition Vector2.h:668
T sqr() const
Returns the square of the vector length.
Definition Vector2.h:633
VectorT2() noexcept
Creates a new 2D vector with undefined elements.
Definition Vector2.h:505
VectorT2< T > normalizedOrValue(const VectorT2< T > &value) const
Returns the normalized vector.
Definition Vector2.h:598
bool operator!=(const VectorT2< T > &vector) const
Returns whether two vectors are not identical up to a small epsilon.
Definition Vector2.h:786
T values_[2]
The two values of the vector, with element order x, y.
Definition Vector2.h:501
bool isNull() const
Returns whether this vector is a null vector up to a small epsilon.
Definition Vector2.h:746
T sqrDistance(const VectorT2< T > &right) const
Returns the square distance between this 2D position and a second 2D position.
Definition Vector2.h:645
VectorT2< T > & operator=(const VectorT2< T > &vector)
Copy assigns a vector.
Definition Vector2.h:765
T length() const
Returns the length of the vector.
Definition Vector2.h:627
bool normalize()
Normalizes this vector.
Definition Vector2.h:612
bool operator<(const VectorT2< T > &vector) const
Compares two vector objects and returns whether the left vector represents a smaller value than the r...
Definition Vector2.h:871
T cross(const VectorT2< T > &vector) const
Returns the cross product of two 2D vectors.
Definition Vector2.h:556
bool isParallel(const VectorT2< T > &right, const T epsilon=NumericT< T >::eps()) const
Returns whether two vectors are parallel.
Definition Vector2.h:689
VectorT2< T > operator/(const T &value) const
Divides this vector by a scalar.
Definition Vector2.h:850
VectorT2< T > perpendicular() const
Returns a vector perpendicular to this vectors.
Definition Vector2.h:562
VectorT2< int > VectorI2
Definition of a 2D vector with integer values.
Definition Vector2.h:49
VectorT2< double > VectorD2
Definition of a 2D vector with double values.
Definition Vector2.h:35
std::vector< VectorI2 > VectorsI2
Definition of a vector holding VectorI2 objects.
Definition Vector2.h:85
std::vector< VectorD2 > VectorsD2
Definition of a vector holding VectorD2 objects.
Definition Vector2.h:71
std::vector< VectorT2< T > > VectorsT2
Definition of a typename alias for vectors with VectorT2 objects.
Definition Vector2.h:57
std::vector< VectorF2 > VectorsF2
Definition of a vector holding VectorF2 objects.
Definition Vector2.h:78
std::vector< Vector2 > Vectors2
Definition of a vector holding Vector2 objects.
Definition Vector2.h:64
VectorT2< float > VectorF2
Definition of a 2D vector with float values.
Definition Vector2.h:42
VectorT2< Scalar > Vector2
Definition of a 2D vector.
Definition Vector2.h:28
The namespace covering the entire Ocean framework.
Definition Accessor.h:15
std::ostream & operator<<(std::ostream &stream, const HighPerformanceStatistic &highPerformanceStatistic)
Definition HighPerformanceTimer.h:963