-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Tools for working with regular grids (graphs, lattices). -- -- Please see the README on GitHub at -- https://github.com/mhwombat/grid#readme @package grid @version 7.8.10 -- | 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: -- Index, Direction, -- indices, distance, -- directionTo. class Grid g where { type family Index g; type family Direction g; } -- | Returns the indices of all tiles in a grid. indices :: Grid g => g -> [Index g] -- | 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. distance :: Grid g => g -> Index g -> Index g -> Int -- | 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. minDistance :: Grid g => g -> [Index g] -> Index g -> Int -- | neighbours g a returns the indices of the tiles in the -- grid g which are adjacent to the tile with index a. neighbours :: (Grid g, Eq (Index g)) => g -> Index g -> [Index g] -- | 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. neighboursOfSet :: (Grid g, Eq (Index g)) => g -> [Index g] -> [Index g] -- | 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. neighbour :: (Grid g, Eq (Index g), Eq (Direction g)) => g -> Index g -> Direction g -> Maybe (Index g) -- | numNeighbours g a returns the number of tiles in the -- grid g which are adjacent to the tile with index a. numNeighbours :: (Grid g, Eq (Index g)) => g -> Index g -> Int -- | g `contains' a returns True if the index -- a is contained within the grid g, otherwise it -- returns false. contains :: (Grid g, Eq (Index g)) => g -> Index g -> Bool -- | Returns the number of tiles in a grid. Compare with -- size. tileCount :: Grid g => g -> Int -- | Returns True if the number of tiles in a grid is zero, -- False otherwise. null :: Grid g => g -> Bool -- | Returns False if the number of tiles in a grid is zero, -- True otherwise. nonNull :: Grid g => g -> Bool -- | A list of all edges in a grid, where the edges are represented by a -- pair of indices of adjacent tiles. edges :: (Grid g, Eq (Index g)) => g -> [(Index g, Index g)] -- | 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. viewpoint :: Grid g => g -> Index g -> [(Index g, Int)] -- | 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. isAdjacent :: Grid g => g -> Index g -> Index g -> Bool -- | 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. adjacentTilesToward :: (Grid g, Eq (Index g)) => g -> Index g -> Index g -> [Index g] -- | 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. minimalPaths :: (Grid g, Eq (Index g)) => g -> Index g -> Index g -> [[Index g]] -- | 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. directionTo :: Grid g => g -> Index g -> Index g -> [Direction g] defaultMinDistance :: Grid g => g -> [Index g] -> Index g -> Int defaultNeighbours :: Grid g => g -> Index g -> [Index g] defaultNeighboursOfSet :: (Grid g, Eq (Index g)) => g -> [Index g] -> [Index g] defaultNeighbour :: (Grid g, Eq (Index g), Eq (Direction g)) => g -> Index g -> Direction g -> Maybe (Index g) defaultTileCount :: Grid g => g -> Int defaultEdges :: (Grid g, Eq (Index g)) => g -> [(Index g, Index g)] defaultIsAdjacent :: Grid g => g -> Index g -> Index g -> Bool defaultAdjacentTilesToward :: (Grid g, Eq (Index g)) => g -> Index g -> Index g -> [Index g] defaultMinimalPaths :: (Grid g, Eq (Index g)) => g -> Index g -> Index g -> [[Index g]] -- | A regular arrangement of tiles where the number of tiles is finite. -- Minimal complete definition: size, -- maxPossibleDistance. class Grid g => FiniteGrid g where { type family Size g; } -- | 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 :: FiniteGrid g => g -> Size g -- | Returns the largest possible distance between two tiles in the grid. maxPossibleDistance :: FiniteGrid g => g -> Int -- | A regular arrangement of tiles with an edge. Minimal complete -- definition: tileSideCount. class Grid g => BoundedGrid g -- | Returns the number of sides a tile has tileSideCount :: BoundedGrid g => g -> Int -- | Returns a the indices of all the tiles at the boundary of a grid. boundary :: (BoundedGrid g, Eq (Index g)) => g -> [Index g] -- | 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.) isBoundary :: (BoundedGrid g, Eq (Index g)) => g -> Index g -> Bool -- | 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). centre :: (BoundedGrid g, Eq (Index g)) => g -> [Index g] -- | isCentre g a' returns True if the tile with -- index a is a centre tile of g, False -- otherwise. isCentre :: (BoundedGrid g, Eq (Index g)) => g -> Index g -> Bool defaultBoundary :: (BoundedGrid g, Eq (Index g)) => g -> [Index g] defaultIsBoundary :: (BoundedGrid g, Eq (Index g)) => g -> Index g -> Bool defaultCentre :: (BoundedGrid g, Eq (Index g)) => g -> [Index g] defaultIsCentre :: (BoundedGrid g, Eq (Index g)) => g -> Index g -> Bool -- | A regular arrangement of tiles where the boundaries are joined. -- Minimal complete definition: normalise and -- denormalise. class (Grid g) => WrappedGrid g -- | normalise g a returns the "normal" indices for -- a. TODO: need a clearer description and an illustration. normalise :: WrappedGrid g => g -> Index g -> Index g -- | 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. denormalise :: WrappedGrid g => g -> Index g -> [Index g] neighboursBasedOn :: (Eq (Index u), Grid g, Grid u, Index g ~ Index u) => u -> g -> Index g -> [Index g] distanceBasedOn :: (Eq (Index g), Grid g, Grid u, Index g ~ Index u) => u -> g -> Index g -> Index g -> Int 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] neighboursWrappedBasedOn :: (Eq (Index g), WrappedGrid g, Grid u, Index g ~ Index u) => u -> g -> Index g -> [Index g] 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) distanceWrappedBasedOn :: (Eq (Index g), WrappedGrid g, Grid u, Index g ~ Index u) => u -> g -> Index g -> Index g -> Int 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] sameEdge :: Eq t => (t, t) -> (t, t) -> Bool adjacentEdges :: (Grid g, Eq (Index g)) => Index g -> g -> [(Index g, Index g)] cartesianIndices :: (Enum r, Enum c, Num r, Num c, Ord r, Ord c) => (r, c) -> [(c, r)] cartesianCentre :: (Int, Int) -> [(Int, Int)] cartesianMidpoints :: Int -> [Int] -- | A module containing private TriGrid internals. Most -- developers should use TriGrid instead. This module is subject -- to change without notice. module Math.Geometry.Grid.TriangularInternal data TriDirection South :: TriDirection Northwest :: TriDirection Northeast :: TriDirection North :: TriDirection Southeast :: TriDirection Southwest :: TriDirection -- | An unbounded 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 UnboundedTriGrid UnboundedTriGrid :: UnboundedTriGrid -- | For triangular tiles, it is convenient to define a third component z. triZ :: Int -> Int -> Int -- | 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 :: Int -> [(Int, Int)] -> TriTriGrid inTriTriGrid :: (Int, Int) -> Int -> Bool -- | 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 null 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 :: (Int, Int) -> [(Int, Int)] -> 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 null and the list of indices will be null. paraTriGrid :: Int -> Int -> ParaTriGrid parallelogramIndices :: Int -> Int -> [(Int, Int)] -- | A rectangular 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 RectTriGrid RectTriGrid :: (Int, Int) -> [(Int, Int)] -> RectTriGrid -- | rectTriGrid r c returns a grid in the shape of a -- rectangle (with jagged edges) that has 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 null and the list of indices -- will be null. rectTriGrid :: Int -> Int -> RectTriGrid -- | A toroidal 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 TorTriGrid TorTriGrid :: (Int, Int) -> [(Int, Int)] -> TorTriGrid -- | torTriGrid r c returns a toroidal grid with r -- rows and c columns, using triangular tiles. The indexing -- method is the same as for ParaTriGrid. If r and -- c are both nonnegative, the resulting grid will have -- 2*r*c tiles. Otherwise, the resulting grid will be null and -- the list of indices will be null. torTriGrid :: Int -> Int -> TorTriGrid -- | A cylindrical grid with triangular tiles, where the cylinder is along -- the y-axis. The grid and its indexing scheme are illustrated in the -- user guide, available at https://github.com/mhwombat/grid/wiki. data YCylTriGrid YCylTriGrid :: (Int, Int) -> [(Int, Int)] -> YCylTriGrid -- | yCylTriGrid r c returns a cylindrical grid with -- r rows and c columns, using triangular tiles, where -- the cylinder is along the y-axis. The indexing method is the same as -- for ParaTriGrid. If r and c are both -- nonnegative, the resulting grid will have 2*r*c tiles. -- Otherwise, the resulting grid will be null and the list of indices -- will be null. yCylTriGrid :: Int -> Int -> YCylTriGrid -- | A cylindrical grid with triangular tiles, where the cylinder is along -- the x-axis. The grid and its indexing scheme are illustrated in the -- user guide, available at https://github.com/mhwombat/grid/wiki. data XCylTriGrid XCylTriGrid :: (Int, Int) -> [(Int, Int)] -> XCylTriGrid -- | xCylTriGrid r c returns a cylindrical grid with -- r rows and c columns, using triangular tiles, where -- the cylinder is along the y-axis. The indexing method is the same as -- for ParaTriGrid. If r and c are both -- nonnegative, the resulting grid will have 2*r*c tiles. -- Otherwise, the resulting grid will be null and the list of indices -- will be null. xCylTriGrid :: Int -> Int -> XCylTriGrid instance GHC.Generics.Generic Math.Geometry.Grid.TriangularInternal.XCylTriGrid instance GHC.Classes.Eq Math.Geometry.Grid.TriangularInternal.XCylTriGrid instance GHC.Generics.Generic Math.Geometry.Grid.TriangularInternal.YCylTriGrid instance GHC.Classes.Eq Math.Geometry.Grid.TriangularInternal.YCylTriGrid instance GHC.Generics.Generic Math.Geometry.Grid.TriangularInternal.TorTriGrid instance GHC.Classes.Eq Math.Geometry.Grid.TriangularInternal.TorTriGrid instance GHC.Generics.Generic Math.Geometry.Grid.TriangularInternal.RectTriGrid instance GHC.Classes.Eq Math.Geometry.Grid.TriangularInternal.RectTriGrid instance GHC.Generics.Generic Math.Geometry.Grid.TriangularInternal.ParaTriGrid instance GHC.Classes.Eq Math.Geometry.Grid.TriangularInternal.ParaTriGrid instance GHC.Generics.Generic Math.Geometry.Grid.TriangularInternal.TriTriGrid instance GHC.Classes.Eq Math.Geometry.Grid.TriangularInternal.TriTriGrid instance GHC.Generics.Generic Math.Geometry.Grid.TriangularInternal.UnboundedTriGrid instance GHC.Show.Show Math.Geometry.Grid.TriangularInternal.UnboundedTriGrid instance GHC.Classes.Eq Math.Geometry.Grid.TriangularInternal.UnboundedTriGrid instance GHC.Generics.Generic Math.Geometry.Grid.TriangularInternal.TriDirection instance GHC.Classes.Eq Math.Geometry.Grid.TriangularInternal.TriDirection instance GHC.Show.Show Math.Geometry.Grid.TriangularInternal.TriDirection instance GHC.Show.Show Math.Geometry.Grid.TriangularInternal.XCylTriGrid instance Math.Geometry.GridInternal.Grid Math.Geometry.Grid.TriangularInternal.XCylTriGrid instance Math.Geometry.GridInternal.FiniteGrid Math.Geometry.Grid.TriangularInternal.XCylTriGrid instance Math.Geometry.GridInternal.WrappedGrid Math.Geometry.Grid.TriangularInternal.XCylTriGrid instance GHC.Show.Show Math.Geometry.Grid.TriangularInternal.YCylTriGrid instance Math.Geometry.GridInternal.Grid Math.Geometry.Grid.TriangularInternal.YCylTriGrid instance Math.Geometry.GridInternal.FiniteGrid Math.Geometry.Grid.TriangularInternal.YCylTriGrid instance Math.Geometry.GridInternal.WrappedGrid Math.Geometry.Grid.TriangularInternal.YCylTriGrid instance GHC.Show.Show Math.Geometry.Grid.TriangularInternal.TorTriGrid instance Math.Geometry.GridInternal.Grid Math.Geometry.Grid.TriangularInternal.TorTriGrid instance Math.Geometry.GridInternal.FiniteGrid Math.Geometry.Grid.TriangularInternal.TorTriGrid instance Math.Geometry.GridInternal.WrappedGrid Math.Geometry.Grid.TriangularInternal.TorTriGrid instance GHC.Show.Show Math.Geometry.Grid.TriangularInternal.RectTriGrid instance Math.Geometry.GridInternal.Grid Math.Geometry.Grid.TriangularInternal.RectTriGrid instance Math.Geometry.GridInternal.FiniteGrid Math.Geometry.Grid.TriangularInternal.RectTriGrid instance Math.Geometry.GridInternal.BoundedGrid Math.Geometry.Grid.TriangularInternal.RectTriGrid instance GHC.Show.Show Math.Geometry.Grid.TriangularInternal.ParaTriGrid instance Math.Geometry.GridInternal.Grid Math.Geometry.Grid.TriangularInternal.ParaTriGrid instance Math.Geometry.GridInternal.FiniteGrid Math.Geometry.Grid.TriangularInternal.ParaTriGrid instance Math.Geometry.GridInternal.BoundedGrid Math.Geometry.Grid.TriangularInternal.ParaTriGrid instance GHC.Show.Show Math.Geometry.Grid.TriangularInternal.TriTriGrid instance Math.Geometry.GridInternal.Grid Math.Geometry.Grid.TriangularInternal.TriTriGrid instance Math.Geometry.GridInternal.FiniteGrid Math.Geometry.Grid.TriangularInternal.TriTriGrid instance Math.Geometry.GridInternal.BoundedGrid Math.Geometry.Grid.TriangularInternal.TriTriGrid instance Math.Geometry.GridInternal.Grid Math.Geometry.Grid.TriangularInternal.UnboundedTriGrid -- | A regular arrangement of triangular tiles. The userguide, with -- illustrations, is available at -- https://github.com/mhwombat/grid/wiki. Also see -- Math.Geometry.Grid for examples of how to use this class. module Math.Geometry.Grid.Triangular -- | An unbounded 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 UnboundedTriGrid UnboundedTriGrid :: UnboundedTriGrid -- | 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 null 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 null and the list of indices will be null. paraTriGrid :: Int -> Int -> ParaTriGrid -- | A rectangular 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 RectTriGrid -- | rectTriGrid r c returns a grid in the shape of a -- rectangle (with jagged edges) that has 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 null and the list of indices -- will be null. rectTriGrid :: Int -> Int -> RectTriGrid -- | A toroidal 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 TorTriGrid -- | torTriGrid r c returns a toroidal grid with r -- rows and c columns, using triangular tiles. The indexing -- method is the same as for ParaTriGrid. If r and -- c are both nonnegative, the resulting grid will have -- 2*r*c tiles. Otherwise, the resulting grid will be null and -- the list of indices will be null. torTriGrid :: Int -> Int -> TorTriGrid -- | A cylindrical grid with triangular tiles, where the cylinder is along -- the y-axis. The grid and its indexing scheme are illustrated in the -- user guide, available at https://github.com/mhwombat/grid/wiki. data YCylTriGrid -- | yCylTriGrid r c returns a cylindrical grid with -- r rows and c columns, using triangular tiles, where -- the cylinder is along the y-axis. The indexing method is the same as -- for ParaTriGrid. If r and c are both -- nonnegative, the resulting grid will have 2*r*c tiles. -- Otherwise, the resulting grid will be null and the list of indices -- will be null. yCylTriGrid :: Int -> Int -> YCylTriGrid -- | A cylindrical grid with triangular tiles, where the cylinder is along -- the x-axis. The grid and its indexing scheme are illustrated in the -- user guide, available at https://github.com/mhwombat/grid/wiki. data XCylTriGrid -- | xCylTriGrid r c returns a cylindrical grid with -- r rows and c columns, using triangular tiles, where -- the cylinder is along the y-axis. The indexing method is the same as -- for ParaTriGrid. If r and c are both -- nonnegative, the resulting grid will have 2*r*c tiles. -- Otherwise, the resulting grid will be null and the list of indices -- will be null. xCylTriGrid :: Int -> Int -> XCylTriGrid -- | A module containing private SquareGrid internals. Most -- developers should use SquareGrid instead. This module is -- subject to change without notice. module Math.Geometry.Grid.SquareInternal data SquareDirection North :: SquareDirection East :: SquareDirection South :: SquareDirection West :: SquareDirection -- | An unbounded 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 UnboundedSquareGrid UnboundedSquareGrid :: UnboundedSquareGrid -- | 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 :: (Int, Int) -> [(Int, Int)] -> 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 -- null 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 :: (Int, Int) -> [(Int, Int)] -> 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 -- null and the list of indices will be null. torSquareGrid :: Int -> Int -> TorSquareGrid instance GHC.Generics.Generic Math.Geometry.Grid.SquareInternal.TorSquareGrid instance GHC.Classes.Eq Math.Geometry.Grid.SquareInternal.TorSquareGrid instance GHC.Generics.Generic Math.Geometry.Grid.SquareInternal.RectSquareGrid instance GHC.Classes.Eq Math.Geometry.Grid.SquareInternal.RectSquareGrid instance GHC.Generics.Generic Math.Geometry.Grid.SquareInternal.UnboundedSquareGrid instance GHC.Show.Show Math.Geometry.Grid.SquareInternal.UnboundedSquareGrid instance GHC.Classes.Eq Math.Geometry.Grid.SquareInternal.UnboundedSquareGrid instance GHC.Classes.Eq Math.Geometry.Grid.SquareInternal.SquareDirection instance GHC.Show.Show Math.Geometry.Grid.SquareInternal.SquareDirection instance GHC.Show.Show Math.Geometry.Grid.SquareInternal.TorSquareGrid instance Math.Geometry.GridInternal.Grid Math.Geometry.Grid.SquareInternal.TorSquareGrid instance Math.Geometry.GridInternal.FiniteGrid Math.Geometry.Grid.SquareInternal.TorSquareGrid instance Math.Geometry.GridInternal.WrappedGrid Math.Geometry.Grid.SquareInternal.TorSquareGrid instance GHC.Show.Show Math.Geometry.Grid.SquareInternal.RectSquareGrid instance Math.Geometry.GridInternal.Grid Math.Geometry.Grid.SquareInternal.RectSquareGrid instance Math.Geometry.GridInternal.FiniteGrid Math.Geometry.Grid.SquareInternal.RectSquareGrid instance Math.Geometry.GridInternal.BoundedGrid Math.Geometry.Grid.SquareInternal.RectSquareGrid instance Math.Geometry.GridInternal.Grid Math.Geometry.Grid.SquareInternal.UnboundedSquareGrid -- | A regular arrangement of square tiles. The userguide, with -- illustrations, is available at -- https://github.com/mhwombat/grid/wiki. Also see -- Math.Geometry.Grid for examples of how to use this class. module Math.Geometry.Grid.Square -- | An unbounded 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 UnboundedSquareGrid UnboundedSquareGrid :: UnboundedSquareGrid -- | 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 -- null 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 -- null and the list of indices will be null. torSquareGrid :: Int -> Int -> TorSquareGrid -- | A module containing private OctGrid internals. Most -- developers should use OctGrid instead. This module is subject -- to change without notice. module Math.Geometry.Grid.OctagonalInternal data OctDirection West :: OctDirection Northwest :: OctDirection North :: OctDirection Northeast :: OctDirection East :: OctDirection Southeast :: OctDirection South :: OctDirection Southwest :: OctDirection -- | An unbounded grid with octagonal tiles. The grid and its indexing -- scheme are illustrated in the user guide, available at -- https://github.com/mhwombat/grid/wiki. data UnboundedOctGrid UnboundedOctGrid :: UnboundedOctGrid -- | A rectangular grid with octagonal tiles. The grid and its indexing -- scheme are illustrated in the user guide, available at -- https://github.com/mhwombat/grid/wiki. data RectOctGrid RectOctGrid :: (Int, Int) -> [(Int, Int)] -> RectOctGrid -- | rectOctGrid r c produces a rectangular grid with -- r rows and c columns, using octagonal tiles. If -- r and c are both nonnegative, the resulting grid -- will have r*c tiles. Otherwise, the resulting grid will be -- null and the list of indices will be null. rectOctGrid :: Int -> Int -> RectOctGrid -- | A toroidal grid with octagonal tiles. The grid and its indexing scheme -- are illustrated in the user guide, available at -- https://github.com/mhwombat/grid/wiki. data TorOctGrid TorOctGrid :: (Int, Int) -> [(Int, Int)] -> TorOctGrid -- | torOctGrid r c returns a toroidal grid with r -- rows and c columns, using octagonal tiles. If r and -- c are both nonnegative, the resulting grid will have -- r*c tiles. Otherwise, the resulting grid will be null and the -- list of indices will be null. torOctGrid :: Int -> Int -> TorOctGrid instance GHC.Generics.Generic Math.Geometry.Grid.OctagonalInternal.TorOctGrid instance GHC.Classes.Eq Math.Geometry.Grid.OctagonalInternal.TorOctGrid instance GHC.Generics.Generic Math.Geometry.Grid.OctagonalInternal.RectOctGrid instance GHC.Classes.Eq Math.Geometry.Grid.OctagonalInternal.RectOctGrid instance GHC.Generics.Generic Math.Geometry.Grid.OctagonalInternal.UnboundedOctGrid instance GHC.Show.Show Math.Geometry.Grid.OctagonalInternal.UnboundedOctGrid instance GHC.Classes.Eq Math.Geometry.Grid.OctagonalInternal.UnboundedOctGrid instance GHC.Generics.Generic Math.Geometry.Grid.OctagonalInternal.OctDirection instance GHC.Classes.Eq Math.Geometry.Grid.OctagonalInternal.OctDirection instance GHC.Show.Show Math.Geometry.Grid.OctagonalInternal.OctDirection instance GHC.Show.Show Math.Geometry.Grid.OctagonalInternal.TorOctGrid instance Math.Geometry.GridInternal.Grid Math.Geometry.Grid.OctagonalInternal.TorOctGrid instance Math.Geometry.GridInternal.FiniteGrid Math.Geometry.Grid.OctagonalInternal.TorOctGrid instance Math.Geometry.GridInternal.WrappedGrid Math.Geometry.Grid.OctagonalInternal.TorOctGrid instance GHC.Show.Show Math.Geometry.Grid.OctagonalInternal.RectOctGrid instance Math.Geometry.GridInternal.Grid Math.Geometry.Grid.OctagonalInternal.RectOctGrid instance Math.Geometry.GridInternal.FiniteGrid Math.Geometry.Grid.OctagonalInternal.RectOctGrid instance Math.Geometry.GridInternal.BoundedGrid Math.Geometry.Grid.OctagonalInternal.RectOctGrid instance Math.Geometry.GridInternal.Grid Math.Geometry.Grid.OctagonalInternal.UnboundedOctGrid -- | A regular arrangement of octagonal tiles. Octagons won't tile a -- regular plane (there will be diamond-shaped gaps between the tiles), -- but they will tile a hyperbolic plane. (Alternatively, you can -- think of these as squares on a board game where diagonal moves are -- allowed.) The userguide, with illustrations, is available at -- https://github.com/mhwombat/grid/wiki. Also see -- Math.Geometry.Grid for examples of how to use this class. module Math.Geometry.Grid.Octagonal -- | An unbounded grid with octagonal tiles. The grid and its indexing -- scheme are illustrated in the user guide, available at -- https://github.com/mhwombat/grid/wiki. data UnboundedOctGrid UnboundedOctGrid :: UnboundedOctGrid -- | A rectangular grid with octagonal tiles. The grid and its indexing -- scheme are illustrated in the user guide, available at -- https://github.com/mhwombat/grid/wiki. data RectOctGrid -- | rectOctGrid r c produces a rectangular grid with -- r rows and c columns, using octagonal tiles. If -- r and c are both nonnegative, the resulting grid -- will have r*c tiles. Otherwise, the resulting grid will be -- null and the list of indices will be null. rectOctGrid :: Int -> Int -> RectOctGrid -- | A toroidal grid with octagonal tiles. The grid and its indexing scheme -- are illustrated in the user guide, available at -- https://github.com/mhwombat/grid/wiki. data TorOctGrid -- | torOctGrid r c returns a toroidal grid with r -- rows and c columns, using octagonal tiles. If r and -- c are both nonnegative, the resulting grid will have -- r*c tiles. Otherwise, the resulting grid will be null and the -- list of indices will be null. torOctGrid :: Int -> Int -> TorOctGrid -- | A module containing private HexGrid2 internals. Most -- developers should use HexGrid2 instead. This module is -- subject to change without notice. module Math.Geometry.Grid.HexagonalInternal2 data HexDirection Northwest :: HexDirection North :: HexDirection Northeast :: HexDirection Southeast :: HexDirection South :: HexDirection Southwest :: HexDirection -- | An unbounded 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 UnboundedHexGrid UnboundedHexGrid :: UnboundedHexGrid -- | 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 :: Int -> [(Int, Int)] -> 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 null and the list of -- indices will be null. hexHexGrid :: Int -> HexHexGrid -- | A rectangular 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 RectHexGrid RectHexGrid :: (Int, Int) -> [(Int, Int)] -> RectHexGrid -- | rectHexGrid 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 null and the list of indices will be null. rectHexGrid :: Int -> Int -> RectHexGrid rectHexGridY :: Int -> Int -> Int instance GHC.Generics.Generic Math.Geometry.Grid.HexagonalInternal2.RectHexGrid instance GHC.Classes.Eq Math.Geometry.Grid.HexagonalInternal2.RectHexGrid instance GHC.Generics.Generic Math.Geometry.Grid.HexagonalInternal2.HexHexGrid instance GHC.Classes.Eq Math.Geometry.Grid.HexagonalInternal2.HexHexGrid instance GHC.Generics.Generic Math.Geometry.Grid.HexagonalInternal2.UnboundedHexGrid instance GHC.Show.Show Math.Geometry.Grid.HexagonalInternal2.UnboundedHexGrid instance GHC.Classes.Eq Math.Geometry.Grid.HexagonalInternal2.UnboundedHexGrid instance GHC.Generics.Generic Math.Geometry.Grid.HexagonalInternal2.HexDirection instance GHC.Classes.Eq Math.Geometry.Grid.HexagonalInternal2.HexDirection instance GHC.Show.Show Math.Geometry.Grid.HexagonalInternal2.HexDirection instance GHC.Show.Show Math.Geometry.Grid.HexagonalInternal2.RectHexGrid instance Math.Geometry.GridInternal.Grid Math.Geometry.Grid.HexagonalInternal2.RectHexGrid instance Math.Geometry.GridInternal.FiniteGrid Math.Geometry.Grid.HexagonalInternal2.RectHexGrid instance Math.Geometry.GridInternal.BoundedGrid Math.Geometry.Grid.HexagonalInternal2.RectHexGrid instance GHC.Show.Show Math.Geometry.Grid.HexagonalInternal2.HexHexGrid instance Math.Geometry.GridInternal.Grid Math.Geometry.Grid.HexagonalInternal2.HexHexGrid instance Math.Geometry.GridInternal.FiniteGrid Math.Geometry.Grid.HexagonalInternal2.HexHexGrid instance Math.Geometry.GridInternal.BoundedGrid Math.Geometry.Grid.HexagonalInternal2.HexHexGrid instance Math.Geometry.GridInternal.Grid Math.Geometry.Grid.HexagonalInternal2.UnboundedHexGrid -- | Same as Hexagonal, except the grids are oriented so -- that the flat part of the hexagonal tiles is on the top. The -- userguide, with illustrations, is available at -- https://github.com/mhwombat/grid/wiki. Also see -- Math.Geometry.Grid for examples of how to use this class. module Math.Geometry.Grid.Hexagonal2 -- | An unbounded 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 UnboundedHexGrid UnboundedHexGrid :: UnboundedHexGrid -- | 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 null and the list of -- indices will be null. hexHexGrid :: Int -> HexHexGrid -- | A rectangular 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 RectHexGrid -- | rectHexGrid 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 null and the list of indices will be null. rectHexGrid :: Int -> Int -> RectHexGrid -- | A module containing private HexGrid internals. Most -- developers should use HexGrid instead. This module is subject -- to change without notice. module Math.Geometry.Grid.HexagonalInternal data HexDirection West :: HexDirection Northwest :: HexDirection Northeast :: HexDirection East :: HexDirection Southeast :: HexDirection Southwest :: HexDirection -- | An unbounded 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 UnboundedHexGrid UnboundedHexGrid :: UnboundedHexGrid -- | 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 :: Int -> [(Int, Int)] -> 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 null 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 :: (Int, Int) -> [(Int, Int)] -> 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 null and the list of indices will be null. paraHexGrid :: Int -> Int -> ParaHexGrid instance GHC.Generics.Generic Math.Geometry.Grid.HexagonalInternal.ParaHexGrid instance GHC.Classes.Eq Math.Geometry.Grid.HexagonalInternal.ParaHexGrid instance GHC.Generics.Generic Math.Geometry.Grid.HexagonalInternal.HexHexGrid instance GHC.Classes.Eq Math.Geometry.Grid.HexagonalInternal.HexHexGrid instance GHC.Generics.Generic Math.Geometry.Grid.HexagonalInternal.UnboundedHexGrid instance GHC.Classes.Eq Math.Geometry.Grid.HexagonalInternal.UnboundedHexGrid instance GHC.Show.Show Math.Geometry.Grid.HexagonalInternal.UnboundedHexGrid instance GHC.Generics.Generic Math.Geometry.Grid.HexagonalInternal.HexDirection instance GHC.Classes.Eq Math.Geometry.Grid.HexagonalInternal.HexDirection instance GHC.Show.Show Math.Geometry.Grid.HexagonalInternal.HexDirection instance GHC.Show.Show Math.Geometry.Grid.HexagonalInternal.ParaHexGrid instance Math.Geometry.GridInternal.Grid Math.Geometry.Grid.HexagonalInternal.ParaHexGrid instance Math.Geometry.GridInternal.FiniteGrid Math.Geometry.Grid.HexagonalInternal.ParaHexGrid instance Math.Geometry.GridInternal.BoundedGrid Math.Geometry.Grid.HexagonalInternal.ParaHexGrid instance GHC.Show.Show Math.Geometry.Grid.HexagonalInternal.HexHexGrid instance Math.Geometry.GridInternal.Grid Math.Geometry.Grid.HexagonalInternal.HexHexGrid instance Math.Geometry.GridInternal.FiniteGrid Math.Geometry.Grid.HexagonalInternal.HexHexGrid instance Math.Geometry.GridInternal.BoundedGrid Math.Geometry.Grid.HexagonalInternal.HexHexGrid instance Math.Geometry.GridInternal.Grid Math.Geometry.Grid.HexagonalInternal.UnboundedHexGrid -- | A regular arrangement of hexagonal tiles. The userguide, with -- illustrations, is available at -- https://github.com/mhwombat/grid/wiki. Also see -- Math.Geometry.Grid for examples of how to use this class. module Math.Geometry.Grid.Hexagonal -- | An unbounded 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 UnboundedHexGrid UnboundedHexGrid :: UnboundedHexGrid -- | 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 null 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 null and the list of indices will be null. paraHexGrid :: Int -> Int -> ParaHexGrid -- | A regular arrangement of tiles. Grids have a variety of uses, -- including games and self-organising maps. The userguide is available -- at https://github.com/mhwombat/grid/wiki. -- -- In this package, tiles are called "triangular", "square", etc., based -- on the number of neighbours they have. For example, a square -- tile has four neighbours, and a hexagonal tile has six. There are only -- three regular polygons that can tile a plane: triangles, squares, and -- hexagons. Of course, other plane tilings are possible if you use -- irregular polygons, or curved shapes, or if you combine tiles of -- different shapes. -- -- When you tile other surfaces, things get very interesting. Octagons -- will tile a hyperbolic plane. (Alternatively, you can think of -- these as squares on a board game where diagonal moves are allowed.) -- -- For a board game, you probably want to choose the grid type based on -- the number of directions a player can move, rather than the -- number of sides the tile will have when you display it. For example, -- for a game that uses square tiles and allows the user to move -- diagonally as well as horizontally and vertically, consider using one -- of the grids with octagonal tiles to model the board. You can -- still display the tiles as squares, but for internal -- calculations they are octagons. -- -- NOTE: Version 6.0 moved the various grid flavours to sub-modules. -- -- NOTE: Version 4.0 uses associated (type) synonyms instead of -- multi-parameter type classes. -- -- NOTE: Version 3.0 changed the order of parameters for many functions. -- This makes it easier for the user to write mapping and folding -- operations. module Math.Geometry.Grid -- | A regular arrangement of tiles. Minimal complete definition: -- Index, Direction, -- indices, distance, -- directionTo. class Grid g -- | Returns the indices of all tiles in a grid. indices :: Grid g => g -> [Index g] -- | 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. distance :: Grid g => g -> Index g -> Index g -> Int -- | 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. minDistance :: Grid g => g -> [Index g] -> Index g -> Int -- | neighbours g a returns the indices of the tiles in the -- grid g which are adjacent to the tile with index a. neighbours :: (Grid g, Eq (Index g)) => g -> Index g -> [Index g] -- | 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. neighbour :: (Grid g, Eq (Index g), Eq (Direction g)) => g -> Index g -> Direction g -> Maybe (Index g) -- | g `contains' a returns True if the index -- a is contained within the grid g, otherwise it -- returns false. contains :: (Grid g, Eq (Index g)) => g -> Index g -> Bool -- | Returns the number of tiles in a grid. Compare with -- size. tileCount :: Grid g => g -> Int -- | Returns True if the number of tiles in a grid is zero, -- False otherwise. null :: Grid g => g -> Bool -- | Returns False if the number of tiles in a grid is zero, -- True otherwise. nonNull :: Grid g => g -> Bool -- | A list of all edges in a grid, where the edges are represented by a -- pair of indices of adjacent tiles. edges :: (Grid g, Eq (Index g)) => g -> [(Index g, Index g)] -- | 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. viewpoint :: Grid g => g -> Index g -> [(Index g, Int)] -- | 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. isAdjacent :: Grid g => g -> Index g -> Index g -> Bool -- | 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. adjacentTilesToward :: (Grid g, Eq (Index g)) => g -> Index g -> Index g -> [Index g] -- | 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. minimalPaths :: (Grid g, Eq (Index g)) => g -> Index g -> Index g -> [[Index g]] -- | 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. directionTo :: Grid g => g -> Index g -> Index g -> [Direction g] -- | A regular arrangement of tiles where the number of tiles is finite. -- Minimal complete definition: size, -- maxPossibleDistance. class Grid g => FiniteGrid g where { type family Size g; } -- | 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 :: FiniteGrid g => g -> Size g -- | Returns the largest possible distance between two tiles in the grid. maxPossibleDistance :: FiniteGrid g => g -> Int -- | A regular arrangement of tiles with an edge. Minimal complete -- definition: tileSideCount. class Grid g => BoundedGrid g -- | Returns the number of sides a tile has tileSideCount :: BoundedGrid g => g -> Int -- | Returns a the indices of all the tiles at the boundary of a grid. boundary :: (BoundedGrid g, Eq (Index g)) => g -> [Index g] -- | 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.) isBoundary :: (BoundedGrid g, Eq (Index g)) => g -> Index g -> Bool -- | 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). centre :: (BoundedGrid g, Eq (Index g)) => g -> [Index g] -- | isCentre g a' returns True if the tile with -- index a is a centre tile of g, False -- otherwise. isCentre :: (BoundedGrid g, Eq (Index g)) => g -> Index g -> Bool defaultBoundary :: (BoundedGrid g, Eq (Index g)) => g -> [Index g] defaultIsBoundary :: (BoundedGrid g, Eq (Index g)) => g -> Index g -> Bool defaultCentre :: (BoundedGrid g, Eq (Index g)) => g -> [Index g] defaultIsCentre :: (BoundedGrid g, Eq (Index g)) => g -> Index g -> Bool -- | 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 regular arrangement of tiles, having a value associated with each -- tile. Minimal complete definition: toMap, toGrid, -- insertWithKey, delete, adjustWithKey, -- alter, mapWithKey, filterWithKey. -- -- Once a GridMap is created, the underlying grid is -- fixed; tiles cannot be added or removed. However, values can be -- added to empty tiles, and the value at a tile can be modified or -- removed. -- -- Note: Some of the methods have an Ord constraint on the grid -- index. This is purely to make it easier to write implementations. -- While tile positions can be ordered (e.g., (1,2) < (2,1)), -- the ordering may not be particularly meaningful. (Comparisons such as -- east of or south of may be more sensible.) However, it -- is convenient to write implementations of this class using -- Data.Map, with the grid indices as keys. Many of the -- functions in Data.Map impose the Ord constraint on -- map keys, so we'll live with it. In summary, to use some methods in -- this class, your grid indices must be orderable. class (Grid (BaseGrid gm v), Foldable gm) => GridMap (gm :: * -> *) v where { type family BaseGrid gm v; } -- | Find the value at a tile position in the grid. Calls error if the tile -- is not in the grid, or if the tile does not have an associated value. -- --
--   λ> let m = lazyGridMap (rectSquareGrid 1 2) ["red","blue"]
--   λ> m ! (0,0)
--   "red"
--   λ> m ! (0,5)
--   "*** Exception: Map.!: given key is not an element in the map
--   
(!) :: (GridMap gm v, k ~ (Index (BaseGrid gm v)), Ord k) => gm v -> k -> v -- | Returns a map of tile positions to values. -- --
--   λ> toMap $ lazyGridMap (rectSquareGrid 1 2) ["red", "blue"]
--   fromList [((0,0),"red"),((1,0),"blue")]
--   
toMap :: (GridMap gm v, k ~ (Index (BaseGrid gm v))) => gm v -> Map k v -- | Returns the grid on which this map is based. -- --
--   λ> toGrid $ lazyGridMap (rectSquareGrid 1 2) ["red", "blue"]
--   rectSquareGrid 1 2
--   
toGrid :: GridMap gm v => gm v -> BaseGrid gm v -- | Convert the map to a list of key/value pairs. -- --
--   λ> toList $ lazyGridMap (rectSquareGrid 1 2) ["red", "blue"]
--   [((0,0),"red"),((1,0),"blue")]
--   
toList :: (GridMap gm v, k ~ (Index (BaseGrid gm v))) => gm v -> [(k, v)] -- | The expression lookup k m returns the value contained -- in the tile at position k in the map m. If the tile -- does not contain a value, or is outside the map bounds, -- Nothing is returned. -- --
--   λ> let m = lazyGridMap (rectSquareGrid 1 2) ["red","blue"]
--   λ> Math.Geometry.GridMap.lookup (1,0) m
--   Just "blue"
--   λ> Math.Geometry.GridMap.lookup (5,5) m
--   Nothing
--   
lookup :: (GridMap gm v, k ~ (Index (BaseGrid gm v)), Ord k) => k -> gm v -> Maybe v -- | Insert a new value at a tile position in the grid map. If the tile -- already contains a value, the value is replaced. -- --
--   λ> insert (1,0) "hello" $ lazyGridMap (rectSquareGrid 1 2) ["red"]
--   lazyGridMap (rectSquareGrid 1 2) ["red","hello"]
--   λ> insert (1,0) "hello" $ lazyGridMap (rectSquareGrid 1 2) ["red","blue"]
--   lazyGridMap (rectSquareGrid 1 2) ["red","hello"]
--   λ> insert (5,5) "hello" $ lazyGridMap (rectSquareGrid 1 2) ["red","blue"]
--   lazyGridMap (rectSquareGrid 1 2) ["red","blue"]
--   
insert :: (GridMap gm v, k ~ (Index (BaseGrid gm v)), Ord k) => k -> v -> gm v -> gm v -- | The expression insertWith f k v m will insert the -- value v into the tile at position k if the tile does -- not already contain a value. If the tile does contain a value, it is -- replaced with f v old_value. If the tile is not within the -- bounds of the grid map, the original grid map is returned. -- --
--   λ> let m = lazyGridMap (rectSquareGrid 1 2) [100]
--   λ> insertWith (+) (0,0) 1 m
--   lazyGridMap (rectSquareGrid 1 2) [101]
--   λ> insertWith (+) (1,0) 1 m
--   lazyGridMap (rectSquareGrid 1 2) [100,1]
--   λ> insertWith (+) (5,5) 1 m
--   lazyGridMap (rectSquareGrid 1 2) [100]
--   
insertWith :: (GridMap gm v, k ~ (Index (BaseGrid gm v)), Ord k) => (v -> v -> v) -> k -> v -> gm v -> gm v -- | The expression insertWithKey f k v m will insert the -- value v into the tile at position k if the tile does -- not already contain a value. If the tile does contain a value, it is -- replaced with f k v old_value. If the tile is not within the -- bounds of the grid map, the original grid map is returned. -- --
--   λ> let m = lazyGridMap (rectSquareGrid 1 2) ["red"]
--   λ> let f k x y = show k ++ " " ++ x ++ y
--   λ> insertWithKey f (0,0) "dark" m
--   lazyGridMap (rectSquareGrid 1 2) ["(0,0) darkred"]
--   λ> insertWithKey f (1,0) "dark" m
--   lazyGridMap (rectSquareGrid 1 2) ["red","dark"]
--   λ> insertWithKey f (5,5) "dark" m
--   lazyGridMap (rectSquareGrid 1 2) ["red"]
--   
insertWithKey :: (GridMap gm v, k ~ (Index (BaseGrid gm v)), Ord k) => (k -> v -> v -> v) -> k -> v -> gm v -> gm v -- | Combines lookup with insertWithKey. -- The old value is returned, along with the updated map. insertLookupWithKey :: (GridMap gm v, k ~ (Index (BaseGrid gm v)), Ord k) => (k -> v -> v -> v) -> k -> v -> gm v -> (Maybe v, gm v) -- | Deletes the value at a tile position in the grid map. The tile is not -- removed from the grid. If the tile is not within the bounds of the -- grid map, the original grid map is returned. Note: Although this -- function may remove values, it never removes tiles from the underlying -- grid. -- --
--   λ> let m = lazyGridMap (rectSquareGrid 1 2) ["red"]
--   λ> delete (0,0) m
--   lazyGridMap (rectSquareGrid 1 2) []
--   λ> delete (1,0) m
--   lazyGridMap (rectSquareGrid 1 2) ["red"]
--   λ> delete (5,5) m
--   lazyGridMap (rectSquareGrid 1 2) ["red"]
--   
delete :: (GridMap gm v, k ~ (Index (BaseGrid gm v)), Ord k) => k -> gm v -> gm v -- | Adjust a value at a specific tile position. If the tile does not -- contain a value, or is not within the bounds of the grid map, the -- original grid map is returned. -- --
--   λ> let m = lazyGridMap (rectSquareGrid 1 2) ["world"]
--   λ> let f x = "hello " ++ x
--   λ> adjust f (0,0) m
--   lazyGridMap (rectSquareGrid 1 2) ["hello world"]
--   λ> adjust f (1,0) m
--   lazyGridMap (rectSquareGrid 1 2) ["world"]
--   λ> adjust f (5,5) m
--   lazyGridMap (rectSquareGrid 1 2) ["world"]
--   
adjust :: (GridMap gm v, k ~ (Index (BaseGrid gm v)), Ord k) => (v -> v) -> k -> gm v -> gm v -- | Adjust a value at a specific tile position. If the tile is not within -- the bounds of the grid map, the original grid map is returned. -- --
--   λ> let m = lazyGridMap (rectSquareGrid 1 2) ["world"]
--   λ> let f k x = "Hello, " ++ x ++ " from " ++ show k
--   λ> adjustWithKey f (0,0) m
--   lazyGridMap (rectSquareGrid 1 2) ["Hello, world from (0,0)"]
--   λ> adjustWithKey f (1,0) m
--   lazyGridMap (rectSquareGrid 1 2) ["world"]
--   λ> adjustWithKey f (5,5) m
--   lazyGridMap (rectSquareGrid 1 2) ["world"]
--   
adjustWithKey :: (GridMap gm v, k ~ (Index (BaseGrid gm v)), Ord k) => (k -> v -> v) -> k -> gm v -> gm v -- | The expression (alter f k map) alters the value at k, or absence -- thereof. If the tile is not within the bounds of the grid map, the -- original grid map is returned. Can be used to insert, delete, or -- update a value. Note: Although this function may remove values, it -- never removes tiles from the underlying grid. -- --
--   λ> let m = lazyGridMap (rectSquareGrid 1 2) ["red"]
--   λ> let f _ = Nothing
--   λ> alter f (1,0) m
--   lazyGridMap (rectSquareGrid 1 2) ["red"]
--   λ> alter f (0,0) m -- deleting a value
--   lazyGridMap (rectSquareGrid 1 2) []
--   λ> alter f (5,5) m
--   lazyGridMap (rectSquareGrid 1 2) ["red"]
--   λ> let f _ = Just "hi!"
--   λ> alter f (1,0) m -- inserting a value
--   lazyGridMap (rectSquareGrid 1 2) ["red","hi!"]
--   λ> alter f (0,0) m -- updating a value
--   lazyGridMap (rectSquareGrid 1 2) ["hi!"]
--   λ> alter f (5,5) m
--   lazyGridMap (rectSquareGrid 1 2) ["red"]
--   
alter :: (GridMap gm v, k ~ (Index (BaseGrid gm v)), Ord k) => (Maybe v -> Maybe v) -> k -> gm v -> gm v -- | 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. -- --
--   λ> let m = lazyGridMap (rectSquareGrid 1 2) ["red"]
--   λ> findWithDefault "yellow" (0,0) m
--   "red"
--   λ> findWithDefault "yellow" (1,0) m
--   "yellow"
--   λ> findWithDefault "yellow" (5,5) m
--   "yellow"
--   
findWithDefault :: (GridMap gm v, k ~ (Index (BaseGrid gm v)), Ord k) => v -> k -> gm v -> v -- | Returns the position of all tiles in the map that contain a value. To -- get a list of all tiles in the map regardless of whether or not they -- contain values, use indices. keys :: (GridMap gm v, k ~ (Index (BaseGrid gm v)), Ord k) => gm v -> [k] -- | Returns all values in the map. elems :: GridMap gm v => gm v -> [v] -- | Maps a function over all values in the map. -- --
--   λ> Math.Geometry.GridMap.map (++ "!") $ lazyGridMap (rectSquareGrid 1 3) ["red","blue"]
--   lazyGridMap (rectSquareGrid 1 3) ["red!","blue!"]
--   
map :: (GridMap gm v, GridMap gm v2, Index (BaseGrid gm v) ~ Index (BaseGrid gm v2)) => (v -> v2) -> gm v -> gm v2 -- | Maps a function over all values in the map. -- --
--   λ> let f k v = v ++ "@" ++ show k
--   λ> mapWithKey f $ lazyGridMap (rectSquareGrid 1 3) ["red","blue"]
--   lazyGridMap (rectSquareGrid 1 3) ["red@(0,0)","blue@(1,0)"]
--   
mapWithKey :: (GridMap gm v, k ~ Index (BaseGrid gm v), k ~ Index (BaseGrid gm v2), GridMap gm v2) => (k -> v -> v2) -> gm v -> gm v2 -- | Return a map containing only the values that satisfy the predicate. -- Note: Although this function may remove values, it never removes tiles -- from the underlying grid. -- --
--   λ> Math.Geometry.GridMap.filter (> 100) $ lazyGridMap (rectSquareGrid 1 4) [99, 100, 101, 102]
--   lazyGridMap (rectSquareGrid 1 4) [101,102]
--   
filter :: GridMap gm v => (v -> Bool) -> gm v -> gm v -- | Return a map containing only the values that satisfy the predicate, -- which may depend on a tile's index as well as its value. Note: -- Although this function may remove values, it never removes tiles from -- the underlying grid. -- --
--   λ> let f k v = k > (2,0) && v > 100
--   λ> filterWithKey f $ lazyGridMap (rectSquareGrid 1 4) [99, 100, 101, 102]
--   lazyGridMap (rectSquareGrid 1 4) [102]
--   
filterWithKey :: (GridMap gm v, k ~ (Index (BaseGrid gm v))) => (k -> v -> Bool) -> gm v -> gm v -- | O(n). Fold the values in the map using the given -- right-associative binary operator, such that foldr f z == -- foldr f z . elems. -- -- For example, -- --
--   elems map = foldr (:) [] map
--   
-- --
--   let f a len = len + (length a)
--   foldr f 0 (fromList [(5,"a"), (3,"bbb")]) == 4
--   
foldr :: () => a -> b -> b -> b -> Map k a -> b -- | O(n). A strict version of foldr. Each application of the -- operator is evaluated before using the result in the next application. -- This function is strict in the starting value. foldr' :: () => a -> b -> b -> b -> Map k a -> b -- | O(n). Fold the values in the map using the given -- left-associative binary operator, such that foldl f z == -- foldl f z . elems. -- -- For example, -- --
--   elems = reverse . foldl (flip (:)) []
--   
-- --
--   let f len a = len + (length a)
--   foldl f 0 (fromList [(5,"a"), (3,"bbb")]) == 4
--   
foldl :: () => a -> b -> a -> a -> Map k b -> a -- | O(n). A strict version of foldl. Each application of the -- operator is evaluated before using the result in the next application. -- This function is strict in the starting value. foldl' :: () => a -> b -> a -> a -> Map k b -> a -- | 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.Lazy -- | A map from tile positions in a grid to values. data LGridMap g v -- | Construct a grid map which is strict in the keys (tile positions), but -- lazy in the values. lazyGridMap :: (Ord (Index g), Grid g) => g -> [v] -> LGridMap g v lazyGridMapIndexed :: (Ord (Index g), Grid g) => g -> [((Index g), v)] -> LGridMap g v empty :: g -> LGridMap g v instance GHC.Generics.Generic (Math.Geometry.GridMap.Lazy.LGridMap g v) instance (Math.Geometry.GridInternal.Grid g, GHC.Classes.Ord (Math.Geometry.GridInternal.Index g)) => GHC.Base.Functor (Math.Geometry.GridMap.Lazy.LGridMap g) instance Data.Foldable.Foldable (Math.Geometry.GridMap.Lazy.LGridMap g) instance Math.Geometry.GridInternal.Grid g => Math.Geometry.GridInternal.Grid (Math.Geometry.GridMap.Lazy.LGridMap g v) instance Math.Geometry.GridInternal.FiniteGrid g => Math.Geometry.GridInternal.FiniteGrid (Math.Geometry.GridMap.Lazy.LGridMap g v) instance Math.Geometry.GridInternal.BoundedGrid g => Math.Geometry.GridInternal.BoundedGrid (Math.Geometry.GridMap.Lazy.LGridMap g v) instance Math.Geometry.GridInternal.WrappedGrid g => Math.Geometry.GridInternal.WrappedGrid (Math.Geometry.GridMap.Lazy.LGridMap g v) instance Math.Geometry.GridInternal.Grid g => Math.Geometry.GridMap.GridMap (Math.Geometry.GridMap.Lazy.LGridMap g) v instance (GHC.Classes.Eq g, GHC.Classes.Eq (Math.Geometry.GridInternal.Index g), GHC.Classes.Eq v) => GHC.Classes.Eq (Math.Geometry.GridMap.Lazy.LGridMap g v) instance (GHC.Show.Show g, GHC.Show.Show v) => GHC.Show.Show (Math.Geometry.GridMap.Lazy.LGridMap g v)