XII Release 0.1.0
Loading...
Searching...
No Matches
xiiVec2Template< Type > Class Template Reference

A 2-component vector class. More...

#include <Vec2.h>

Public Types

using ComponentType = Type
 

Public Member Functions

 XII_DECLARE_POD_TYPE ()
 
 xiiVec2Template ()
 default-constructed vector is uninitialized (for speed)
 
 xiiVec2Template (Type x, Type y)
 Initializes the vector with x,y.
 
 xiiVec2Template (Type v)
 Initializes all components with xy.
 
const xiiVec3Template< Type > GetAsVec3 (Type z) const
 Returns a xiiVec3Template with x,y from this vector and z set by the parameter.
 
const xiiVec4Template< Type > GetAsVec4 (Type z, Type w) const
 Returns a xiiVec4Template with x,y from this vector and z and w set by the parameters.
 
const Type * GetData () const
 Returns the data as an array.
 
Type * GetData ()
 Returns the data as an array.
 
void Set (Type xy)
 Sets all components to this value.
 
void Set (Type x, Type y)
 Sets the vector to these values.
 
void SetZero ()
 Sets the vector to all zero.
 
XII_DECLARE_IF_FLOAT_TYPE Type GetLength () const
 Returns the length of the vector.
 
XII_DECLARE_IF_FLOAT_TYPE xiiResult SetLength (Type fNewLength, Type fEpsilon=xiiMath::DefaultEpsilon< Type >())
 Tries to rescale the vector to the given length. If the vector is too close to zero, XII_FAILURE is returned and the vector is set to zero.
 
Type GetLengthSquared () const
 Returns the squared length. Faster, since no square-root is taken. Useful, if one only wants to compare the lengths of two vectors.
 
XII_DECLARE_IF_FLOAT_TYPE Type GetLengthAndNormalize ()
 Normalizes this vector and returns its previous length in one operation. More efficient than calling GetLength and then Normalize.
 
XII_DECLARE_IF_FLOAT_TYPE const xiiVec2Template< Type > GetNormalized () const
 Returns a normalized version of this vector, leaves the vector itself unchanged.
 
XII_DECLARE_IF_FLOAT_TYPE void Normalize ()
 Normalizes this vector.
 
XII_DECLARE_IF_FLOAT_TYPE xiiResult NormalizeIfNotZero (const xiiVec2Template< Type > &vFallback=xiiVec2Template< Type >(1, 0), Type fEpsilon=xiiMath::DefaultEpsilon< Type >())
 Tries to normalize this vector. If the vector is too close to zero, XII_FAILURE is returned and the vector is set to the given fallback value.
 
bool IsZero () const
 Returns, whether this vector is (0, 0).
 
bool IsZero (Type fEpsilon) const
 Returns, whether this vector is (0, 0) within a certain threshold.
 
XII_DECLARE_IF_FLOAT_TYPE bool IsNormalized (Type fEpsilon=xiiMath::HugeEpsilon< Type >()) const
 Returns, whether the squared length of this vector is between 0.999f and 1.001f.
 
bool IsNaN () const
 Returns true, if any of x or y is NaN.
 
bool IsValid () const
 Checks that all components are finite numbers.
 
XII_DECLARE_IF_FLOAT_TYPE Type Distance (const xiiVec2Template< Type > &vPoint) const
 Returns the distance between two 2D Vectors.
 
Type DistanceSquared (const xiiVec2Template< Type > &vPoint) const
 Returns the squared distance between two 2D Vectors. Faster, since no square-root is taken. Useful, if one only wants to compare the distance of two vectors regardless of the magnitude.
 
const xiiVec2Template< Type > operator- () const
 Returns the negation of this vector.
 
void operator+= (const xiiVec2Template< Type > &vCc)
 Adds cc component-wise to this vector.
 
void operator-= (const xiiVec2Template< Type > &vCc)
 Subtracts cc component-wise from this vector.
 
void operator*= (Type f)
 Multiplies all components of this vector with f.
 
void operator/= (Type f)
 Divides all components of this vector by f.
 
bool IsIdentical (const xiiVec2Template< Type > &rhs) const
 Equality Check (bitwise)
 
bool IsEqual (const xiiVec2Template< Type > &rhs, Type fEpsilon) const
 Equality Check with epsilon.
 
xiiAngle GetAngleBetween (const xiiVec2Template< Type > &rhs) const
 Returns the positive angle between *this and rhs.
 
Type Dot (const xiiVec2Template< Type > &rhs) const
 Returns the Dot-product of the two vectors (commutative, order does not matter)
 
const xiiVec2Template< Type > CompMin (const xiiVec2Template< Type > &rhs) const
 Returns the component-wise minimum of *this and rhs.
 
const xiiVec2Template< Type > CompMax (const xiiVec2Template< Type > &rhs) const
 Returns the component-wise maximum of *this and rhs.
 
const xiiVec2Template< Type > CompClamp (const xiiVec2Template< Type > &vLow, const xiiVec2Template< Type > &vHigh) const
 Returns the component-wise clamped value of *this between low and high.
 
const xiiVec2Template< Type > CompMul (const xiiVec2Template< Type > &rhs) const
 Returns the component-wise multiplication of *this and rhs.
 
const xiiVec2Template< Type > CompDiv (const xiiVec2Template< Type > &rhs) const
 Returns the component-wise division of *this and rhs.
 
const xiiVec2Template< Type > Abs () const
 brief Returns the component-wise absolute of *this.
 
XII_DECLARE_IF_FLOAT_TYPE void MakeOrthogonalTo (const xiiVec2Template< Type > &vNormal)
 Modifies this direction vector to be orthogonal to the given (normalized) direction vector. The result is NOT normalized.
 
const xiiVec2Template< Type > GetOrthogonalVector () const
 Returns some arbitrary vector orthogonal to this one. The vector is NOT normalized.
 
XII_DECLARE_IF_FLOAT_TYPE const xiiVec2Template< Type > GetReflectedVector (const xiiVec2Template< Type > &vNormal) const
 Returns this vector reflected at vNormal.
 

Static Public Member Functions

static XII_DECLARE_IF_FLOAT_TYPE const xiiVec2Template< Type > MakeNaN ()
 Returns a vector with all components set to Not-a-Number (NaN).
 
static constexpr xiiVec2Template< Type > MakeZero ()
 Static function that returns a zero-vector.
 
static constexpr xiiVec2Template< Type > Make (Type x, Type y)
 Returns a vector initialized to x,y.
 

Public Attributes

Type x
 
Type y
 

Detailed Description

template<typename Type>
class xiiVec2Template< Type >

A 2-component vector class.

Member Function Documentation

◆ IsNormalized()

template<typename Type>
XII_IMPLEMENT_IF_FLOAT_TYPE bool xiiVec2Template< Type >::IsNormalized ( Type fEpsilon = xiiMath::HugeEpsilon<Type>()) const
inline

Returns, whether the squared length of this vector is between 0.999f and 1.001f.

Note
Normalization, especially with SSE is not very precise. So this function checks whether the (squared) length is between a lower and upper limit.

◆ MakeOrthogonalTo()

template<typename Type>
XII_IMPLEMENT_IF_FLOAT_TYPE void xiiVec2Template< Type >::MakeOrthogonalTo ( const xiiVec2Template< Type > & vNormal)
inline

Modifies this direction vector to be orthogonal to the given (normalized) direction vector. The result is NOT normalized.

Note
This function may fail, e.g. create a vector that is zero, if the given normal is parallel to the vector itself. If you need to handle such cases, you should manually check afterwards, whether the result is zero, or cannot be normalized.

The documentation for this class was generated from the following files: