From 303726c2e41d5e1bd3d18f82489646cc11ff902c Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Thu, 14 Sep 2023 20:07:16 +0200 Subject: src: convert from vector to local_coords --- src/local-coords.hpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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 requires (std::is_integral_v && 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 requires requires (const Math::Vector2& vec) { local_coords{vec.x(), vec.y()}; } + constexpr local_coords(Math::Vector2 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; -- cgit v1.2.3