aboutsummaryrefslogtreecommitdiff
path: root/src/engine/data
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-03-08 16:20:41 +0100
committerHampusM <hampus@hampusmat.com>2022-06-13 17:56:55 +0200
commit3a24ec6e5b5236ad6b943548b9948603e053559d (patch)
tree31d788193e10bc325f1ffa1aa140670f02847e05 /src/engine/data
parentf0824fdebc79fbf3843c2053522107c33e3ce2a3 (diff)
refactor: improve vector2 data type & methods
Diffstat (limited to 'src/engine/data')
-rw-r--r--src/engine/data/vector2.cpp18
-rw-r--r--src/engine/data/vector2.hpp24
2 files changed, 22 insertions, 20 deletions
diff --git a/src/engine/data/vector2.cpp b/src/engine/data/vector2.cpp
index c182fba..f91afa8 100644
--- a/src/engine/data/vector2.cpp
+++ b/src/engine/data/vector2.cpp
@@ -4,22 +4,22 @@
Vector2::Vector2(const Vector2Options &options) : _x(options.x), _y(options.y) {}
-int32_t Vector2::get_x() const noexcept
+Vector2::Value Vector2::get_x() const noexcept
{
return _x;
}
-void Vector2::set_x(int32_t x) noexcept
+void Vector2::set_x(Vector2::Value x) noexcept
{
_x = x;
}
-int32_t Vector2::get_y() const noexcept
+Vector2::Value Vector2::get_y() const noexcept
{
return _y;
}
-void Vector2::set_y(int32_t y) noexcept
+void Vector2::set_y(Vector2::Value y) noexcept
{
_y = y;
}
@@ -45,27 +45,27 @@ bool Vector2::operator==(const Vector2 &vector2) const noexcept
return _x == vector2._x && _y == vector2._y;
}
-Vector2 Vector2::up()
+Vector2 Vector2::up() noexcept
{
return Vector2({.x = 0, .y = 1});
}
-Vector2 Vector2::down()
+Vector2 Vector2::down() noexcept
{
return Vector2({.x = 0, .y = -1});
}
-Vector2 Vector2::left()
+Vector2 Vector2::left() noexcept
{
return Vector2({.x = -1, .y = 0});
}
-Vector2 Vector2::right()
+Vector2 Vector2::right() noexcept
{
return Vector2({.x = 1, .y = 0});
}
-std::size_t Vector2Hasher::operator()(const Vector2 &vector2) const
+std::size_t Vector2Hasher::operator()(const Vector2 &vector2) const noexcept
{
std::size_t result_hash = 0;
diff --git a/src/engine/data/vector2.hpp b/src/engine/data/vector2.hpp
index dff548c..49e5d85 100644
--- a/src/engine/data/vector2.hpp
+++ b/src/engine/data/vector2.hpp
@@ -15,15 +15,17 @@ struct Vector2Options
class Vector2
{
public:
+ using Value = int32_t;
+
explicit Vector2(const Vector2Options &options);
- [[nodiscard]] int32_t get_x() const noexcept;
+ [[nodiscard]] Value get_x() const noexcept;
- void set_x(int32_t x) noexcept;
+ void set_x(Value x) noexcept;
- [[nodiscard]] int32_t get_y() const noexcept;
+ [[nodiscard]] Value get_y() const noexcept;
- void set_y(int32_t y) noexcept;
+ void set_y(Value y) noexcept;
const Vector2 &operator+=(const Vector2 &vector2) noexcept;
const Vector2 &operator-=(const Vector2 &vector2) noexcept;
@@ -33,30 +35,30 @@ public:
/**
* Returns Vector2({.x = 0, .y = 1})
*/
- static Vector2 up();
+ static Vector2 up() noexcept;
/**
* Returns Vector2({.x = 0, .y = -1})
*/
- static Vector2 down();
+ static Vector2 down() noexcept;
/**
* Returns Vector2({.x = -1, .y = 0})
*/
- static Vector2 left();
+ static Vector2 left() noexcept;
/**
* Returns Vector2({.x = 1, .y = 0})
*/
- static Vector2 right();
+ static Vector2 right() noexcept;
private:
- int32_t _x;
- int32_t _y;
+ Value _x;
+ Value _y;
};
class Vector2Hasher
{
public:
- std::size_t operator()(const Vector2 &vector2) const;
+ std::size_t operator()(const Vector2 &vector2) const noexcept;
};