#pragma once #include #include struct Vector2Options { int32_t x; int32_t y; }; /** * A 2D Vector. */ class Vector2 { public: using Value = int32_t; constexpr explicit Vector2(const Vector2Options &options) noexcept : _x(options.x), _y(options.y) { } [[nodiscard]] Value get_x() const noexcept; void set_x(Value x) noexcept; [[nodiscard]] Value get_y() const noexcept; void set_y(Value y) noexcept; [[nodiscard]] Vector2 to_direction(const Vector2 &direction, Vector2::Value amount) const noexcept; const Vector2 &operator+=(const Vector2 &vector2) noexcept; const Vector2 &operator-=(const Vector2 &vector2) noexcept; Vector2 operator+(const Vector2 &vector2) const noexcept; Vector2 operator-(const Vector2 &vector2) const noexcept; Vector2 operator*(const Vector2 &vector2) const noexcept; bool operator==(const Vector2 &vector2) const noexcept; /** * Returns Vector2({.x = 0, .y = -1}) */ static constexpr Vector2 up() noexcept { return Vector2({.x = 0, .y = -1}); } /** * Returns Vector2({.x = 0, .y = 1}) */ static constexpr Vector2 down() noexcept { return Vector2({.x = 0, .y = 1}); } /** * Returns Vector2({.x = -1, .y = 0}) */ static constexpr Vector2 left() noexcept { return Vector2({.x = -1, .y = 0}); } /** * Returns Vector2({.x = 1, .y = 0}) */ static constexpr Vector2 right() noexcept { return Vector2({.x = 1, .y = 0}); } private: Value _x; Value _y; }; class Vector2Hasher { public: std::size_t operator()(const Vector2 &vector2) const noexcept; };