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

Copyright (c) Amy de Buitléir 2012-2017 BSD-style amy@nualeargais.ie experimental portable Safe Haskell2010

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 where Source #

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

Minimal complete definition

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 -> Int Source #

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 -> Int Source #

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 -> Int Source #

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 -> Bool Source #

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

tileCount :: g -> Int Source #

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

null :: g -> Bool Source #

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

nonNull :: g -> Bool Source #

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 -> Bool Source #

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 -> Int Source #

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 -> Int Source #

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

defaultIsAdjacent :: g -> Index g -> Index g -> Bool Source #

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

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

Instances
 Source # Instance detailsDefined in Math.Geometry.Grid.TriangularInternal Associated Types Methods Source # Instance detailsDefined in Math.Geometry.Grid.TriangularInternal Associated Types Methods Source # Instance detailsDefined in Math.Geometry.Grid.TriangularInternal Associated Types Methods Source # Instance detailsDefined in Math.Geometry.Grid.TriangularInternal Associated Types Methods Source # Instance detailsDefined in Math.Geometry.Grid.TriangularInternal Associated Types Methods Source # Instance detailsDefined in Math.Geometry.Grid.TriangularInternal Associated Types Methods Source # Instance detailsDefined in Math.Geometry.Grid.TriangularInternal Associated Types Source # Instance detailsDefined in Math.Geometry.Grid.SquareInternal Associated Types Methods Source # Instance detailsDefined in Math.Geometry.Grid.SquareInternal Associated Types Methods Source # Instance detailsDefined in Math.Geometry.Grid.SquareInternal Associated Types Source # Instance detailsDefined in Math.Geometry.Grid.OctagonalInternal Associated Types Methods Source # Instance detailsDefined in Math.Geometry.Grid.OctagonalInternal Associated Types Methods Source # Instance detailsDefined in Math.Geometry.Grid.OctagonalInternal Associated Types Source # Instance detailsDefined in Math.Geometry.Grid.HexagonalInternal2 Associated Types Methods Source # Instance detailsDefined in Math.Geometry.Grid.HexagonalInternal2 Associated Types Methods Source # Instance detailsDefined in Math.Geometry.Grid.HexagonalInternal2 Associated Types Source # Instance detailsDefined in Math.Geometry.Grid.HexagonalInternal Associated Types Methods Source # Instance detailsDefined in Math.Geometry.Grid.HexagonalInternal Associated Types Methods Source # Instance detailsDefined in Math.Geometry.Grid.HexagonalInternal Associated Types Grid g => Grid (LGridMap g v) Source # Instance detailsDefined in Math.Geometry.GridMap.Lazy Associated Typestype Index (LGridMap g v) :: Type Source #type Direction (LGridMap g v) :: Type Source # Methodsindices :: LGridMap g v -> [Index (LGridMap g v)] Source #distance :: LGridMap g v -> Index (LGridMap g v) -> Index (LGridMap g v) -> Int Source #minDistance :: LGridMap g v -> [Index (LGridMap g v)] -> Index (LGridMap g v) -> Int Source #neighbours :: LGridMap g v -> Index (LGridMap g v) -> [Index (LGridMap g v)] Source #neighboursOfSet :: LGridMap g v -> [Index (LGridMap g v)] -> [Index (LGridMap g v)] Source #neighbour :: LGridMap g v -> Index (LGridMap g v) -> Direction (LGridMap g v) -> Maybe (Index (LGridMap g v)) Source #numNeighbours :: LGridMap g v -> Index (LGridMap g v) -> Int Source #contains :: LGridMap g v -> Index (LGridMap g v) -> Bool Source #tileCount :: LGridMap g v -> Int Source #null :: LGridMap g v -> Bool Source #nonNull :: LGridMap g v -> Bool Source #edges :: LGridMap g v -> [(Index (LGridMap g v), Index (LGridMap g v))] Source #viewpoint :: LGridMap g v -> Index (LGridMap g v) -> [(Index (LGridMap g v), Int)] Source #isAdjacent :: LGridMap g v -> Index (LGridMap g v) -> Index (LGridMap g v) -> Bool Source #adjacentTilesToward :: LGridMap g v -> Index (LGridMap g v) -> Index (LGridMap g v) -> [Index (LGridMap g v)] Source #minimalPaths :: LGridMap g v -> Index (LGridMap g v) -> Index (LGridMap g v) -> [[Index (LGridMap g v)]] Source #directionTo :: LGridMap g v -> Index (LGridMap g v) -> Index (LGridMap g v) -> [Direction (LGridMap g v)] Source #defaultMinDistance :: LGridMap g v -> [Index (LGridMap g v)] -> Index (LGridMap g v) -> Int Source #defaultNeighbours :: LGridMap g v -> Index (LGridMap g v) -> [Index (LGridMap g v)] Source #defaultNeighboursOfSet :: LGridMap g v -> [Index (LGridMap g v)] -> [Index (LGridMap g v)] Source #defaultNeighbour :: LGridMap g v -> Index (LGridMap g v) -> Direction (LGridMap g v) -> Maybe (Index (LGridMap g v)) Source #defaultEdges :: LGridMap g v -> [(Index (LGridMap g v), Index (LGridMap g v))] Source #defaultIsAdjacent :: LGridMap g v -> Index (LGridMap g v) -> Index (LGridMap g v) -> Bool Source #defaultAdjacentTilesToward :: LGridMap g v -> Index (LGridMap g v) -> Index (LGridMap g v) -> [Index (LGridMap g v)] Source #defaultMinimalPaths :: LGridMap g v -> Index (LGridMap g v) -> Index (LGridMap g v) -> [[Index (LGridMap g v)]] Source #

