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)
568 ocean_assert(
false &&
"Devision by zero!");
572 const T factor = T(1) / len;
586 const T factor = T(1) / len;
600 const T factor = T(1) / len;
613 const T factor = T(1) / len;
667 const T thisLength =
length();
668 const T rightLength = right.
length();
672 ocean_assert(
false &&
"Invalid vector!");
684 ocean_assert(epsilon >= T(0));
689 const T dotProduct = normalizedThis * normalizedRight;
697 ocean_assert(epsilon >= T(0));
832 const T factor = T(1) / value;
841 const T factor = T(1) / value;
858 ocean_assert(index < 2u);
865 ocean_assert(index < 2u);
872 ocean_assert(index < 2u);
879 ocean_assert(index < 2u);
898 size_t seed = std::hash<T>{}(vector.
x());
899 seed ^= std::hash<T>{}(vector.
y()) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
920 return std::move(vectors);
927 return std::move(vectors);
934 std::vector<VectorT2<T>> result;
935 result.reserve(vectors.size());
937 for (
typename std::vector<
VectorT2<U>>::const_iterator i = vectors.cbegin(); i != vectors.cend(); ++i)
939 result.emplace_back(*i);
963 std::vector<VectorT2<T>> result;
964 result.reserve(vectors.size());
966 for (
typename std::vector<
VectorT2<U>>::const_iterator i = vectors.cbegin(); i != vectors.cend(); ++i)
968 result.emplace_back(*i);
978 std::vector<VectorT2<T>> result;
979 result.reserve(size);
981 for (
size_t n = 0; n < size; ++n)
983 result.emplace_back(vectors[n]);
992 stream <<
"[" << vector.
x() <<
", " << vector.
y() <<
"]";
997template <
bool tActive,
typename T>
998MessageObject<tActive>&
operator<<(MessageObject<tActive>& messageObject,
const VectorT2<T>& vector)
1000 return messageObject <<
"[" << vector.x() <<
", " << vector.y() <<
"]";
1003template <
bool tActive,
typename T>
1004MessageObject<tActive>&
operator<<(MessageObject<tActive>&& messageObject,
const VectorT2<T>& vector)
1006 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: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 bool isNotEqual(const T first, const T second)
Returns whether two values are not equal up to a small epsilon.
Definition Numeric.h:2622
T Type
Definition of the signed data type, if existing.
Definition DataType.h:294
const T & x() const noexcept
Returns the x value.
Definition Vector2.h:703
VectorT2< T > & operator*=(const T &value)
Multiplies and assigns this vector with a scalar.
Definition Vector2.h:820
const T & y() const noexcept
Returns the y value.
Definition Vector2.h:715
VectorT2< T > operator+(const VectorT2< T > &vector) const
Adds two vectors.
Definition Vector2.h:772
VectorT2< T > & operator+=(const VectorT2< T > &vector)
Adds and assigns two vectors.
Definition Vector2.h:778
static VectorT2< T > minValue()
Returns a 2D vector with all elements set to NumericT::minValue().
Definition Vector2.h:905
VectorT2< T > & operator-=(const VectorT2< T > &vector)
Subtracts and assigns two vectors.
Definition Vector2.h:793
const T * operator()() const noexcept
Access operator.
Definition Vector2.h:884
bool isOrthogonal(const VectorT2< T > &right, const T epsilon=NumericT< T >::eps()) const
Returns whether two vectors are orthogonal.
Definition Vector2.h:695
VectorT2< T > & operator/=(const T &value)
Divides and assigns this vector by a scalar.
Definition Vector2.h:838
T operator*(const VectorT2< T > &vector) const
Returns the dot product of two vectors.
Definition Vector2.h:808
const T & operator[](const unsigned int index) const noexcept
Element access operator.
Definition Vector2.h:856
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:745
static VectorT2< T > maxValue()
Returns a 2D vector with all elements set to NumericT::maxValue().
Definition Vector2.h:911
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:932
VectorT2< T > operator-() const
Returns the negated vector.
Definition Vector2.h:802
const T * data() const noexcept
Returns an pointer to the vector elements.
Definition Vector2.h:727
bool operator==(const VectorT2< T > &vector) const
Returns whether two vectors are identical up to a small epsilon.
Definition Vector2.h:758
VectorT2< T > normalized() const
Returns the normalized vector.
Definition Vector2.h:563
bool isEqual(const VectorT2< T > &vector, const T eps) const
Returns whether two vectors are equal up to a specified epsilon.
Definition Vector2.h:751
T distance(const VectorT2< T > &right) const
Returns the distance between this 2D position and a second 2D position.
Definition Vector2.h:632
VectorT2< T > normalizedOrZero() const
Returns the normalized vector.
Definition Vector2.h:577
T angle(const VectorT2< T > &right) const
Returns the angle between this vector and a second vectors.
Definition Vector2.h:661
T sqr() const
Returns the square of the vector length.
Definition Vector2.h:626
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:591
bool operator!=(const VectorT2< T > &vector) const
Returns whether two vectors are not identical up to a small epsilon.
Definition Vector2.h:765
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:739
T sqrDistance(const VectorT2< T > &right) const
Returns the square distance between this 2D position and a second 2D position.
Definition Vector2.h:638
T length() const
Returns the length of the vector.
Definition Vector2.h:620
bool normalize()
Normalizes this vector.
Definition Vector2.h:605
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:850
T cross(const VectorT2< T > &vector) const
Returns the cross product of two 2D vectors.
Definition Vector2.h:549
bool isParallel(const VectorT2< T > &right, const T epsilon=NumericT< T >::eps()) const
Returns whether two vectors are parallel.
Definition Vector2.h:682
T Type
Definition of the used data type.
Definition Vector2.h:102
VectorT2< T > operator/(const T &value) const
Divides this vector by a scalar.
Definition Vector2.h:829
VectorT2< T > perpendicular() const
Returns a vector perpendicular to this vectors.
Definition Vector2.h:555
std::vector< VectorI2 > VectorsI2
Definition of a vector holding VectorI2 objects.
Definition Vector2.h:85
std::vector< Vector2 > Vectors2
Definition of a vector holding Vector2 objects.
Definition Vector2.h:64
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< VectorD2 > VectorsD2
Definition of a vector holding VectorD2 objects.
Definition Vector2.h:71
The namespace covering the entire Ocean framework.
Definition Accessor.h:15
std::ostream & operator<<(std::ostream &stream, const HighPerformanceStatistic &highPerformanceStatistic)
Definition HighPerformanceTimer.h:963