csVector2 Class Reference [Geometry utilities]

A 2D vector. More...

`#include <csgeom/vector2.h>`

List of all members.

Public Member Functions

csVector2 (const csVector2 &o)
Copyconstructor.
csVector2 (float x, float y)
Make a new vector and initialize with the given values.
csVector2 (float v)
Make a new vector and initialize with the given values.
csVector2 ()
Make a new vector. No initialization is done.
csString Description () const
Return a textual representation of the vector in the form "x,y".
void Get (float *v)
Get the value of this vector.
float InverseNorm () const
Return the inverse norm (1/Norm()) (magnitude) of this vector.
float IsLeft (const csVector2 &p0, const csVector2 &p1)
Test if this point is left of the line through p0 and p1.
bool IsZero (float precision=SMALL_EPSILON) const
Query if the vector is zero.
float Norm () const
Return the norm (magnitude) of this vector.
void Normalize ()
Scale this vector to length = 1.0;.
csVector2operator*= (float f)
Multiply this vector by a scalar.
csVector2 operator+ () const
Unary + operator.
csVector2operator+= (const csVector2 &v)
Add another vector to this vector.
csVector2 operator- () const
Unary - operator.
csVector2operator-= (const csVector2 &v)
Subtract another vector from this vector.
csVector2operator/= (float f)
Divide this vector by a scalar.
float & operator[] (int n)
Returns n-th component of the vector.
float operator[] (int n) const
Returns n-th component of the vector.
void Rotate (float angle)
Rotate vector around the origin by a given angle in radians.
void Set (float v)
Set the value of this vector so that all components are the same.
void Set (float const *v)
Set the value of this vector.
void Set (csVector2 const &v)
Set vector to given values.
void Set (float ix, float iy)
Set vector to given values.
float SquaredNorm () const
Return the squared norm (magnitude) of this vector.
csVector2 Unit () const
Returns the unit vector in the direction of this vector.
csVector2 UnitAxisClamped () const
Return a version of the vector clamped to closest unit vector (+-xyz).

Static Public Member Functions

static float Norm (csVector2 const &v)
Return the norm (magnitude) of a 2D vector.
static csVector2 Unit (const csVector2 &v)
Normalizes a vector to a unit vector.

Public Attributes

float x
X component of vector.
float y
Y component of vector.

Friends

bool operator!= (const csVector2 &v1, const csVector2 &v2)
Check if two vectors are not equal.
csVector2 operator* (float f, const csVector2 &v)
Multiply a vector and a scalar.
csVector2 operator* (const csVector2 &v, float f)
Multiply a vector and a scalar.
float operator* (const csVector2 &v1, const csVector2 &v2)
Take the dot product of two vectors.
csVector2 operator+ (const csVector2 &v1, const csVector2 &v2)
csVector2 operator- (const csVector2 &v1, const csVector2 &v2)
Subtract two vectors.
csVector2 operator/ (const csVector2 &v, float f)
Divide a vector by a scalar.
bool operator< (const csVector2 &v, float f)
Test if each component of a vector is less than a small epsilon value.
bool operator== (const csVector2 &v1, const csVector2 &v2)
Check if two vectors are equal.
bool operator> (float f, const csVector2 &v)
Test if each component of a vector is greater than a small epsilon value.

Detailed Description

A 2D vector.

Definition at line 38 of file vector2.h.

Constructor & Destructor Documentation

 csVector2::csVector2 ( ) ` [inline]`

Make a new vector. No initialization is done.

Definition at line 47 of file vector2.h.

 csVector2::csVector2 ( float v ) ` [inline]`

Make a new vector and initialize with the given values.

Definition at line 50 of file vector2.h.

 csVector2::csVector2 ( float x, float y ) ` [inline]`

Make a new vector and initialize with the given values.

Definition at line 55 of file vector2.h.

 csVector2::csVector2 ( const csVector2 & o ) ` [inline]`

Copyconstructor.

Definition at line 60 of file vector2.h.

Member Function Documentation

 csString csVector2::Description ( ) const

Return a textual representation of the vector in the form "x,y".

 void csVector2::Get ( float * v ) ` [inline]`

Get the value of this vector.

Definition at line 82 of file vector2.h.

 float csVector2::InverseNorm ( ) const` [inline]`

Return the inverse norm (1/Norm()) (magnitude) of this vector.

Definition at line 93 of file vector2.h.

 float csVector2::IsLeft ( const csVector2 & p0, const csVector2 & p1 ) ` [inline]`

Test if this point is left of the line through p0 and p1.

Returns:
>0 if this point is left, 0 if on the line and <0 if right.

Definition at line 147 of file vector2.h.

 bool csVector2::IsZero ( float precision = `SMALL_EPSILON` ) const` [inline]`

Query if the vector is zero.

Definition at line 119 of file vector2.h.

 float csVector2::Norm ( ) const` [inline]`

Return the norm (magnitude) of this vector.

