From 578cf43e9c8384aab463aa2a33c5be00e46dc999 Mon Sep 17 00:00:00 2001 From: HampusM Date: Fri, 1 Jul 2022 17:27:49 +0200 Subject: refactor: matrix add get_size method --- src/engine/graphics/matrix.hpp | 2 ++ src/engine/graphics/matrix_impl.hpp | 6 ++++++ src/game/cell_helper_impl.hpp | 3 +-- src/interfaces/matrix.hpp | 9 +++++---- test/mocks/matrix.hpp | 8 ++++++-- 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/engine/graphics/matrix.hpp b/src/engine/graphics/matrix.hpp index 58905ee..5964f0f 100644 --- a/src/engine/graphics/matrix.hpp +++ b/src/engine/graphics/matrix.hpp @@ -32,6 +32,8 @@ public: [[nodiscard]] auto get_column_cnt() const noexcept -> std::uint32_t override; + [[nodiscard]] auto get_size() const noexcept -> Bounds override; + [[nodiscard]] auto begin() const noexcept -> MatrixIterator override; [[nodiscard]] auto end() const noexcept -> MatrixIterator override; diff --git a/src/engine/graphics/matrix_impl.hpp b/src/engine/graphics/matrix_impl.hpp index 9105149..d2de795 100644 --- a/src/engine/graphics/matrix_impl.hpp +++ b/src/engine/graphics/matrix_impl.hpp @@ -81,6 +81,12 @@ auto Matrix::get_column_cnt() const noexcept -> std::uint32_t return _column_cnt; } +template +auto Matrix::get_size() const noexcept -> Bounds +{ + return Bounds({.width = _column_cnt, .height = _row_cnt}); +} + template auto Matrix::begin() const noexcept -> MatrixIterator { diff --git a/src/game/cell_helper_impl.hpp b/src/game/cell_helper_impl.hpp index e2010fa..2a42f6c 100644 --- a/src/game/cell_helper_impl.hpp +++ b/src/game/cell_helper_impl.hpp @@ -92,8 +92,7 @@ auto CellHelper::_get_valid_pos_neighbours( position + Vector2::down() + Vector2::left(), position + Vector2::down() + Vector2::right()}; - const auto matrix_size = - Bounds({.width = _matrix->get_column_cnt(), .height = _matrix->get_row_cnt()}); + const auto matrix_size = _matrix->get_size(); return neighbours | ranges::views::filter( diff --git a/src/interfaces/matrix.hpp b/src/interfaces/matrix.hpp index 8edad80..6a6966e 100644 --- a/src/interfaces/matrix.hpp +++ b/src/interfaces/matrix.hpp @@ -1,13 +1,12 @@ #pragma once +#include +#include + #include "engine/data/bounds.hpp" #include "engine/data/vector2.hpp" #include "engine/graphics/matrix_iterator.hpp" -#include - -#include - template // NOLINTNEXTLINE(cppcoreguidelines-special-member-functions) class IMatrix @@ -27,6 +26,8 @@ public: [[nodiscard]] virtual auto get_column_cnt() const noexcept -> std::uint32_t = 0; + [[nodiscard]] virtual auto get_size() const noexcept -> Bounds = 0; + [[nodiscard]] virtual auto begin() const noexcept -> MatrixIterator = 0; [[nodiscard]] virtual auto end() const noexcept -> MatrixIterator = 0; diff --git a/test/mocks/matrix.hpp b/test/mocks/matrix.hpp index 4b193b2..d1110f2 100644 --- a/test/mocks/matrix.hpp +++ b/test/mocks/matrix.hpp @@ -1,9 +1,10 @@ #pragma once -#include "interfaces/matrix.hpp" - #include +#include "engine/data/bounds.hpp" +#include "interfaces/matrix.hpp" + template class MockMatrix : public IMatrix { @@ -23,6 +24,9 @@ public: // NOLINTNEXTLINE(modernize-use-trailing-return-type) MAKE_MOCK0(get_column_cnt, uint32_t(), const noexcept override); + // NOLINTNEXTLINE(modernize-use-trailing-return-type) + MAKE_MOCK0(get_size, Bounds(), const noexcept override); + // NOLINTNEXTLINE(modernize-use-trailing-return-type) MAKE_MOCK0(begin, MatrixIterator(), const noexcept override); -- cgit v1.2.3-18-g5258