grid-1.0: Tools for working with regular grids\/graphs\/lattices.

Portability portable experimental amy@nualeargais.ie Safe-Infered

Math.Geometry.Grid

Description

A regular arrangement of tiles. Grids have a variety of uses, including games and self-organising maps.

Synopsis

# Generic

class Eq x => Grid g s x | g -> s, g -> x whereSource

A regular arrangement of tiles. Minimal complete definition: `indices`, `distance`, and `size`.

Methods

indices :: g -> [x]Source

Returns the indices of all tiles in a grid.

distance :: x -> x -> g -> IntSource

`distance a b` returns the minimum number of moves required to get from `a` to `b`, moving between adjacent tiles at each step. (Two tiles are adjacent if they share an edge.) If `a` or `b` are not contained within `g`, the result is undefined.

size :: g -> sSource

Returns the dimensions of the grid. For example, if `g` is a 4x3 rectangular grid, `size g` would return `(4, 3)`, while `tileCount g` would return `12`.

neighbours :: x -> g -> [x]Source

`neighbours x g` returns the indices of the tiles in the grid `g` which are adjacent to the tile at `x`.

inGrid :: x -> g -> BoolSource

`x `'inGrid'` g` returns true if the index `x` is contained within `g`, otherwise it returns false.

viewpoint :: x -> g -> [(x, Int)]Source

`viewpoint x g` returns a list of pairs associating the index of each tile in `g` with its distance to the tile with index `x`. If `x` is not contained within `g`, the result is undefined.

tileCount :: Grid g s x => g -> IntSource

Returns the number of tiles in a grid. Compare with `size`.

empty :: Grid g s x => g -> BoolSource

Returns `True` if the number of tiles in a grid is zero, `False` otherwise.

nonEmpty :: Grid g s x => g -> BoolSource

Returns `False` if the number of tiles in a grid is zero, `True` otherwise.

Instances

 Grid HexHexGrid Int (Int, Int) Grid TriTriGrid Int (Int, Int) Grid ParaHexGrid (Int, Int) (Int, Int) Grid TorSquareGrid (Int, Int) (Int, Int) Grid RectSquareGrid (Int, Int) (Int, Int) Grid ParaTriGrid (Int, Int) (Int, Int)

# Grids with triangular tiles

data TriTriGrid Source

A triangular grid with triangular tiles. The grid and its indexing scheme are illustrated in the user guide, available from

Instances

 Show TriTriGrid Grid TriTriGrid Int (Int, Int)

`triTriGrid s` returns a triangular grid with sides of length `s`, using triangular tiles. If `s` is nonnegative, the resulting grid will have `s^2` tiles. Otherwise, the resulting grid will be empty and the list of indices will be null.

A Parallelogrammatical grid with triangular tiles.

Instances

 Show ParaTriGrid Grid ParaTriGrid (Int, Int) (Int, Int)

`paraTriGrid r c` returns a grid in the shape of a parallelogram with `r` rows and `c` columns, using triangular tiles. If `r` and `c` are both nonnegative, the resulting grid will have `2*r*c` tiles. Otherwise, the resulting grid will be empty and the list of indices will be null.

A rectangular grid with square tiles.

Instances

 Show RectSquareGrid Grid RectSquareGrid (Int, Int) (Int, Int)

`rectSquareGrid r c` produces a rectangular grid with `r` rows and `c` columns, using square tiles. If `r` and `c` are both nonnegative, the resulting grid will have `r*c` tiles. Otherwise, the resulting grid will be empty and the list of indices will be null.

A toroidal grid with square tiles.

Instances

 Show TorSquareGrid Grid TorSquareGrid (Int, Int) (Int, Int)

`torSquareGrid r c` returns a toroidal grid with `r` rows and `c` columns, using square tiles. If `r` and `c` are both nonnegative, the resulting grid will have `r*c` tiles. Otherwise, the resulting grid will be empty and the list of indices will be null.

# Grids with hexagonal tiles

data HexHexGrid Source

A hexagonal grid with hexagonal tiles

Instances

 Show HexHexGrid Grid HexHexGrid Int (Int, Int)

`hexHexGrid s` returns a grid of hexagonal shape, with -- sides of length `s`, using hexagonal tiles. If `s` is nonnegative, the resulting grid will have `3*s*(s-1) + 1` tiles. Otherwise, the resulting grid will be empty and the list of indices will be null.

A parallelogramatical grid with hexagonal tiles

Instances

 Show ParaHexGrid Grid ParaHexGrid (Int, Int) (Int, Int)

`paraHexGrid r c` returns a grid in the shape of a parallelogram with `r` rows and `c` columns, using hexagonal tiles. If `r` and `c` are both nonnegative, the resulting grid will have `r*c` tiles. Otherwise, the resulting grid will be empty and the list of indices will be null.