grid-3.0.1: Tools for working with regular grids (graphs, lattices).

Portability portable experimental amy@nualeargais.ie Safe-Inferred

Math.Geometry.GridInternal

Description

A module containing private `Grid` internals. Most developers should use `Grid` instead. This module is subject to change without notice.

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 :: g -> x -> x -> IntSource

`distance g a b` returns the minimum number of moves required to get from the tile at index `a` to the tile at index `b` in grid `g`, 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.

minDistance :: g -> [x] -> x -> IntSource

`minDistance g bs a` returns the minimum number of moves required to get from any of the tiles at indices `bs` to the tile at index `a` in grid `g`, moving between adjacent tiles at each step. (Two tiles are adjacent if they share an edge.) If `a` or any of `bs` 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 :: g -> x -> [x]Source

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

numNeighbours :: g -> x -> IntSource

`numNeighbours g x` returns the number of tiles in the grid `g` which are adjacent to the tile with index `x`.

contains :: g -> x -> BoolSource

`g `'contains'` x` returns `True` if the index `x` is contained within the grid `g`, otherwise it returns false.

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

`viewpoint g x` 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 :: g -> IntSource

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

empty :: g -> BoolSource

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

nonEmpty :: g -> BoolSource

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

edges :: g -> [(x, x)]Source

A list of all edges in a grid, where the edges are represented by a pair of indices of adjacent tiles.

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

`isAdjacent g a b` returns `True` if the tile at index `a` is adjacent to the tile at index `b` in `g`. (Two tiles are adjacent if they share an edge.) If `a` or `b` are not contained within `g`, the result is undefined.

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

`adjacentTilesToward g a b` returns the indices of all tiles which are neighbours of the tile at index `a`, and which are closer to the tile at `b` than `a` is. In other words, it returns the possible next steps on a minimal path from `a` to `b`. If `a` or `b` are not contained within `g`, or if there is no path from `a` to `b` (e.g., a disconnected grid), the result is undefined.

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

`minimalPaths g a b` returns a list of all minimal paths from the tile at index `a` to the tile at index `b` in grid `g`. A path is a sequence of tiles where each tile in the sequence is adjacent to the previous one. (Two tiles are adjacent if they share an edge.) If `a` or `b` are not contained within `g`, the result is undefined.

Tip: The default implementation of this function calls `adjacentTilesToward`. If you want to use a custom algorithm, consider modifying `adjacentTilesToward` instead of `minimalPaths`.

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) (Eq k, Grid g s k) => Grid (GridMap g k v) s k

class Grid g s x => BoundedGrid g s x whereSource

A regular arrangement of tiles with an edge. Minimal complete definition: `boundary`.

Methods

boundary :: g -> [x]Source

Returns a the indices of all the tiles at the boundary of a grid, including corner tiles.

isBoundary :: g -> x -> BoolSource

`isBoundary g x`' returns `True` if the tile with index `x` is on a boundary of `g`, `False` otherwise. (Corner tiles are also boundary tiles.)

centre :: g -> [x]Source

Returns the index of the tile(s) that require the maximum number of moves to reach the nearest boundary tile. A grid may have more than one central tile (e.g., a rectangular grid with an even number of rows and columns will have four central tiles).

isCentre :: g -> x -> BoolSource

`isCentre g x`' returns `True` if the tile with index `x` is a centre tile of `g`, `False` otherwise.

Instances

 BoundedGrid HexHexGrid Int (Int, Int) BoundedGrid TriTriGrid Int (Int, Int) BoundedGrid ParaHexGrid (Int, Int) (Int, Int) BoundedGrid RectSquareGrid (Int, Int) (Int, Int) BoundedGrid 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 at https://github.com/mhwombat/grid/wiki.

Instances

 Eq TriTriGrid Show TriTriGrid BoundedGrid TriTriGrid Int (Int, Int) 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. The grid and its indexing scheme are illustrated in the user guide, available at https://github.com/mhwombat/grid/wiki.

Instances

 Eq ParaTriGrid Show ParaTriGrid BoundedGrid ParaTriGrid (Int, Int) (Int, Int) 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.

# Grids with square tiles

A rectangular grid with square tiles. The grid and its indexing scheme are illustrated in the user guide, available at https://github.com/mhwombat/grid/wiki.

Instances

 Eq RectSquareGrid Show RectSquareGrid BoundedGrid RectSquareGrid (Int, Int) (Int, Int) 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. The grid and its indexing scheme are illustrated in the user guide, available at https://github.com/mhwombat/grid/wiki.

Instances

 Eq TorSquareGrid 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 The grid and its indexing scheme are illustrated in the user guide, available at https://github.com/mhwombat/grid/wiki.

Instances

 Eq HexHexGrid Show HexHexGrid BoundedGrid HexHexGrid Int (Int, Int) 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 The grid and its indexing scheme are illustrated in the user guide, available at https://github.com/mhwombat/grid/wiki.

Instances

 Eq ParaHexGrid Show ParaHexGrid BoundedGrid ParaHexGrid (Int, Int) (Int, Int) 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.