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

Portabilityportable
Stabilityexperimental
Maintaineramy@nualeargais.ie
Safe HaskellSafe-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

Documentation

class Grid g whereSource

A regular arrangement of tiles. Minimal complete definition: Index, Direction, indices, distance, directionTo.

Associated Types

type Index g Source

type Direction g Source

Methods

indices :: g -> [Index g]Source

Returns the indices of all tiles in a grid.

distance :: g -> Index g -> Index g -> 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 -> [Index g] -> Index g -> 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.

neighbours :: Eq (Index g) => g -> Index g -> [Index g]Source

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

neighboursOfSet :: Eq (Index g) => g -> [Index g] -> [Index g]Source

neighboursOfSet g as returns the indices of the tiles in the grid g which are adjacent to any of the tiles with index in as.

neighbour :: (Eq (Index g), Eq (Direction g)) => g -> Index g -> Direction g -> Maybe (Index g)Source

neighbour g d a returns the indices of the tile in the grid g which is adjacent to the tile with index a, in the direction d.

numNeighbours :: Eq (Index g) => g -> Index g -> IntSource

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

contains :: Eq (Index g) => g -> Index g -> BoolSource

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

tileCount :: g -> IntSource

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

null :: g -> BoolSource

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

nonNull :: g -> BoolSource

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

edges :: Eq (Index g) => g -> [(Index g, Index g)]Source

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

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

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

isAdjacent :: g -> Index g -> Index g -> 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 :: Eq (Index g) => g -> Index g -> Index g -> [Index g]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 :: Eq (Index g) => g -> Index g -> Index g -> [[Index g]]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.

directionTo :: g -> Index g -> Index g -> [Direction g]Source

directionTo g a b returns the direction(s) of the next tile(s) in a minimal path from the tile at index a to the tile at index b in grid g.

defaultMinDistance :: g -> [Index g] -> Index g -> IntSource

defaultNeighbours :: g -> Index g -> [Index g]Source

defaultNeighboursOfSet :: Eq (Index g) => g -> [Index g] -> [Index g]Source

defaultNeighbour :: (Eq (Index g), Eq (Direction g)) => g -> Index g -> Direction g -> Maybe (Index g)Source

defaultTileCount :: g -> IntSource

defaultEdges :: Eq (Index g) => g -> [(Index g, Index g)]Source

defaultIsAdjacent :: g -> Index g -> Index g -> BoolSource

defaultAdjacentTilesToward :: Eq (Index g) => g -> Index g -> Index g -> [Index g]Source

defaultMinimalPaths :: Eq (Index g) => g -> Index g -> Index g -> [[Index g]]Source

class Grid g => FiniteGrid g whereSource

A regular arrangement of tiles where the number of tiles is finite. Minimal complete definition: size, maxPossibleDistance.

Associated Types

type Size s Source

Methods

size :: g -> Size gSource

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.

maxPossibleDistance :: g -> IntSource

Returns the largest possible distance between two tiles in the grid.

class Grid g => BoundedGrid g whereSource

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

Methods

tileSideCount :: g -> IntSource

Returns the number of sides a tile has

boundary :: Eq (Index g) => g -> [Index g]Source

Returns a the indices of all the tiles at the boundary of a grid.

isBoundary :: Eq (Index g) => g -> Index g -> BoolSource

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

centre :: Eq (Index g) => g -> [Index g]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 :: Eq (Index g) => g -> Index g -> BoolSource

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

defaultBoundary :: Eq (Index g) => g -> [Index g]Source

defaultIsBoundary :: Eq (Index g) => g -> Index g -> BoolSource

defaultCentre :: Eq (Index g) => g -> [Index g]Source

defaultIsCentre :: Eq (Index g) => g -> Index g -> BoolSource

class Grid g => WrappedGrid g whereSource

A regular arrangement of tiles where the boundaries are joined. Minimal complete definition: normalise and denormalise.

Methods

normalise :: g -> Index g -> Index gSource

normalise g a returns the normal indices for a. TODO: need a clearer description and an illustration.

denormalise :: g -> Index g -> [Index g]Source

denormalise g a returns all of the indices in a's translation group. In other words, it returns a plus the indices obtained by translating a in each direction by the extent of the grid along that direction. TODO: need a clearer description and an illustration.

neighboursBasedOn :: (Eq (Index u), Grid g, Grid u, Index g ~ Index u) => u -> g -> Index g -> [Index g]Source

distanceBasedOn :: (Eq (Index g), Grid g, Grid u, Index g ~ Index u) => u -> g -> Index g -> Index g -> IntSource

directionToBasedOn :: (Eq (Index g), Eq (Direction g), Grid g, Grid u, Index g ~ Index u, Direction g ~ Direction u) => u -> g -> Index g -> Index g -> [Direction g]Source

neighboursWrappedBasedOn :: (Eq (Index g), WrappedGrid g, Grid u, Index g ~ Index u) => u -> g -> Index g -> [Index g]Source

distanceWrappedBasedOn :: (Eq (Index g), WrappedGrid g, Grid u, Index g ~ Index u) => u -> g -> Index g -> Index g -> IntSource

directionToWrappedBasedOn :: (Eq (Index g), Eq (Direction g), WrappedGrid g, Grid u, Index g ~ Index u, Direction g ~ Direction u) => u -> g -> Index g -> Index g -> [Direction g]Source

sameEdge :: Eq t => (t, t) -> (t, t) -> BoolSource

adjacentEdges :: (Grid g, Eq (Index g)) => Index g -> g -> [(Index g, Index g)]Source

cartesianIndices :: (Enum r, Enum c, Num r, Num c, Ord r, Ord c) => (r, c) -> [(c, r)]Source