-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | Tools for working with regular grids\/graphs\/lattices.
--
-- Provides tools for working with regular arrangements of tiles, such as
-- might be used in a board game or some other type of grid map.
-- Currently supports triangular, square, and hexagonal tiles, with
-- various 2D and toroidal layouts.
@package grid
@version 2.0
-- | A module containing private Grid internals. Most developers
-- should use Grid instead. This module is subject to change
-- without notice.
module Math.Geometry.GridInternal
-- | A regular arrangement of tiles. Minimal complete definition:
-- indices, distance, and size.
class Eq x => Grid g s x | g -> s, g -> x where neighbours x g = filter (\ a -> distance x a g ≡ 1) $ indices g inGrid x g = x `elem` indices g viewpoint p g = map f (indices g) where f x = (x, distance p x g) tileCount = length . indices empty g = tileCount g ≡ 0 nonEmpty = not . empty edges g = nubBy sameEdge $ concatMap (`adjacentEdges` g) $ indices g
indices :: Grid g s x => g -> [x]
distance :: Grid g s x => x -> x -> g -> Int
size :: Grid g s x => g -> s
neighbours :: Grid g s x => x -> g -> [x]
inGrid :: Grid g s x => x -> g -> Bool
viewpoint :: Grid g s x => x -> g -> [(x, Int)]
tileCount :: Grid g s x => g -> Int
empty :: Grid g s x => g -> Bool
nonEmpty :: Grid g s x => g -> Bool
edges :: Grid g s x => g -> [(x, x)]
-- | 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.
data TriTriGrid
-- | 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.
triTriGrid :: Int -> TriTriGrid
-- | 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.
data ParaTriGrid
-- | 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.
paraTriGrid :: Int -> Int -> ParaTriGrid
-- | 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.
data RectSquareGrid
-- | 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.
rectSquareGrid :: Int -> Int -> RectSquareGrid
-- | 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.
data TorSquareGrid
-- | 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.
torSquareGrid :: Int -> Int -> TorSquareGrid
-- | 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.
data HexHexGrid
-- | 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.
hexHexGrid :: Int -> HexHexGrid
-- | 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.
data ParaHexGrid
-- | 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.
paraHexGrid :: Int -> Int -> ParaHexGrid
instance Eq TriTriGrid
instance Eq ParaTriGrid
instance Eq RectSquareGrid
instance Eq TorSquareGrid
instance Eq HexHexGrid
instance Eq ParaHexGrid
instance Grid ParaHexGrid (Int, Int) (Int, Int)
instance Show ParaHexGrid
instance Grid HexHexGrid Int (Int, Int)
instance Show HexHexGrid
instance Grid TorSquareGrid (Int, Int) (Int, Int)
instance Show TorSquareGrid
instance Grid RectSquareGrid (Int, Int) (Int, Int)
instance Show RectSquareGrid
instance Grid ParaTriGrid (Int, Int) (Int, Int)
instance Show ParaTriGrid
instance Grid TriTriGrid Int (Int, Int)
instance Show TriTriGrid
-- | A regular arrangement of tiles. Grids have a variety of uses,
-- including games and self-organising maps.
module Math.Geometry.Grid
-- | A regular arrangement of tiles. Minimal complete definition:
-- indices, distance, and size.
class Eq x => Grid g s x | g -> s, g -> x where neighbours x g = filter (\ a -> distance x a g ≡ 1) $ indices g inGrid x g = x `elem` indices g viewpoint p g = map f (indices g) where f x = (x, distance p x g) tileCount = length . indices empty g = tileCount g ≡ 0 nonEmpty = not . empty edges g = nubBy sameEdge $ concatMap (`adjacentEdges` g) $ indices g
indices :: Grid g s x => g -> [x]
distance :: Grid g s x => x -> x -> g -> Int
size :: Grid g s x => g -> s
neighbours :: Grid g s x => x -> g -> [x]
inGrid :: Grid g s x => x -> g -> Bool
viewpoint :: Grid g s x => x -> g -> [(x, Int)]
tileCount :: Grid g s x => g -> Int
empty :: Grid g s x => g -> Bool
nonEmpty :: Grid g s x => g -> Bool
edges :: Grid g s x => g -> [(x, x)]
-- | 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.
data TriTriGrid
-- | 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.
triTriGrid :: Int -> TriTriGrid
-- | 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.
data ParaTriGrid
-- | 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.
paraTriGrid :: Int -> Int -> ParaTriGrid
-- | 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.
data RectSquareGrid
-- | 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.
rectSquareGrid :: Int -> Int -> RectSquareGrid
-- | 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.
data TorSquareGrid
-- | 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.
torSquareGrid :: Int -> Int -> TorSquareGrid
-- | 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.
data HexHexGrid
-- | 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.
hexHexGrid :: Int -> HexHexGrid
-- | 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.
data ParaHexGrid
-- | 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.
paraHexGrid :: Int -> Int -> ParaHexGrid
-- | Ordered maps from tiles on a grid to values. This module is a wrapper
-- around Grid and Map, in order to
-- combine the functionality of grids and maps into a single type.
module Math.Geometry.GridMap
-- | A Map from tile positions in a grid to values.
data GridMap g k v
-- | Construct a grid map which is strict in the keys (tile positions), but
-- lazy in the values.
lazyGridMap :: (Ord k, Grid g s k) => g -> [v] -> GridMap g k v
-- | Returns the indices of all tiles in a grid.
indices :: Grid g s x => g -> [x]
-- | 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.
distance :: Grid g s x => x -> x -> g -> Int
-- | 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.
size :: Grid g s x => g -> s
-- | neighbours x g returns the indices of the tiles in the
-- grid g which are adjacent to the tile at x.
neighbours :: Grid g s x => x -> g -> [x]
-- | x `'inGrid'` g returns true if the index x is
-- contained within g, otherwise it returns false.
inGrid :: Grid g s x => x -> g -> Bool
-- | 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.
viewpoint :: Grid g s x => x -> g -> [(x, Int)]
-- | Returns the number of tiles in a grid. Compare with
-- size.
tileCount :: Grid g s x => g -> Int
-- | Returns True if the number of tiles in a grid is zero,
-- False otherwise.
empty :: Grid g s x => g -> Bool
-- | Returns False if the number of tiles in a grid is zero,
-- True otherwise.
nonEmpty :: Grid g s x => g -> Bool
-- | O(min(n,W)). Find the value at a tile position in the grid.
-- Calls error when the element can not be found.
(!) :: Ord k => GridMap g k v -> k -> v
-- | O(min(n,W)). Lookup the value at a tile position in the grid
-- map.
lookup :: Ord k => k -> GridMap g k v -> Maybe v
-- | O(min(n,W)). The expression (findWithDefault def k
-- map) returns the value at tile position k or returns
-- def when the tile is not within the bounds of the grid map.
findWithDefault :: Ord k => v -> k -> GridMap g k v -> v
-- | O(min(n,W)). Adjust a value at a specific tile position. When
-- the tile is not within the bounds of the grid map, the original grid
-- map is returned.
adjust :: Ord k => (v -> v) -> k -> GridMap g k v -> GridMap g k v
-- | O(min(n,W)). Adjust a value at a specific key. When the tile is
-- not within the bounds of the grid map, the original grid map is
-- returned.
adjustWithKey :: Ord k => (k -> v -> v) -> k -> GridMap g k v -> GridMap g k v
-- | O(n). Map a function over all values in the grid map.
map :: (a -> b) -> GridMap g k a -> GridMap g k b
-- | O(n). Map a function over all values in the grid map.
mapWithKey :: (k -> a -> b) -> GridMap g k a -> GridMap g k b
-- | O(n). The function mapAccum threads an
-- accumulating argument through the grid map. WARNING: The order in
-- which the elements are processed is not guaranteed.
mapAccum :: (a -> b -> (a, c)) -> a -> GridMap g k b -> (a, GridMap g k c)
-- | O(n). The function mapAccumWithKey threads an
-- accumulating argument through the grid map. WARNING: The order in
-- which the elements are processed is not guaranteed.
mapAccumWithKey :: (a -> k -> b -> (a, c)) -> a -> GridMap g k b -> (a, GridMap g k c)
-- | O(n). Fold the values in the grid map using the given
-- left-associative binary operator. WARNING: The order in which the
-- elements are processed is not guaranteed.
fold :: (a -> b -> a) -> a -> GridMap g k b -> a
-- | O(n). Fold the keys and values in the grid map using the given
-- left-associative binary operator. WARNING: The order in which the
-- elements are processed is not guaranteed.
foldWithKey :: (a -> k -> b -> a) -> a -> GridMap g k b -> a
-- | O(n). A strict version of fold.
fold' :: (a -> b -> a) -> a -> GridMap g k b -> a
-- | O(n). A strict version of foldWithKey.
foldWithKey' :: (a -> k -> b -> a) -> a -> GridMap g k b -> a
-- | O(n). Return all elements of the grid map. The order is not
-- guaranteed.
elems :: GridMap g k a -> [a]
-- | O(n*min(n,W)). The set of all tile positions in the grid map.
keysSet :: GridMap g k a -> Set k
-- | O(n). Returns all key (tile position)/value pairs in the grid
-- map.
toList :: GridMap g k a -> [(k, a)]
instance (Eq g, Eq k, Eq v) => Eq (GridMap g k v)
instance (Eq k, Grid g s k) => Grid (GridMap g k v) s k
instance (Show g, Show v) => Show (GridMap g k v)