cee::Vec2d

class Vec2d

Vector class for a 2D double vector.

Public Functions

Vec2d()

Constructs a null vector.

Vec2d(const Vec2d &other)

Constructs a vector as a copy of other.

Vec2d(double x, double y)

Constructs a vector from an x and y coordinate.

Vec2d &operator=(const Vec2d &other)

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

bool operator==(const Vec2d &rhs) const

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

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

bool operator!=(const Vec2d &rhs) const

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

Exact comparison is used (!= between doubles)

const Vec2d operator+(const Vec2d &rhs) const

Returns a vector that is this vector added with rhs.

const Vec2d operator-(const Vec2d &rhs) const

Returns a vector that is this vector subtracted with rhs.

const Vec2d operator*(double scalar) const

Returns a vector that is this vector multiplies with scalar.

const Vec2d operator/(double scalar) const

Returns a vector that is this vector divided with scalar.

Vec2d &operator+=(const Vec2d &rhs)

Adds the given rhs vector to this.

Vec2d &operator-=(const Vec2d &rhs)

Subtracts the given rhs vector from this.

Vec2d &operator*=(double scalar)

Multiplies every components of this vector with the given scalar.

Vec2d &operator/=(double scalar)

Divides every components of this vector with the given scalar.

double operator*(const Vec2d &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 double &x() const

X element of the vector.

const double &y() const

Y element of the vector.

double &x()

X element of the vector.

double &y()

Y element of the vector.

void set(double x, double y)

Sets x and y value.

bool normalize()

Normalizes this vector.

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

double length() const

Returns the length of this vector.

Public Static Functions

static double dot(const Vec2d &v1, const Vec2d &v2)

Returns the dot product of v1 and v2.

Formula:

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