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

Constructors
 Vec2 (T _x, T _y)
 
 Vec2 (T v)
 
 Vec2 (Vec3< T > const &p)
 
 Vec2 (Vec4< T > const &p)
 
 Vec2 (T const *v)
 
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)
 
Set & Get value methods
void Zero ()
 Sets the coordinates as zero.
 
void Get (T *p) const
 Puts the coordinate values into the array.
 
void Set (T const *p)
 Sets the coordinates using the values in the given array.
 
void Set (T v)
 Sets all coordinates using the given value.
 
void Set (T _x, T _y)
 Sets the coordinates using the given values.
 
void Normalize ()
 Normalizes the vector, such that its length becomes 1.
 
General methods
Vec2 GetNormalized () const
 Returns a normalized copy of the vector.
 
LengthSquared () const
 Returns the square of the length. Effectively, this is the dot product of the vector with itself.
 
Length () const
 Returns the length of the vector.
 
Sum () const
 Returns the sum of its components.
 
bool IsZero () const
 Returns true if all components are exactly zero.
 
Min () const
 Returns the minimum component of the vector.
 
Max () const
 Returns the maximum component of the vector.
 
int MinComp () const
 Returns the index of the minimum component of the vector.
 
int MaxComp () const
 Returns the index of the maximum component of the vector.
 
bool IsFinite () const
 Returns true if all components are finite real numbers.
 
bool IsUnit () const
 Returns true if the length of the vector is close to 1.
 
Vec2 Sqrt () const
 Returns the square root of the vector.
 
Vec2 Abs () const
 Returns a vector containing the absolute values of all components.
 
Vec2 SortAsc () const
 Returns a vector with components sorted in ascending order.
 
Vec2 SortDesc () const
 Returns a vector with components sorted in descending order.
 
Vec2 GetPerpendicular () const
 Returns a perpendicular vector (rotated by 90 degrees in counter clockwise direction).
 
Limit methods
void Clamp (T minLimit, T maxLimit)
 Ensures that all components of the vector are within the given limits.
 
void ClampMin (T v)
 Ensures that all components of the vector are greater than or equal to the given limit.
 
void ClampMax (T v)
 Ensures that all components of the vector are smaller than or equal to the given limit.
 
void SetAbs ()
 Converts all negative components to positive values.
 
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
 Cross product.
 
operator^ (Vec2 const &p) const
 Cross product operator.
 
Dot (Vec2 const &p) const
 Dot product.
 
operator% (Vec2 const &p) const
 Dot product operator.
 
Swizzling Methods
Vec2< T > XX () const
 
Vec2< T > XY () const
 
Vec2< T > YX () const
 
Vec2< T > YY () const
 

Public Attributes

Components of the vector
x
 
y
 

Friends

Vec2 operator- (T v, Vec2 const &p)
 Subtraction from a constant.
 
Vec2 operator+ (T v, Vec2 const &p)
 Addition with a constant.
 
Vec2 operator* (T v, Vec2 const &p)
 Multiplication with a constant.