3template <
typename Type>
6#if PL_ENABLED(PL_MATH_CHECK_FOR_NAN)
14template <
typename Type>
21template <
typename Type>
28template <
typename Type>
35template <
typename Type>
42template <
typename Type>
48template <
typename Type>
54template <
typename Type>
64template <
typename Type>
67 return (x * x + y * y);
70template <
typename Type>
73 const Type fLength = GetLength();
78template <
typename Type>
81 const Type fLen = GetLength();
87template <
typename Type>
93template <
typename Type>
96 PL_NAN_ASSERT(&vFallback);
98 const Type fLength = GetLength();
100 if (!plMath::IsFinite(fLength) ||
plMath::IsZero(fLength, fEpsilon))
113template <
typename Type>
116 const Type t = GetLengthSquared();
120template <
typename Type>
123 return (x == 0 && y == 0);
126template <
typename Type>
134template <
typename Type>
137 if (plMath::IsNaN(x))
139 if (plMath::IsNaN(y))
145template <
typename Type>
148 if (!plMath::IsFinite(x))
150 if (!plMath::IsFinite(y))
156template <
typename Type>
164template <
typename Type>
173template <
typename Type>
182template <
typename Type>
191template <
typename Type>
194 if constexpr (std::is_floating_point_v<Type>)
209template <
typename Type>
212 PL_ASSERT_DEBUG(vNormal.
IsNormalized(),
"The normal must be normalized.");
214 const Type fDot = this->Dot(vNormal);
215 *
this -= fDot * vNormal;
218template <
typename Type>
222 PL_ASSERT_DEBUG(!IsZero(plMath::SmallEpsilon<Type>()),
"The vector must not be zero to be able to compute an orthogonal vector.");
227template <
typename Type>
230 PL_ASSERT_DEBUG(vNormal.
IsNormalized(),
"vNormal must be normalized.");
232 return ((*
this) - (2 * this->Dot(vNormal) * vNormal));
235template <
typename Type>
241 return ((x * rhs.x) + (y * rhs.y));
244template <
typename Type>
247 PL_ASSERT_DEBUG(this->IsNormalized(),
"This vector must be normalized.");
248 PL_ASSERT_DEBUG(rhs.
IsNormalized(),
"The other vector must be normalized.");
253template <
typename Type>
262template <
typename Type>
271template <
typename Type>
275 PL_NAN_ASSERT(&vLow);
276 PL_NAN_ASSERT(&vHigh);
281template <
typename Type>
290template <
typename Type>
299template <
typename Type>
307template <
typename Type>
316template <
typename Type>
325template <
typename Type>
333template <
typename Type>
341template <
typename Type>
346 if constexpr (std::is_floating_point_v<Type>)
358template <
typename Type>
364 return ((x == rhs.x) && (y == rhs.y));
367template <
typename Type>
376template <
typename Type>
382template <
typename Type>
388template <
typename Type>
399 return (v1.y < v2.y);
Float wrapper struct for a safe usage and conversions of angles.
Definition Angle.h:10
A 2-component vector class.
Definition Vec2.h:14
plAngle GetAngleBetween(const plVec2Template< Type > &rhs) const
Returns the positive angle between *this and rhs.
Definition Vec2_inl.h:245
void operator-=(const plVec2Template< Type > &vCc)
Subtracts cc component-wise from this vector.
Definition Vec2_inl.h:174
PL_DECLARE_IF_FLOAT_TYPE Type GetLength() const
Returns the length of the vector.
Definition Vec2_inl.h:49
void operator+=(const plVec2Template< Type > &vCc)
Adds cc component-wise to this vector.
Definition Vec2_inl.h:165
void Set(Type xy)
Sets all components to this value.
Definition Vec2_inl.h:29
const plVec2Template< Type > GetOrthogonalVector() const
Returns some arbitrary vector orthogonal to this one. The vector is NOT normalized.
Definition Vec2_inl.h:219
PL_DECLARE_IF_FLOAT_TYPE void MakeOrthogonalTo(const plVec2Template< Type > &vNormal)
Modifies this direction vector to be orthogonal to the given (normalized) direction vector....
Definition Vec2_inl.h:210
const plVec2Template< Type > CompClamp(const plVec2Template< Type > &vLow, const plVec2Template< Type > &vHigh) const
Returns the component-wise clamped value of *this between low and high.
Definition Vec2_inl.h:272
void SetZero()
Sets the vector to all zero.
Definition Vec2_inl.h:43
const plVec2Template< Type > CompMul(const plVec2Template< Type > &rhs) const
Returns the component-wise multiplication of *this and rhs.
Definition Vec2_inl.h:282
bool IsValid() const
Checks that all components are finite numbers.
Definition Vec2_inl.h:146
PL_DECLARE_IF_FLOAT_TYPE const plVec2Template< Type > GetNormalized() const
Returns a normalized version of this vector, leaves the vector itself unchanged.
Definition Vec2_inl.h:79
void operator/=(Type f)
Divides all components of this vector by f.
Definition Vec2_inl.h:192
PL_DECLARE_IF_FLOAT_TYPE void Normalize()
Normalizes this vector.
Definition Vec2_inl.h:88
PL_DECLARE_IF_FLOAT_TYPE plResult NormalizeIfNotZero(const plVec2Template< Type > &vFallback=plVec2Template< Type >(1, 0), Type fEpsilon=plMath::DefaultEpsilon< Type >())
Tries to normalize this vector. If the vector is too close to zero, PL_FAILURE is returned and the ve...
Definition Vec2_inl.h:94
PL_DECLARE_IF_FLOAT_TYPE const plVec2Template< Type > GetReflectedVector(const plVec2Template< Type > &vNormal) const
Returns this vector reflected at vNormal.
Definition Vec2_inl.h:228
bool IsIdentical(const plVec2Template< Type > &rhs) const
Equality Check (bitwise)
Definition Vec2_inl.h:359
bool IsZero() const
Returns, whether this vector is (0, 0).
Definition Vec2_inl.h:121
PL_DECLARE_IF_FLOAT_TYPE bool IsNormalized(Type fEpsilon=plMath::HugeEpsilon< Type >()) const
Returns, whether the squared length of this vector is between 0.999f and 1.001f.
Definition Vec2_inl.h:114
const plVec2Template< Type > CompDiv(const plVec2Template< Type > &rhs) const
Returns the component-wise division of *this and rhs.
Definition Vec2_inl.h:291
Type Dot(const plVec2Template< Type > &rhs) const
Returns the Dot-product of the two vectors (commutative, order does not matter)
Definition Vec2_inl.h:236
bool IsNaN() const
Returns true, if any of x or y is NaN.
Definition Vec2_inl.h:135
const plVec2Template< Type > CompMax(const plVec2Template< Type > &rhs) const
Returns the component-wise maximum of *this and rhs.
Definition Vec2_inl.h:263
plVec2Template()
default-constructed vector is uninitialized (for speed)
Definition Vec2_inl.h:4
PL_DECLARE_IF_FLOAT_TYPE Type GetLengthAndNormalize()
Normalizes this vector and returns its previous length in one operation. More efficient than calling ...
Definition Vec2_inl.h:71
PL_DECLARE_IF_FLOAT_TYPE plResult SetLength(Type fNewLength, Type fEpsilon=plMath::DefaultEpsilon< Type >())
Tries to rescale the vector to the given length. If the vector is too close to zero,...
Definition Vec2_inl.h:55
Type GetLengthSquared() const
Returns the squared length. Faster, since no square-root is taken. Useful, if one only wants to compa...
Definition Vec2_inl.h:65
const plVec2Template< Type > Abs() const
brief Returns the component-wise absolute of *this.
Definition Vec2_inl.h:300
void operator*=(Type f)
Multiplies all components of this vector with f.
Definition Vec2_inl.h:183
bool IsEqual(const plVec2Template< Type > &rhs, Type fEpsilon) const
Equality Check with epsilon.
Definition Vec2_inl.h:368
const plVec2Template< Type > CompMin(const plVec2Template< Type > &rhs) const
Returns the component-wise minimum of *this and rhs.
Definition Vec2_inl.h:254
const plVec2Template< Type > operator-() const
Returns the negation of this vector.
Definition Vec2_inl.h:157
constexpr PL_ALWAYS_INLINE T Min(T f1, T f2)
Returns the smaller value, f1 or f2.
Definition Math_inl.h:27
PL_ALWAYS_INLINE plAngle ACos(float f)
Returns the arcus cosinus of f.
Definition MathFloat_inl.h:82
constexpr Type Invert(Type f)
Returns 1 / f.
Definition Math_inl.h:63
constexpr PL_ALWAYS_INLINE T Clamp(T value, T min_val, T max_val)
Clamps "value" to the range [min; max]. Returns "value", if it is inside the range already.
Definition Math_inl.h:51
constexpr TYPE NaN()
Returns the value for NaN as the template type. Returns zero, if the type does not support NaN.
Definition Constants_inl.h:58
PL_ALWAYS_INLINE double Sqrt(double f)
Returns the square root of f.
Definition MathDouble_inl.h:99
bool IsZero(Type f, Type fEpsilon)
Checks whether the given number is close to zero.
Definition Math_inl.h:288
constexpr bool IsEqual(Type lhs, Type rhs, Type fEpsilon)
Checks, whether fValue is in the range [fDesired - fMaxImprecision; fDesired + fMaxImprecision].
Definition Math_inl.h:276
constexpr PL_ALWAYS_INLINE T Abs(T f)
Returns the absolute value of f.
Definition Math_inl.h:21
constexpr PL_ALWAYS_INLINE T Max(T f1, T f2)
Returns the greater value, f1 or f2.
Definition Math_inl.h:39
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54