3#include <Foundation/Math/Math.h>
5#if PL_ENABLED(PL_MATH_CHECK_FOR_NAN)
6# define PL_VEC2_CHECK_FOR_NAN(obj) (obj)->AssertNotNaN();
8# define PL_VEC2_CHECK_FOR_NAN(obj)
12template <
typename Type>
17 PL_DECLARE_POD_TYPE();
19 using ComponentType = Type;
41 PL_DECLARE_IF_FLOAT_TYPE
51#if PL_ENABLED(PL_MATH_CHECK_FOR_NAN)
52 void AssertNotNaN()
const
54 PL_ASSERT_ALWAYS(!
IsNaN(),
"This object contains NaN values. This can happen when you forgot to initialize it before using it. Please "
55 "check that all code-paths properly initialize this object.");
68 const Type*
GetData()
const {
return &x; }
79 void Set(Type x, Type y);
87 PL_DECLARE_IF_FLOAT_TYPE
92 PL_DECLARE_IF_FLOAT_TYPE
93 plResult SetLength(Type fNewLength, Type fEpsilon = plMath::DefaultEpsilon<Type>());
101 PL_DECLARE_IF_FLOAT_TYPE
105 PL_DECLARE_IF_FLOAT_TYPE
109 PL_DECLARE_IF_FLOAT_TYPE
114 PL_DECLARE_IF_FLOAT_TYPE
121 bool IsZero(Type fEpsilon)
const;
124 PL_DECLARE_IF_FLOAT_TYPE
125 bool IsNormalized(Type fEpsilon = plMath::HugeEpsilon<Type>())
const;
191 PL_DECLARE_IF_FLOAT_TYPE
198 PL_DECLARE_IF_FLOAT_TYPE
205template <
typename Type>
209template <
typename Type>
213template <
typename Type>
217template <
typename Type>
221template <
typename Type>
225template <
typename Type>
229template <
typename Type>
233template <
typename Type>
236#include <Foundation/Math/Implementation/Vec2_inl.h>
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
const plVec3Template< Type > GetAsVec3(Type z) const
Returns an plVec3Template with x,y from this vector and z set by the parameter.
Definition Vec4_inl.h:10
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 plVec4Template< Type > GetAsVec4(Type z, Type w) const
Returns an plVec4Template with x,y from this vector and z and w set by the parameters.
Definition Vec4_inl.h:18
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
static constexpr plVec2Template< Type > MakeZero()
Static function that returns a zero-vector.
Definition Vec2.h:49
bool IsValid() const
Checks that all components are finite numbers.
Definition Vec2_inl.h:146
Type * GetData()
Returns the data as an array.
Definition Vec2.h:71
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
static PL_DECLARE_IF_FLOAT_TYPE const plVec2Template< Type > MakeNaN()
Returns a vector with all components set to Not-a-Number (NaN).
Definition Vec2.h:43
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
const Type * GetData() const
Returns the data as an array.
Definition Vec2.h:68
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
A 3-component vector class.
Definition Vec3.h:9
A 4-component vector class.
Definition Vec4.h:9
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
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54