class Grid g => FiniteGrid g where Source #

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

Associated Types

type Size g Source #

Methods

size :: g -> Size g Source #

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.

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

Instances
 Source # Instance detailsDefined in Math.Geometry.Grid.TriangularInternal Associated Types Methods Source # Instance detailsDefined in Math.Geometry.Grid.TriangularInternal Associated Types Methods Source # Instance detailsDefined in Math.Geometry.Grid.TriangularInternal Associated Types Methods Source # Instance detailsDefined in Math.Geometry.Grid.TriangularInternal Associated Types Methods Source # Instance detailsDefined in Math.Geometry.Grid.TriangularInternal Associated Types Methods Source # Instance detailsDefined in Math.Geometry.Grid.TriangularInternal Associated Types Methods Source # Instance detailsDefined in Math.Geometry.Grid.SquareInternal Associated Types Methods Source # Instance detailsDefined in Math.Geometry.Grid.SquareInternal Associated Types Methods Source # Instance detailsDefined in Math.Geometry.Grid.OctagonalInternal Associated Types Methods Source # Instance detailsDefined in Math.Geometry.Grid.OctagonalInternal Associated Types Methods Source # Instance detailsDefined in Math.Geometry.Grid.HexagonalInternal2 Associated Types Methods Source # Instance detailsDefined in Math.Geometry.Grid.HexagonalInternal2 Associated Types Methods Source # Instance detailsDefined in Math.Geometry.Grid.HexagonalInternal Associated Types Methods Source # Instance detailsDefined in Math.Geometry.Grid.HexagonalInternal Associated Types Methods FiniteGrid g => FiniteGrid (LGridMap g v) Source # Instance detailsDefined in Math.Geometry.GridMap.Lazy Associated Typestype Size (LGridMap g v) :: Type Source # Methodssize :: LGridMap g v -> Size (LGridMap g v) Source #

class Grid g => BoundedGrid g where Source #

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

Minimal complete definition

tileSideCount

Methods

tileSideCount :: g -> Int Source #

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 -> Bool Source #

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 -> Bool Source #

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 -> Bool Source #

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

defaultIsCentre :: Eq (Index g) => g -> Index g -> Bool Source #

Instances
 Source # Instance detailsDefined in Math.Geometry.Grid.TriangularInternal Methods Source # Instance detailsDefined in Math.Geometry.Grid.TriangularInternal Methods Source # Instance detailsDefined in Math.Geometry.Grid.TriangularInternal Methods Source # Instance detailsDefined in Math.Geometry.Grid.SquareInternal Methods Source # Instance detailsDefined in Math.Geometry.Grid.OctagonalInternal Methods Source # Instance detailsDefined in Math.Geometry.Grid.HexagonalInternal2 Methods Source # Instance detailsDefined in Math.Geometry.Grid.HexagonalInternal2 Methods Source # Instance detailsDefined in Math.Geometry.Grid.HexagonalInternal Methods Source # Instance detailsDefined in Math.Geometry.Grid.HexagonalInternal Methods BoundedGrid g => BoundedGrid (LGridMap g v) Source # Instance detailsDefined in Math.Geometry.GridMap.Lazy MethodstileSideCount :: LGridMap g v -> Int Source #boundary :: LGridMap g v -> [Index (LGridMap g v)] Source #isBoundary :: LGridMap g v -> Index (LGridMap g v) -> Bool Source #centre :: LGridMap g v -> [Index (LGridMap g v)] Source #isCentre :: LGridMap g v -> Index (LGridMap g v) -> Bool Source #defaultBoundary :: LGridMap g v -> [Index (LGridMap g v)] Source #defaultIsBoundary :: LGridMap g v -> Index (LGridMap g v) -> Bool Source #defaultCentre :: LGridMap g v -> [Index (LGridMap g v)] Source #defaultIsCentre :: LGridMap g v -> Index (LGridMap g v) -> Bool Source #

class Grid g => WrappedGrid g where Source #

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

Methods

normalise :: g -> Index g -> Index g Source #

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.

Instances
 Source # Instance detailsDefined in Math.Geometry.Grid.TriangularInternal Methods Source # Instance detailsDefined in Math.Geometry.Grid.TriangularInternal Methods Source # Instance detailsDefined in Math.Geometry.Grid.TriangularInternal Methods Source # Instance detailsDefined in Math.Geometry.Grid.SquareInternal Methods Source # Instance detailsDefined in Math.Geometry.Grid.OctagonalInternal Methods WrappedGrid g => WrappedGrid (LGridMap g v) Source # Instance detailsDefined in Math.Geometry.GridMap.Lazy Methodsnormalise :: LGridMap g v -> Index (LGridMap g v) -> Index (LGridMap g v) Source #denormalise :: LGridMap g v -> Index (LGridMap g v) -> [Index (LGridMap g v)] Source #

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 -> Int Source #

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 #

neighbourWrappedBasedOn :: (Eq (Index g), Eq (Direction g), WrappedGrid g, Grid u, Index g ~ Index u, Direction g ~ Direction u) => u -> g -> Index g -> Direction g -> Maybe (Index g) Source #

distanceWrappedBasedOn :: (Eq (Index g), WrappedGrid g, Grid u, Index g ~ Index u) => u -> g -> Index g -> Index g -> Int Source #

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) -> Bool Source #

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 #