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

General purpose grid class for 2D maze generation. More...

#include <grid.h>

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

Public Member Functions

 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
std::shared_ptr< cell > search (int index) const noexcept override
 Search for a cell by index.
std::size_t num_cells () const noexcept override
 Get the count of cells in the grid.
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

General purpose grid class for 2D maze generation.

Constructor & Destructor Documentation

◆ grid() [1/4]

mazes::grid::grid ( unsigned int rows = 1u,
unsigned int columns = 1u,
unsigned int levels = 1u )
explicit

Construct a grid using unsigned integers.

Parameters
rows
columns
levels

◆ grid() [2/4]

mazes::grid::grid ( const std::tuple< unsigned int, unsigned int, unsigned int > & dimensions)
explicit

Construct a grid using a tuple of unsigned integers.

Parameters
dimensions

◆ grid() [3/4]

mazes::grid::grid ( const grid & other)

Copy constructor.

Parameters
other

◆ grid() [4/4]

mazes::grid::grid ( grid && other)
noexcept

Move constructor.

Parameters
other

Member Function Documentation

◆ background_color_for()

std::uint32_t mazes::grid::background_color_for ( std::shared_ptr< cell > const & c) const
overridevirtualnoexcept

Get the background color for a cell in the grid.

Parameters
c
Returns

Implements mazes::grid_interface.

◆ cells()

std::span< const std::shared_ptr< cell > > mazes::grid::cells ( ) const
overridevirtualnoexcept

Zero-copy view of all cells, in index order (level-major, then row, then column).

Note
The span is invalidated by resize()

Implements mazes::grid_operations.

◆ collect_neighbors()

std::size_t mazes::grid::collect_neighbors ( std::shared_ptr< cell > const & c,
std::span< std::shared_ptr< cell >, MAX_NEIGHBORS > out ) const
overridevirtualnoexcept

Fill a caller-provided buffer with the neighbors of a cell, avoiding allocation.

Parameters
c
outBuffer to fill (reusable across calls)
Returns
The number of neighbors written to out

Implements mazes::grid_operations.

◆ contents_of()

std::string mazes::grid::contents_of ( std::shared_ptr< cell > const & c) const
overridevirtualnoexcept

Get detailed information of a cell in the grid.

Parameters
c
Returns

Implements mazes::grid_interface.

◆ get_dimensions()

std::tuple< unsigned int, unsigned int, unsigned int > mazes::grid::get_dimensions ( ) const
overridevirtualnoexcept

Get the dimensions of the grid.

Returns
A tuple containing the number of rows, columns, and levels

Implements mazes::grid_operations.

◆ get_east()

std::shared_ptr< cell > mazes::grid::get_east ( const std::shared_ptr< cell > & c) const
overridevirtualnoexcept

◆ get_faces()

std::vector< std::vector< std::uint32_t > > mazes::grid::get_faces ( ) const
overridevirtualnoexcept

Get the faces.

Returns
A vector of faces, where each face is a vector of vertex indices

Implements mazes::grid_operations.

◆ get_neighbor()

std::shared_ptr< cell > mazes::grid::get_neighbor ( std::shared_ptr< cell > const & c,
Direction dir ) const
overridevirtualnoexcept

Get neighbor by the cell's respective location.

Parameters
c
dir
Returns

Implements mazes::grid_operations.

◆ get_north()

std::shared_ptr< cell > mazes::grid::get_north ( const std::shared_ptr< cell > & c) const
overridevirtualnoexcept

◆ get_pixels()

std::vector< std::uint8_t > mazes::grid::get_pixels ( ) const
overridevirtualnoexcept

Get the pixel data for image generation.

Returns
A vector of RGBA pixel data

Implements mazes::grid_operations.

◆ get_south()

std::shared_ptr< cell > mazes::grid::get_south ( const std::shared_ptr< cell > & c) const
overridevirtualnoexcept

◆ get_vertices()

std::vector< std::tuple< int, int, int, int > > mazes::grid::get_vertices ( ) const
overridevirtualnoexcept

Get the vertices.

Returns
A vector of vertices as tuples (x, y, z, w)

Implements mazes::grid_operations.

◆ get_west()

std::shared_ptr< cell > mazes::grid::get_west ( const std::shared_ptr< cell > & c) const
overridevirtualnoexcept

◆ num_cells()

std::size_t mazes::grid::num_cells ( ) const
overridevirtualnoexcept

Get the count of cells in the grid.

Returns
The number of cells in the grid

Implements mazes::grid_operations.

Reimplemented in mazes::masked_grid.

◆ operations() [1/2]

const grid_operations & mazes::grid::operations ( ) const
overridevirtualnoexcept
Returns

Implements mazes::grid_interface.

◆ operations() [2/2]

grid_operations & mazes::grid::operations ( )
overridevirtualnoexcept
Returns

Implements mazes::grid_interface.

◆ operator=() [1/2]

grid & mazes::grid::operator= ( const grid & other)

Assignment operator.

Parameters
other
Returns

◆ operator=() [2/2]

grid & mazes::grid::operator= ( grid && other)
noexcept

Move assignment operator.

Parameters
other
Returns

◆ search()

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

Search for a cell by index.

Parameters
index
Returns

Implements mazes::grid_operations.

Reimplemented in mazes::masked_grid.

◆ set_faces()

void mazes::grid::set_faces ( const std::vector< std::vector< std::uint32_t > > & faces)
overridevirtualnoexcept

Set the faces.

Parameters
facesA vector of faces, where each face is a vector of vertex indices

Implements mazes::grid_operations.

◆ set_neighbor()

void mazes::grid::set_neighbor ( const std::shared_ptr< cell > & c,
Direction dir,
std::shared_ptr< cell > const & neighbor )
overridevirtualnoexcept

Set neighbor for a cell in a given direction.

Parameters
c
dir
neighbor
Returns

Implements mazes::grid_operations.

◆ set_pixels()

void mazes::grid::set_pixels ( const std::vector< std::uint8_t > & pixels)
overridevirtualnoexcept

Set the pixel data for image generation.

Parameters
pixelsA vector of RGBA pixel data

Implements mazes::grid_operations.

◆ set_vertices()

void mazes::grid::set_vertices ( const std::vector< std::tuple< int, int, int, int > > & vertices)
overridenoexcept

Set the vertices.

Parameters
verticesA vector of vertices as tuples (x, y, z, w)

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