Files Class List
Vec2< T > Class Template Reference

Detailed Description

template<typename T>
class cy::Vec2< T >

2D vector class

#include <cyVector.h>

Public Member Functions

Set & Get value methods
void Zero ()
 
void Get (T *p) const
 
void Set (T const *p)
 
void Set (T v)
 
void Set (T _x, T _y)
 
General methods
void Normalize ()
 
Vec2 GetNormalized () const
 
LengthSquared () const
 
Length () const
 
Sum () const
 
bool IsZero () const
 
Min () const
 
Max () const
 
int MinID () const
 
int MaxID () const
 
bool IsFinite () const
 
bool IsUnit () const
 
Vec2 Sqrt () const
 
Vec2 Abs () const
 
Vec2 SortDesc () const
 
Vec2 SortAsc () const
 
Vec2 GetPerpendicular () const
 
Limit methods
void Clamp (T minLimit, T maxLimit)
 
void ClampMin (T v)
 
void ClampMax (T v)
 
void SetAbs ()
 
Unary operators
Vec2 operator- () const
 
Binary operators
Vec2 operator+ (Vec2 const &p) const
 
Vec2 operator- (Vec2 const &p) const
 
Vec2 operator* (Vec2 const &p) const
 
Vec2 operator/ (Vec2 const &p) const
 
Vec2 operator+ (T const v) const
 
Vec2 operator- (T const v) const
 
Vec2 operator* (T const v) const
 
Vec2 operator/ (T const v) const
 
Assignment operators
Vec2 const & operator+= (Vec2 const &p)
 
Vec2 const & operator-= (Vec2 const &p)
 
Vec2 const & operator*= (Vec2 const &p)
 
Vec2 const & operator/= (Vec2 const &p)
 
Vec2 const & operator+= (T const v)
 
Vec2 const & operator-= (T const v)
 
Vec2 const & operator*= (T const v)
 
Vec2 const & operator/= (T const v)
 
Test operators
bool operator== (Vec2 const &p) const
 
bool operator!= (Vec2 const &p) const
 
Access operators
T & operator[] (int i)
 
T const & operator[] (int i) const
 
T & Element (int i)
 
T const & Element (int i) const
 
T * Elements ()
 
T const * Elements () const
 
Cross product and dot product
Cross (Vec2 const &p) const
 
operator^ (Vec2 const &p) const
 
Dot (Vec2 const &p) const
 
operator% (Vec2 const &p) const
 

Public Attributes

x
 
y
 
elem [2]
 
Components of the vector
union {
   struct {
      T   x
 
      T   y
 
   } 
 
   T   elem [2]
 
}; 
 

Friends

Vec2 operator+ (T v, Vec2 const &p)
 
Vec2 operator- (T v, Vec2 const &p)
 
Vec2 operator* (T v, Vec2 const &p)
 

Constructors

_y: x( _x)
 
 Vec2 () CY_CLASS_FUNCTION_DEFAULT Vec2(T _x
 
y (_y)
 
 Vec2 (T v)
 
 Vec2 (Vec3< T > const &p)
 
 Vec2 (Vec4< T > const &p)
 
template<typename S >
 Vec2 (Vec2< S > const &p)
 
template<typename S >
 Vec2 (Vec3< S > const &p)
 
template<typename S >
 Vec2 (Vec4< S > const &p)
 
template<int N>
 Vec2 (Vec< T, N > const &p)
 
template<int N, typename S >
 Vec2 (Vec< S, N > const &p)
 

Member Function Documentation

§ Zero()

void Zero ( )

Sets the coordinates as zero.

§ Get()

void Get ( T *  p) const

Puts the coordinate values into the array.

§ Set() [1/3]

void Set ( T const *  p)

Sets the coordinates using the values in the given array.

§ Set() [2/3]

void Set ( v)

Sets all coordinates using the given value.

§ Set() [3/3]

void Set ( _x,
_y 
)

Sets the coordinates using the given values.

§ Normalize()

void Normalize ( )

Normalizes the vector, such that its length becomes 1.

§ GetNormalized()

Vec2 GetNormalized ( ) const

Returns a normalized copy of the vector.

§ LengthSquared()

T LengthSquared ( ) const

Returns the square of the length. Effectively, this is the dot product of the vector with itself.

§ Length()

T Length ( ) const

Returns the length of the vector.

§ Sum()

T Sum ( ) const

Returns the sum of its components.

§ IsZero()

bool IsZero ( ) const

Returns true if all components are exactly zero.

§ Min()

T Min ( ) const

Returns the minimum component of the vector.

§ Max()

T Max ( ) const

Returns the maximum component of the vector.

§ MinID()

int MinID ( ) const

Returns the index of the minimum component of the vector.

§ MaxID()

int MaxID ( ) const

Returns the index of the maximum component of the vector.

§ IsFinite()

bool IsFinite ( ) const

Returns true if all components are finite real numbers.

§ IsUnit()

bool IsUnit ( ) const

Returns true if the length of the vector is close to 1.

§ Sqrt()

Vec2 Sqrt ( ) const

Returns the square root of the vector.

§ Abs()

Vec2 Abs ( ) const

Returns a vector containing the absolute values of all components.

§ SortDesc()

Vec2 SortDesc ( ) const

Returns a vector with components sorted in descending order.

§ SortAsc()

Vec2 SortAsc ( ) const

Returns a vector with components sorted in ascending order.

§ GetPerpendicular()

Vec2 GetPerpendicular ( ) const

Returns a perpendicular vector (rotated by 90 degrees in counter clockwise direction).

§ Clamp()

void Clamp ( minLimit,
maxLimit 
)

Ensures that all components of the vector are within the given limits.

§ ClampMin()

void ClampMin ( v)

Ensures that all components of the vector are greater than or equal to the given limit.

§ ClampMax()

void ClampMax ( v)

Ensures that all components of the vector are smaller than or equal to the given limit.

§ SetAbs()

void SetAbs ( )

Converts all negative components to positive values.

§ Cross()

T Cross ( Vec2< T > const &  p) const

Cross product.

§ operator^()

T operator^ ( Vec2< T > const &  p) const

Cross product operator.

§ Dot()

T Dot ( Vec2< T > const &  p) const

Dot product.

§ operator%()

T operator% ( Vec2< T > const &  p) const

Dot product operator.

Friends And Related Function Documentation

§ operator+

Vec2 operator+ ( v,
Vec2< T > const &  p 
)
friend

Addition with a constant.

§ operator-

Vec2 operator- ( v,
Vec2< T > const &  p 
)
friend

Subtraction from a constant.

§ operator*

Vec2 operator* ( v,
Vec2< T > const &  p 
)
friend

Multiplication with a constant.

Member Data Documentation

§ elem

T elem[2]

Array-type access to the vector elements x and y.