Maze Builder Docs 8.8.13
Loading...
Searching...
No Matches
grid_operations.h
Go to the documentation of this file.
1#ifndef GRID_OPERATIONS_H
2#define GRID_OPERATIONS_H
3
5#include <MazeBuilder/cell.h>
6
7#include <cstdint>
8#include <array>
9#include <iterator>
10#include <memory>
11#include <span>
12#include <tuple>
13#include <vector>
14
17namespace mazes
18{
22 {
23 public:
27 [[nodiscard]]
28 static bool is_valid_ops(const grid_operations *ops) noexcept
29 {
30 return ops != nullptr;
31 }
32
34 virtual ~grid_operations() = default;
35
38 [[nodiscard]] virtual std::tuple<std::uint32_t, std::uint32_t, std::uint32_t> get_dimensions() const noexcept = 0;
39
44 [[nodiscard]] virtual std::shared_ptr<cell> get_neighbor(std::shared_ptr<cell> const &c,
45 Direction dir) const noexcept = 0;
46
48 static constexpr std::size_t MAX_NEIGHBORS = 4;
49
51 using neighbor_buffer = std::array<std::shared_ptr<cell>, MAX_NEIGHBORS>;
52
57 [[nodiscard]] virtual std::size_t collect_neighbors(std::shared_ptr<cell> const &c,
58 std::span<std::shared_ptr<cell>, MAX_NEIGHBORS> out) const noexcept = 0;
59
62 [[deprecated("use collect_neighbors(c, buffer), which does not allocate")]] [[nodiscard]]
63 std::vector<std::shared_ptr<cell>> collect_neighbors(std::shared_ptr<cell> const &c) const noexcept
64 {
66 const auto n = collect_neighbors(c, std::span<std::shared_ptr<cell>, MAX_NEIGHBORS>{buf});
67 return {std::make_move_iterator(buf.begin()), std::make_move_iterator(buf.begin() + n)};
68 }
69
72 [[nodiscard]] virtual std::span<const std::shared_ptr<cell>> cells() const noexcept = 0;
73
79 virtual void set_neighbor(const std::shared_ptr<cell> &c, Direction dir,
80 std::shared_ptr<cell> const &neighbor) noexcept = 0;
81
82 // Convenience methods for accessing neighbors
83 [[nodiscard]] virtual std::shared_ptr<cell> get_north(const std::shared_ptr<cell> &c) const noexcept = 0;
84 [[nodiscard]] virtual std::shared_ptr<cell> get_south(const std::shared_ptr<cell> &c) const noexcept = 0;
85 [[nodiscard]] virtual std::shared_ptr<cell> get_east(const std::shared_ptr<cell> &c) const noexcept = 0;
86 [[nodiscard]] virtual std::shared_ptr<cell> get_west(const std::shared_ptr<cell> &c) const noexcept = 0;
87
91 [[nodiscard]] virtual std::shared_ptr<cell> search(int index) const noexcept = 0;
92
95 [[nodiscard]] virtual std::size_t num_cells() const noexcept = 0;
96
99 [[nodiscard]] virtual std::vector<std::tuple<std::int32_t, std::int32_t, std::int32_t, std::int32_t>>
100 get_vertices() const noexcept = 0;
101
104 virtual void set_vertices(
105 const std::vector<std::tuple<std::int32_t, std::int32_t, std::int32_t, std::int32_t>> &vertices) noexcept = 0;
106
109 [[nodiscard]] virtual std::vector<std::vector<std::uint32_t>> get_faces() const noexcept = 0;
110
113 virtual void set_faces(const std::vector<std::vector<std::uint32_t>> &faces) noexcept = 0;
114
117 [[nodiscard]] virtual std::vector<std::uint8_t> get_pixels() const noexcept = 0;
118
121 virtual void set_pixels(const std::vector<std::uint8_t> &pixels) noexcept = 0;
122
125 virtual void resize(std::uint32_t rows, std::uint32_t cols, std::uint32_t levels) noexcept = 0;
126 };
127} // namespace mazes
128
129#endif // GRID_OPERATIONS_H
Direction
Directional neighbors for grid topology.
Definition barriers.h:30
Cell class with links to other cells.
Definition cell.h:18
Interface for grid navigation and manipulation operations.
Definition grid_operations.h:22
virtual std::size_t collect_neighbors(std::shared_ptr< cell > const &c, std::span< std::shared_ptr< cell >, MAX_NEIGHBORS > out) const noexcept=0
Fill a caller-provided buffer with the neighbors of a cell, avoiding allocation.
static bool is_valid_ops(const grid_operations *ops) noexcept
Checks for nullity.
Definition grid_operations.h:28
virtual std::vector< std::uint8_t > get_pixels() const noexcept=0
Get the pixel data for image generation.
static constexpr std::size_t MAX_NEIGHBORS
Maximum number of neighbors a cell can have.
Definition grid_operations.h:48
virtual void set_pixels(const std::vector< std::uint8_t > &pixels) noexcept=0
Set the pixel data for image generation.
virtual std::shared_ptr< cell > get_neighbor(std::shared_ptr< cell > const &c, Direction dir) const noexcept=0
Get neighbor by the cell's respective location.
virtual std::span< const std::shared_ptr< cell > > cells() const noexcept=0
Zero-copy view of all cells, in index order (level-major, then row, then column).
virtual void resize(std::uint32_t rows, std::uint32_t cols, std::uint32_t levels) noexcept=0
Resize the grid to new dimensions, clearing all existing cells and topology.
virtual std::size_t num_cells() const noexcept=0
Get the count of cells in the grid.
virtual void set_vertices(const std::vector< std::tuple< std::int32_t, std::int32_t, std::int32_t, std::int32_t > > &vertices) noexcept=0
Set the vertices.
virtual std::tuple< std::uint32_t, std::uint32_t, std::uint32_t > get_dimensions() const noexcept=0
Retrieves the dimensions as a tuple of three unsigned integers.
virtual std::vector< std::vector< std::uint32_t > > get_faces() const noexcept=0
Get the faces.
std::array< std::shared_ptr< cell >, MAX_NEIGHBORS > neighbor_buffer
Reusable neighbor buffer type for collect_neighbors.
Definition grid_operations.h:51
virtual std::vector< std::tuple< std::int32_t, std::int32_t, std::int32_t, std::int32_t > > get_vertices() const noexcept=0
Get the vertices.
virtual ~grid_operations()=default
Destroys the grid_operations object and releases any associated resources.
virtual void set_neighbor(const std::shared_ptr< cell > &c, Direction dir, std::shared_ptr< cell > const &neighbor) noexcept=0
Set neighbor for a cell in a given direction.
virtual std::shared_ptr< cell > search(int index) const noexcept=0
Search for a cell by index.
virtual void set_faces(const std::vector< std::vector< std::uint32_t > > &faces) noexcept=0
Set the faces.