aboutsummaryrefslogtreecommitdiff
path: root/src/engine/data
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine/data')
-rw-r--r--src/engine/data/vector2.cpp37
-rw-r--r--src/engine/data/vector2.hpp29
2 files changed, 66 insertions, 0 deletions
diff --git a/src/engine/data/vector2.cpp b/src/engine/data/vector2.cpp
index 6dcd7d6..c182fba 100644
--- a/src/engine/data/vector2.cpp
+++ b/src/engine/data/vector2.cpp
@@ -1,5 +1,7 @@
#include "vector2.hpp"
+#include "util/hash.hpp"
+
Vector2::Vector2(const Vector2Options &options) : _x(options.x), _y(options.y) {}
int32_t Vector2::get_x() const noexcept
@@ -37,3 +39,38 @@ const Vector2 &Vector2::operator-=(const Vector2 &vector2) noexcept
return *this;
}
+
+bool Vector2::operator==(const Vector2 &vector2) const noexcept
+{
+ return _x == vector2._x && _y == vector2._y;
+}
+
+Vector2 Vector2::up()
+{
+ return Vector2({.x = 0, .y = 1});
+}
+
+Vector2 Vector2::down()
+{
+ return Vector2({.x = 0, .y = -1});
+}
+
+Vector2 Vector2::left()
+{
+ return Vector2({.x = -1, .y = 0});
+}
+
+Vector2 Vector2::right()
+{
+ return Vector2({.x = 1, .y = 0});
+}
+
+std::size_t Vector2Hasher::operator()(const Vector2 &vector2) const
+{
+ std::size_t result_hash = 0;
+
+ hash_combine(result_hash, vector2.get_x());
+ hash_combine(result_hash, vector2.get_y());
+
+ return result_hash;
+}
diff --git a/src/engine/data/vector2.hpp b/src/engine/data/vector2.hpp
index acfe11f..dff548c 100644
--- a/src/engine/data/vector2.hpp
+++ b/src/engine/data/vector2.hpp
@@ -1,6 +1,7 @@
#pragma once
#include <cstdint>
+#include <functional>
struct Vector2Options
{
@@ -27,7 +28,35 @@ public:
const Vector2 &operator+=(const Vector2 &vector2) noexcept;
const Vector2 &operator-=(const Vector2 &vector2) noexcept;
+ bool operator==(const Vector2 &vector2) const noexcept;
+
+ /**
+ * Returns Vector2({.x = 0, .y = 1})
+ */
+ static Vector2 up();
+
+ /**
+ * Returns Vector2({.x = 0, .y = -1})
+ */
+ static Vector2 down();
+
+ /**
+ * Returns Vector2({.x = -1, .y = 0})
+ */
+ static Vector2 left();
+
+ /**
+ * Returns Vector2({.x = 1, .y = 0})
+ */
+ static Vector2 right();
+
private:
int32_t _x;
int32_t _y;
};
+
+class Vector2Hasher
+{
+public:
+ std::size_t operator()(const Vector2 &vector2) const;
+};