diff options
Diffstat (limited to 'kue/vector.h')
-rw-r--r-- | kue/vector.h | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/kue/vector.h b/kue/vector.h new file mode 100644 index 00000000..f1a0947a --- /dev/null +++ b/kue/vector.h @@ -0,0 +1,65 @@ +#ifndef _VECTOR_H +#define _VECTOR_H + +#include <math.h> +#include "point.h" + +// Implements a vector in 2D +class vector { + public: + // Normal constructors + vector(double magnitude, double direction) { _magnitude = magnitude; _direction = direction; } + vector(const point& source, const point& dest); + vector(); + + // Copy constructor + vector(const vector&); + + // Accessors, sorta + double componentX() const { return (_magnitude * cos(_direction)); }; + double componentY() const { return (_magnitude * sin(_direction)); }; + + // Sets individual components + // Wrappers around setComponents(double, double) - below + void setComponentX(double x); + void setComponentY(double y); + + // Sets both components at once + void setComponents(double x, double y); + + // Accessors + double magnitude() const { return _magnitude; } + double direction() const { return _direction; } + void setMagnitude(double m) { _magnitude = m; } + void setDirection(double d) { _direction = d; } + + // Vector math + vector operator+(const vector&); + vector operator-(const vector&); + + vector& operator+=(const vector&); + vector& operator-=(const vector&); + + // Dot product + double operator*(const vector&); + + // Magnitude math + vector operator+(double m) { return vector(_magnitude + m, _direction); } + vector operator-(double m) { return vector(_magnitude - m, _direction); } + vector operator*(double m) { return vector(_magnitude * m, _direction); } + vector operator/(double m) { return vector(_magnitude / m, _direction); } + + vector& operator+=(double m); + vector& operator-=(double m); + vector& operator*=(double m); + vector& operator/=(double m); + + // Return the vector's equalivent on the unit circle + vector unit() const { return vector(1.0, _direction); } + + protected: + double _magnitude; + double _direction; +}; + +#endif |