cee::Vec2f

class Vec2f

Vector class for a 2D float vector.

Public Functions

Vec2f()

Constructs a null vector.

Vec2f(const Vec2f &other)

Constructs a vector as a copy of other.

Vec2f(float x, float y)

Constructs a vector from an x and y coordinate.

Vec2f &operator=(const Vec2f &other)

Assigns other to this vector and returns a reference to this vector.

bool operator==(const Vec2f &rhs) const

Returns true if two vectors are equal, otherwise returns false.

An exact match is required x() == rhs.x(), etc.

bool operator!=(const Vec2f &rhs) const

Returns true if two vectors are not equal, otherwise returns false.

Exact comparison is used (!= between floats)

const Vec2f operator+(const Vec2f &rhs) const

Returns a vector that is this vector added with rhs.

const Vec2f operator-(const Vec2f &rhs) const

Returns a vector that is this vector subtracted with rhs.

const Vec2f operator*(float scalar) const

Returns a vector that is this vector multiplies with scalar.

const Vec2f operator/(float scalar) const

Returns a vector that is this vector divided with scalar.

Vec2f &operator+=(const Vec2f &rhs)

Adds the given rhs vector to this.

Vec2f &operator-=(const Vec2f &rhs)

Subtracts the given rhs vector from this.

Vec2f &operator*=(float scalar)

Multiplies every components of this vector with the given scalar.

Vec2f &operator/=(float scalar)

Divides every components of this vector with the given scalar.

float operator*(const Vec2f &rhs) const

Computes the dot product of this and rhs and return the result (scalar)

Formula:

S = this.x*rhs.x + this.y*rhs.y

const float &x() const

X element of the vector.

const float &y() const

Y element of the vector.

float &x()

X element of the vector.

float &y()

Y element of the vector.

void set(float x, float y)

Sets x and y value.

bool normalize()

Normalizes this vector.

Returns false if the vector is a null vector. Otherwise returns true.

float length() const

Returns the length of this vector.

Public Static Functions

static float dot(const Vec2f &v1, const Vec2f &v2)

Returns the dot product of v1 and v2.

Formula:

S = v1.x*v2.x + v1.y*v2.y