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