8#ifndef META_OCEAN_MATH_VECTOR2_H
9#define META_OCEAN_MATH_VECTOR2_H
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 constexpr T minValue()
Returns the min scalar value.
Definition Numeric.h:3259
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
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 Scalar & x() const noexcept
VectorT2< T > & operator*=(const T &value)
Multiplies and assigns this vector with a scalar.
Definition Vector2.h:820
const Scalar & y() const noexcept
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< Scalar > minValue()
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< Scalar > &right, const Scalar epsilon=NumericT< Scalar >::eps()) const
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 Scalar eps=NumericT< Scalar >::eps()) const
static VectorT2< Scalar > maxValue()
static std::vector< VectorT2< Scalar > > vectors2vectors(std::vector< VectorT2< U > > &&vectors)
VectorT2< T > operator-() const
Returns the negated vector.
Definition Vector2.h:802
const Scalar * data() const noexcept
bool operator==(const VectorT2< T > &vector) const
Returns whether two vectors are identical up to a small epsilon.
Definition Vector2.h:758
VectorT2< Scalar > normalized() const
bool isEqual(const VectorT2< Scalar > &vector, const Scalar eps) const
Scalar distance(const VectorT2< Scalar > &right) const
VectorT2< Scalar > normalizedOrZero() const
Scalar angle(const VectorT2< Scalar > &right) const
VectorT2() noexcept
Creates a new 2D vector with undefined elements.
Definition Vector2.h:505
VectorT2< Scalar > normalizedOrValue(const VectorT2< Scalar > &value) const
bool operator!=(const VectorT2< T > &vector) const
Returns whether two vectors are not identical up to a small epsilon.
Definition Vector2.h:765
Scalar values_[2]
Definition Vector2.h:501
Scalar sqrDistance(const VectorT2< Scalar > &right) const
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
Scalar cross(const VectorT2< Scalar > &vector) const
bool isParallel(const VectorT2< Scalar > &right, const Scalar epsilon=NumericT< Scalar >::eps()) const
Scalar Type
Definition Vector2.h:102
VectorT2< T > operator/(const T &value) const
Divides this vector by a scalar.
Definition Vector2.h:829
VectorT2< Scalar > perpendicular() const
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
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< VectorF2 > VectorsF2
Definition of a vector holding VectorF2 objects.
Definition Vector2.h:78
VectorT2< int > VectorI2
Definition of a 2D vector with integer values.
Definition Vector2.h:49
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
The namespace covering the entire Ocean framework.
Definition Accessor.h:15
std::ostream & operator<<(std::ostream &stream, const HighPerformanceStatistic &highPerformanceStatistic)
Definition HighPerformanceTimer.h:963