Definition at line 89 of file vector2.h.

 static float csVector2::Norm ( csVector2 const & v ) ` [inline, static]`

Return the norm (magnitude) of a 2D vector.

Definition at line 85 of file vector2.h.

 void csVector2::Normalize ( ) ` [inline]`

Scale this vector to length = 1.0;.

Definition at line 109 of file vector2.h.

 csVector2& csVector2::operator*= ( float f ) ` [inline]`

Multiply this vector by a scalar.

Definition at line 161 of file vector2.h.

 csVector2 csVector2::operator+ ( ) const` [inline]`

Unary + operator.

Definition at line 174 of file vector2.h.

 csVector2& csVector2::operator+= ( const csVector2 & v ) ` [inline]`

Add another vector to this vector.

Definition at line 153 of file vector2.h.

 csVector2 csVector2::operator- ( ) const` [inline]`

Unary - operator.

Definition at line 178 of file vector2.h.

 csVector2& csVector2::operator-= ( const csVector2 & v ) ` [inline]`

Subtract another vector from this vector.

Definition at line 157 of file vector2.h.

 csVector2& csVector2::operator/= ( float f ) ` [inline]`

Divide this vector by a scalar.

Definition at line 165 of file vector2.h.

 float& csVector2::operator[] ( int n ) ` [inline]`

Returns n-th component of the vector.

Definition at line 229 of file vector2.h.

 float csVector2::operator[] ( int n ) const` [inline]`

Returns n-th component of the vector.

Definition at line 225 of file vector2.h.

 void csVector2::Rotate ( float angle )

Rotate vector around the origin by a given angle in radians.

 void csVector2::Set ( float v ) ` [inline]`

Set the value of this vector so that all components are the same.

Definition at line 79 of file vector2.h.

 void csVector2::Set ( float const * v ) ` [inline]`

Set the value of this vector.

Definition at line 76 of file vector2.h.

 void csVector2::Set ( csVector2 const & v ) ` [inline]`

Set vector to given values.

Definition at line 72 of file vector2.h.

 void csVector2::Set ( float ix, float iy ) ` [inline]`

Set vector to given values.

Definition at line 68 of file vector2.h.

 float csVector2::SquaredNorm ( ) const` [inline]`

Return the squared norm (magnitude) of this vector.

Definition at line 137 of file vector2.h.

 csVector2 csVector2::Unit ( ) const` [inline]`

Returns the unit vector in the direction of this vector.

Attempting to normalize a zero-vector will result in a divide by zero error. This is as it should be... fix the calling code.

Definition at line 105 of file vector2.h.

 static csVector2 csVector2::Unit ( const csVector2 & v ) ` [inline, static]`

Normalizes a vector to a unit vector.

Definition at line 97 of file vector2.h.

 csVector2 csVector2::UnitAxisClamped ( ) const` [inline]`

Return a version of the vector clamped to closest unit vector (+-xyz).

Definition at line 125 of file vector2.h.

Friends And Related Function Documentation

 bool operator!= ( const csVector2 & v1, const csVector2 & v2 ) ` [friend]`

Check if two vectors are not equal.

Definition at line 213 of file vector2.h.

 csVector2 operator* ( float f, const csVector2 & v ) ` [friend]`

Multiply a vector and a scalar.

Definition at line 198 of file vector2.h.

 csVector2 operator* ( const csVector2 & v, float f ) ` [friend]`

Multiply a vector and a scalar.

Definition at line 194 of file vector2.h.

 float operator* ( const csVector2 & v1, const csVector2 & v2 ) ` [friend]`

Take the dot product of two vectors.

Definition at line 190 of file vector2.h.

 csVector2 operator+ ( const csVector2 & v1, const csVector2 & v2 ) ` [friend]`

Definition at line 182 of file vector2.h.

 csVector2 operator- ( const csVector2 & v1, const csVector2 & v2 ) ` [friend]`

Subtract two vectors.

Definition at line 186 of file vector2.h.

 csVector2 operator/ ( const csVector2 & v, float f ) ` [friend]`

Divide a vector by a scalar.

Definition at line 202 of file vector2.h.

 bool operator< ( const csVector2 & v, float f ) ` [friend]`

Test if each component of a vector is less than a small epsilon value.

Definition at line 217 of file vector2.h.

 bool operator== ( const csVector2 & v1, const csVector2 & v2 ) ` [friend]`

Check if two vectors are equal.

Definition at line 209 of file vector2.h.

 bool operator> ( float f, const csVector2 & v ) ` [friend]`

Test if each component of a vector is greater than a small epsilon value.

Definition at line 221 of file vector2.h.

Member Data Documentation

 float csVector2::x

X component of vector.

Definition at line 42 of file vector2.h.

 float csVector2::y

Y component of vector.

Definition at line 44 of file vector2.h.

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

Generated for Crystal Space 2.0 by doxygen 1.6.1