diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2023-09-14 20:07:16 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-09-14 20:07:16 +0200 |
commit | 303726c2e41d5e1bd3d18f82489646cc11ff902c (patch) | |
tree | a488d047880880130039e15b3c482cbb53d6a9bd | |
parent | 2d422fc0e46ff8719c6b965ff94e08e010784c7e (diff) |
src: convert from vector to local_coords
-rw-r--r-- | src/local-coords.hpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/local-coords.hpp b/src/local-coords.hpp index 34aa09f1..70b7a62d 100644 --- a/src/local-coords.hpp +++ b/src/local-coords.hpp @@ -12,11 +12,17 @@ namespace floormat { struct local_coords final { uint8_t x : 4 = 0, y : 4 = 0; + explicit constexpr local_coords(size_t idx) noexcept; constexpr local_coords() noexcept = default; + constexpr local_coords(uint8_t x, uint8_t y) noexcept : x{x}, y{y} {} + template<typename T> requires (std::is_integral_v<T> && sizeof(T) <= sizeof(size_t)) constexpr local_coords(T x, T y) noexcept; - constexpr local_coords(uint8_t x, uint8_t y) noexcept : x{x}, y{y} {} + + template<typename T> requires requires (const Math::Vector2<T>& vec) { local_coords{vec.x(), vec.y()}; } + constexpr local_coords(Math::Vector2<T> vec) noexcept : local_coords{vec.x(), vec.y()} {} + constexpr uint8_t to_index() const noexcept { return y*TILE_MAX_DIM + x; } constexpr bool operator==(const local_coords&) const noexcept = default; |