Vector class for a 2D float vector. More...
Public Member Functions | |
Vec2f () | |
Constructs a null vector. More... | |
Vec2f (const Vec2f &other) | |
Constructs a vector as a copy of other. More... | |
Vec2f (float x, float y) | |
Constructs a vector from an x and y coordinate. More... | |
Vec2f & | operator= (const Vec2f &other) |
Assigns other to this vector and returns a reference to this vector. More... | |
bool | operator== (const Vec2f &rhs) const |
Returns true if two vectors are equal, otherwise returns false. More... | |
bool | operator!= (const Vec2f &rhs) const |
Returns true if two vectors are not equal, otherwise returns false. More... | |
const Vec2f | operator+ (const Vec2f &rhs) const |
Returns a vector that is this vector added with rhs. More... | |
const Vec2f | operator- (const Vec2f &rhs) const |
Returns a vector that is this vector subtracted with rhs. More... | |
const Vec2f | operator* (float scalar) const |
Returns a vector that is this vector multiplies with scalar. More... | |
const Vec2f | operator/ (float scalar) const |
Returns a vector that is this vector divided with scalar. More... | |
Vec2f & | operator+= (const Vec2f &rhs) |
Adds the given rhs vector to this. More... | |
Vec2f & | operator-= (const Vec2f &rhs) |
Subtracts the given rhs vector from this. More... | |
Vec2f & | operator*= (float scalar) |
Multiplies every components of this vector with the given scalar. More... | |
Vec2f & | operator/= (float scalar) |
Divides every components of this vector with the given scalar. More... | |
float | operator* (const Vec2f &rhs) const |
Computes the dot product of this and rhs and return the result (scalar) More... | |
const float & | x () const |
X element of the vector. More... | |
const float & | y () const |
Y element of the vector. More... | |
float & | x () |
X element of the vector. More... | |
float & | y () |
Y element of the vector. More... | |
void | set (float x, float y) |
Sets x and y value. More... | |
bool | normalize () |
Normalizes this vector. More... | |
float | length () const |
Returns the length of this vector. More... | |
Static Public Member Functions | |
static float | dot (const Vec2f &v1, const Vec2f &v2) |
Returns the dot product of v1 and v2. More... | |
Vector class for a 2D float vector.
cee::Vec2f::Vec2f | ( | ) |
Constructs a null vector.
cee::Vec2f::Vec2f | ( | const Vec2f & | other | ) |
Constructs a vector as a copy of other.
cee::Vec2f::Vec2f | ( | float | x, |
float | y | ||
) |
Constructs a vector from an x and y coordinate.
Returns the dot product of v1 and v2.
Formula:
float cee::Vec2f::length | ( | ) | const |
Returns the length of this vector.
bool cee::Vec2f::normalize | ( | ) |
Normalizes this vector.
Returns false if the vector is a null vector. Otherwise returns true.
bool cee::Vec2f::operator!= | ( | const Vec2f & | rhs | ) | const |
Returns true if two vectors are not equal, otherwise returns false.
Exact comparison is used (!= between floats)
const Vec2f cee::Vec2f::operator* | ( | float | scalar | ) | const |
Returns a vector that is this vector multiplies with scalar.
float cee::Vec2f::operator* | ( | const Vec2f & | rhs | ) | const |
Vec2f & cee::Vec2f::operator*= | ( | float | scalar | ) |
Multiplies every components of this vector with the given scalar.
Returns a vector that is this vector added with rhs.
cee::Vec2f & cee::Vec2f::operator+= | ( | const Vec2f & | rhs | ) |
Adds the given rhs vector to this.
Returns a vector that is this vector subtracted with rhs.
cee::Vec2f & cee::Vec2f::operator-= | ( | const Vec2f & | rhs | ) |
Subtracts the given rhs vector from this.
const Vec2f cee::Vec2f::operator/ | ( | float | scalar | ) | const |
Returns a vector that is this vector divided with scalar.
Vec2f & cee::Vec2f::operator/= | ( | float | scalar | ) |
Divides every components of this vector with the given scalar.
Assigns other to this vector and returns a reference to this vector.
bool cee::Vec2f::operator== | ( | const Vec2f & | rhs | ) | const |
Returns true if two vectors are equal, otherwise returns false.
An exact match is required x() == rhs.x(), etc.
void cee::Vec2f::set | ( | float | x, |
float | y | ||
) |
Sets x and y value.
const float & cee::Vec2f::x | ( | ) | const |
X element of the vector.
float & cee::Vec2f::x | ( | ) |
X element of the vector.
const float & cee::Vec2f::y | ( | ) | const |
Y element of the vector.
float & cee::Vec2f::y | ( | ) |
Y element of the vector.