summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorvaxerski <43317083+vaxerski@users.noreply.github.com>2022-03-16 22:21:12 +0100
committervaxerski <43317083+vaxerski@users.noreply.github.com>2022-03-16 22:21:12 +0100
commit52090853dafb75dd99969a0cecdd291c109210f8 (patch)
tree282fa613a51e24366512723517278ff9f444edb1 /src
parentffd309ca2adc313f2aaaea08b4cac9553982b48c (diff)
added vector2d
Diffstat (limited to 'src')
-rw-r--r--src/helpers/Vector2D.cpp19
-rw-r--r--src/helpers/Vector2D.hpp29
-rw-r--r--src/includes.hpp4
3 files changed, 51 insertions, 1 deletions
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 <math.h>
+
+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"