diff --git a/src/helpers/Vector2D.cpp b/src/helpers/Vector2D.cpp new file mode 100644 index 00000000..33b12e7c --- /dev/null +++ b/src/helpers/Vector2D.cpp @@ -0,0 +1,19 @@ +#include "Vector2D.hpp" + +Vector2D::Vector2D(double xx, double yy) { + x = xx; + y = yy; +} + +Vector2D::Vector2D() { x = 0; y = 0; } +Vector2D::~Vector2D() {} + +double Vector2D::normalize() { + // get max abs + const auto max = abs(x) > abs(y) ? abs(x) : abs(y); + + x /= max; + y /= max; + + return max; +} \ No newline at end of file diff --git a/src/helpers/Vector2D.hpp b/src/helpers/Vector2D.hpp new file mode 100644 index 00000000..9bc427e8 --- /dev/null +++ b/src/helpers/Vector2D.hpp @@ -0,0 +1,29 @@ +#pragma once + +#include + +class Vector2D { + public: + Vector2D(double, double); + Vector2D(); + ~Vector2D(); + + double x = 0; + double y = 0; + + // returns the scale + double normalize(); + + Vector2D operator+(Vector2D a) { + return Vector2D(this->x + a.x, this->y + a.y); + } + Vector2D operator-(Vector2D a) { + return Vector2D(this->x - a.x, this->y - a.y); + } + Vector2D operator*(float a) { + return Vector2D(this->x * a, this->y * a); + } + Vector2D operator/(float a) { + return Vector2D(this->x / a, this->y / a); + } +}; \ No newline at end of file diff --git a/src/includes.hpp b/src/includes.hpp index d2f49181..352286d4 100644 --- a/src/includes.hpp +++ b/src/includes.hpp @@ -65,4 +65,6 @@ extern "C" { #undef namespace #undef static -#endif \ No newline at end of file +#endif + +#include "helpers/Vector2D.hpp"