#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]] auto get_x() const noexcept -> Value; void set_x(Value x) noexcept; [[nodiscard]] auto get_y() const noexcept -> Value; void set_y(Value y) noexcept; [[nodiscard]] auto to_direction(const Vector2 &direction, Vector2::Value amount) const noexcept -> Vector2; auto operator+=(const Vector2 &rhs) noexcept -> const Vector2 &; auto operator-=(const Vector2 &rhs) noexcept -> const Vector2 &; auto operator+(const Vector2 &rhs) const noexcept -> Vector2; auto operator-(const Vector2 &rhs) const noexcept -> Vector2; auto operator*(const Vector2 &rhs) const noexcept -> Vector2; auto operator==(const Vector2 &rhs) const noexcept -> bool; /** * Returns Vector2({.x = 0, .y = 1}) */ static constexpr auto up() noexcept -> Vector2 { return Vector2({.x = 0, .y = 1}); } /** * Returns Vector2({.x = 0, .y = -1}) */ static constexpr auto down() noexcept -> Vector2 { return Vector2({.x = 0, .y = -1}); } /** * Returns Vector2({.x = -1, .y = 0}) */ static constexpr auto left() noexcept -> Vector2 { return Vector2({.x = -1, .y = 0}); } /** * Returns Vector2({.x = 1, .y = 0}) */ static constexpr auto right() noexcept -> Vector2 { return Vector2({.x = 1, .y = 0}); } private: Value _x; Value _y; }; class Vector2Hasher { public: auto operator()(const Vector2 &vector2) const noexcept -> std::size_t; };