template class cogs::Grid

Overview

Organizational structure of values in a 2 dimensional grid. More…

#include <Grid.h>

template <typename Type>
class Grid {
public:
    // construction

    Grid();
    Grid(const cogs::Grid<Type>& source);
    Grid(const size_t width, const size_t height);
    Grid(const size_t width, const size_t height, const Type& init_value);

    // methods

    void Resize(const size_t width, const size_t height, const Type& init_value);
    void Resize(const size_t width, const size_t height);
    void Clear();
    void Fill(const Type value);
    void Fill(const geom::URect& area, const Type value);
    bool IsInBounds(const size_t x, const size_t y) const;
    Type& At(const size_t x, const size_t y);
    const Type& At(const size_t x, const size_t y) const;
    Type& operator()(const size_t x, const size_t y);
    size_t GetWidth() const;
    size_t GetHeight() const;
    void FlipX();
    void FlipY();
    void Foreach(std::function<void(size_t x, size_t y, const Type&value)> func) const;
    void Foreach(std::function<void(size_t x, size_t y, Type&value)> func);
};

Detailed Documentation

Organizational structure of values in a 2 dimensional grid.

Construction

Grid()

Creates grid with zero size.

Grid(const cogs::Grid<Type>& source)

Creates exact copy of provided grid.

Grid(const size_t width, const size_t height)

Creates grid with specified width and height.

Grid(const size_t width, const size_t height, const Type& init_value)

Creates grid with specified width and height and initializes elements to init_value.

Methods

void Resize(const size_t width, const size_t height, const Type& init_value)

Sets width and height of a grid, and initializes new elements to init_value.

void Resize(const size_t width, const size_t height)

Sets width and height of a grid, and initializes new elements to zeros.

void Clear()

Clears all elements and sets resolution to (0, 0).

void Fill(const Type value)

Sets all elements of grid to a defined value.

void Fill(const geom::URect& area, const Type value)

Sets specified area in grid to a defined value.

bool IsInBounds(const size_t x, const size_t y) const

Checks whether a combination of xy correspond to valid grid cell.

Type& At(const size_t x, const size_t y)

Returns a reference to the cell at position xy.

const Type& At(const size_t x, const size_t y) const

Returns a reference to the cell at position xy.

Type& operator()(const size_t x, const size_t y)

Returns a reference to the cell at position xy.

size_t GetWidth() const

Returns current width of grid.

size_t GetHeight() const

Returns current height of grid.

void FlipX()

Flips all values in x direction.

void FlipY()

Flips all values in y direction.

void Foreach(std::function<void(size_t x, size_t y, const Type&value)> func) const

Executes a specified function for every element in the grid.

void Foreach(std::function<void(size_t x, size_t y, Type&value)> func)

Executes a specified function for every element in the grid.