Maze Builder Docs 8.8.13
Loading...
Searching...
No Matches
mazes::masked_grid Class Reference

A grid that restricts cell availability based on a boolean mask. More...

#include <masked_grid.h>

Inheritance diagram for mazes::masked_grid:
[legend]
Collaboration diagram for mazes::masked_grid:
[legend]

Public Member Functions

 masked_grid (unsigned int width=1u, unsigned int length=1u, unsigned int height=1u)
 Constructs a masked grid with specified dimensions.
 masked_grid (mask m)
 Constructs a masked grid sized to the given mask.
 masked_grid (const masked_grid &)=delete
masked_grid & operator= (const masked_grid &)=delete
 masked_grid (masked_grid &&) noexcept=default
masked_grid & operator= (masked_grid &&) noexcept=default
std::size_t num_cells () const noexcept override
 Get the number of available cells in the masked grid.
std::shared_ptr< cell > search (int index) const noexcept override
 Search for a cell by index, respecting the mask.
const mask & get_mask () const noexcept
 Access the mask used by this grid.
std::shared_ptr< cell > random_cell (randomizer &rng) const noexcept
 Return a random available cell based on the mask.
Public Member Functions inherited from mazes::grid
 grid (unsigned int rows=1u, unsigned int columns=1u, unsigned int levels=1u)
 Construct a grid using unsigned integers.
 grid (const std::tuple< unsigned int, unsigned int, unsigned int > &dimensions)
 Construct a grid using a tuple of unsigned integers.
 grid (const grid &other)
 Copy constructor.
grid & operator= (const grid &other)
 Assignment operator.
 grid (grid &&other) noexcept
 Move constructor.
grid & operator= (grid &&other) noexcept
 Move assignment operator.
 ~grid () override
 Destructor.
grid_operations & operations () noexcept override
const grid_operations & operations () const noexcept override
std::tuple< unsigned int, unsigned int, unsigned int > get_dimensions () const noexcept override
 Get the dimensions of the grid.
std::string contents_of (std::shared_ptr< cell > const &c) const noexcept override
 Get detailed information of a cell in the grid.
std::uint32_t background_color_for (std::shared_ptr< cell > const &c) const noexcept override
 Get the background color for a cell in the grid.
std::shared_ptr< cell > get_neighbor (std::shared_ptr< cell > const &c, Direction dir) const noexcept override
 Get neighbor by the cell's respective location.
std::size_t collect_neighbors (std::shared_ptr< cell > const &c, std::span< std::shared_ptr< cell >, MAX_NEIGHBORS > out) const noexcept override
 Fill a caller-provided buffer with the neighbors of a cell, avoiding allocation.
std::span< const std::shared_ptr< cell > > cells () const noexcept override
 Zero-copy view of all cells, in index order (level-major, then row, then column).
void set_neighbor (const std::shared_ptr< cell > &c, Direction dir, std::shared_ptr< cell > const &neighbor) noexcept override
 Set neighbor for a cell in a given direction.
std::shared_ptr< cell > get_north (const std::shared_ptr< cell > &c) const noexcept override
std::shared_ptr< cell > get_south (const std::shared_ptr< cell > &c) const noexcept override
std::shared_ptr< cell > get_east (const std::shared_ptr< cell > &c) const noexcept override
std::shared_ptr< cell > get_west (const std::shared_ptr< cell > &c) const noexcept override
void clear_cells () noexcept
 Cleanup cells by cleaning up links within cells.
std::vector< std::tuple< int, int, int, int > > get_vertices () const noexcept override
 Get the vertices.
void set_vertices (const std::vector< std::tuple< int, int, int, int > > &vertices) noexcept override
 Set the vertices.
std::vector< std::vector< std::uint32_t > > get_faces () const noexcept override
 Get the faces.
void set_faces (const std::vector< std::vector< std::uint32_t > > &faces) noexcept override
 Set the faces.
std::vector< std::uint8_t > get_pixels () const noexcept override
 Get the pixel data for image generation.
void set_pixels (const std::vector< std::uint8_t > &pixels) noexcept override
 Set the pixel data for image generation.
void resize (unsigned int rows, unsigned int cols, unsigned int levels) noexcept override
 Resize: clear all cells/topology and reset dimensions.
Public Member Functions inherited from mazes::grid_interface
virtual ~grid_interface ()=default
 Virtual destructor for the grid_interface class.
Public Member Functions inherited from mazes::grid_operations
virtual ~grid_operations ()=default
 Destroys the grid_operations object and releases any associated resources.
std::vector< std::shared_ptr< cell > > collect_neighbors (std::shared_ptr< cell > const &c) const noexcept
 Get all the neighbors by the cell.
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 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.

Additional Inherited Members

Public Types inherited from mazes::grid_operations
using neighbor_buffer = std::array<std::shared_ptr<cell>, MAX_NEIGHBORS>
 Reusable neighbor buffer type for collect_neighbors.
Static Public Member Functions inherited from mazes::grid_operations
static bool is_valid_ops (const grid_operations *ops) noexcept
 Checks for nullity.
Static Public Attributes inherited from mazes::grid_operations
static constexpr std::size_t MAX_NEIGHBORS = 4
 Maximum number of neighbors a cell can have.

Detailed Description

A grid that restricts cell availability based on a boolean mask.

Cells at positions where the mask returns false are treated as non-existent. Inherits from grid and overrides search() so that algorithms naturally skip blocked positions. Use binary_tree or sidewinder algorithms with masked grids.

Constructor & Destructor Documentation

◆ masked_grid() [1/2]

mazes::masked_grid::masked_grid ( unsigned int width = 1u,
unsigned int length = 1u,
unsigned int height = 1u )
explicit

Constructs a masked grid with specified dimensions.

Parameters
widthThe width of the grid. Defaults to 1.
lengthThe length of the grid. Defaults to 1.
heightThe number of levels in the grid. Defaults to 1.

◆ masked_grid() [2/2]

mazes::masked_grid::masked_grid ( mask m)
explicit

Constructs a masked grid sized to the given mask.

Parameters
mThe mask restricting available cells

Member Function Documentation

◆ get_mask()

const mask & mazes::masked_grid::get_mask ( ) const
noexcept

Access the mask used by this grid.

Returns
Const reference to the mask

◆ num_cells()

std::size_t mazes::masked_grid::num_cells ( ) const
nodiscardoverridevirtualnoexcept

Get the number of available cells in the masked grid.

Returns
The count of cells that are not blocked by the mask

Reimplemented from mazes::grid.

◆ random_cell()

std::shared_ptr< cell > mazes::masked_grid::random_cell ( randomizer & rng) const
noexcept

Return a random available cell based on the mask.

Parameters
rngRandomizer to use
Returns
A shared pointer to a random available cell

◆ search()

std::shared_ptr< cell > mazes::masked_grid::search ( int index) const
overridevirtualnoexcept

Search for a cell by index, respecting the mask.

Parameters
indexCell index (row * length + col)
Returns
The cell if the position is available, nullptr if blocked or out of range

Reimplemented from mazes::grid.


The documentation for this class was generated from the following file: