diff options
author | HampusM <hampus@hampusmat.com> | 2022-07-01 17:27:49 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-07-01 17:27:49 +0200 |
commit | 578cf43e9c8384aab463aa2a33c5be00e46dc999 (patch) | |
tree | 927262a92b7ff0365463327130de78722578aa03 | |
parent | ae15df6689b1245200f8a9eb074c59a200561e49 (diff) |
refactor: matrix add get_size method
-rw-r--r-- | src/engine/graphics/matrix.hpp | 2 | ||||
-rw-r--r-- | src/engine/graphics/matrix_impl.hpp | 6 | ||||
-rw-r--r-- | src/game/cell_helper_impl.hpp | 3 | ||||
-rw-r--r-- | src/interfaces/matrix.hpp | 9 | ||||
-rw-r--r-- | 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<Element> override; [[nodiscard]] auto end() const noexcept -> MatrixIterator<Element> 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 @@ -82,6 +82,12 @@ auto Matrix<Element>::get_column_cnt() const noexcept -> std::uint32_t } template <typename Element> +auto Matrix<Element>::get_size() const noexcept -> Bounds +{ + return Bounds({.width = _column_cnt, .height = _row_cnt}); +} + +template <typename Element> auto Matrix<Element>::begin() const noexcept -> MatrixIterator<Element> { return MatrixIterator(_matrix, _column_cnt); 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<MatrixElement>::_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 <memory> +#include <yacppdic/factory.hpp> + #include "engine/data/bounds.hpp" #include "engine/data/vector2.hpp" #include "engine/graphics/matrix_iterator.hpp" -#include <yacppdic/factory.hpp> - -#include <memory> - template <typename ElementType> // 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<Element> = 0; [[nodiscard]] virtual auto end() const noexcept -> MatrixIterator<Element> = 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 <trompeloeil.hpp> +#include "engine/data/bounds.hpp" +#include "interfaces/matrix.hpp" + template <typename Element> class MockMatrix : public IMatrix<Element> { @@ -24,6 +25,9 @@ public: 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<Element>(), const noexcept override); // NOLINTNEXTLINE(modernize-use-trailing-return-type) |