-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | QuadTree library for Haskell, with lens support. -- -- The purpose of this package is to provide discrete region quadtrees -- that can be used as effective functional alternatives to 2D arrays, -- with lens support. @package QuadTree @version 0.10.0 -- | The purpose of this module is to provide discrete region quadtrees -- that can be used as simple functional alternatives to 2D arrays, with -- lens support. -- --
--   test = set (atLocation (0,0)) 'd' $
--          set (atLocation (5,5)) 'c' $
--          set (atLocation (3,2)) 'b' $
--          set (atLocation (2,4)) 'a' $
--          makeTree (6,6) '.'
--   
-- --
--   >>> printTree id test
--   d.....
--   ......
--   ...b..
--   ......
--   ..a...
--   .....c
--   
module Data.QuadTree -- | The eponymous data type. -- -- QuadTree is itself a wrapper around an internal tree structure -- along with spatial metadata about the boundaries and depth of the 2D -- area it maps to. data QuadTree a -- | Constructor that generates a QuadTree of the given dimensions, -- with all cells filled with a default value. makeTree :: (Int, Int) -> a -> QuadTree a -- | Tuple corresponds to (X, Y) co-ordinates. type Location = (Int, Int) -- | Getter for the value at a given location for a QuadTree. getLocation :: Location -> QuadTree a -> a -- | Setter for the value at a given location for a QuadTree. -- -- This automatically compresses the QuadTree nodes if possible -- with the new value. setLocation :: Eq a => Location -> QuadTree a -> a -> QuadTree a -- | Lens for accessing and manipulating data at a specific location. -- -- This is simply getLocation and setLocation wrapped into -- a lens. atLocation :: Eq a => Location -> Lens' (QuadTree a) a -- | Cleanup function for use after any fmap. -- -- When elements of a QuadTree are modified by setLocation -- (or the atLocation lens), it automatically compresses identical -- adjacent nodes into larger ones. This keeps the QuadTree from -- bloating over constant use. -- -- fmap does not do this. If you wish to treat the QuadTree -- as a Functor, you should compose this function after to -- collapse it down to its minimum size. -- -- Example: fuseTree $ fmap fn tree This -- particular example is reified in the function below. fuseTree :: Eq a => QuadTree a -> QuadTree a -- | tmap is simply fmap with fuseTree applied after. -- --
--   tmap fn tree == fuseTree $ fmap fn tree
--   
tmap :: Eq b => (a -> b) -> QuadTree a -> QuadTree b -- | filters a list of the QuadTree 's elements. filterTree :: (a -> Bool) -> QuadTree a -> [a] -- | sortBys a list of the QuadTree 's elements. sortTreeBy :: (a -> a -> Ordering) -> QuadTree a -> [a] -- | Rectangular area, represented by a tuple of four Ints. -- -- They correspond to (X floor, Y floor, X ceiling, Y ceiling). -- -- The co-ordinates are inclusive of all the rows and columns in all four -- Ints. -- --
--   regionArea (x, y, x, y) == 1
--   
type Region = (Int, Int, Int, Int) -- | Each Tile is a tuple of an element from a QuadTree and -- the Region it subtends. type Tile a = (a, Region) -- | Returns a list of Tiles. The block equivalent of toList. tile :: QuadTree a -> [Tile a] -- | Takes a list of Tiles and then decomposes them into a list of -- all their elements, properly weighted by Tile size. expand :: [Tile a] -> [a] -- | Decomposes a QuadTree into its constituent Tiles, before -- folding a Tile consuming function over all of them. foldTiles :: (Tile a -> b -> b) -> b -> QuadTree a -> b -- | filters a list of the Tiles of a QuadTree. filterTiles :: (a -> Bool) -> [Tile a] -> [Tile a] -- | sortBys a list of the Tiles of a QuadTree. sortTilesBy :: (a -> a -> Ordering) -> [Tile a] -> [Tile a] -- | Generates a newline delimited string representing a QuadTree as -- a 2D block of characters. -- -- Note that despite the word show in the function name, this does -- not show the QuadTree. It pretty prints it. The name is -- simply a mnemonic for its QuadTree -> String -- behaviour. showTree :: (a -> Char) -> QuadTree a -> String -- | As showTree above, but also prints it. printTree :: (a -> Char) -> QuadTree a -> IO () -- | Checks if a Location is outside the boundaries of a -- QuadTree. outOfBounds :: QuadTree a -> Location -> Bool -- | Dimensions of a QuadTree, as an Int pair. treeDimensions :: QuadTree a -> (Int, Int) -- | Simple helper function that lets you calculate the area of a -- Region, usually for replicate purposes. regionArea :: Region -> Int -- | Does the region contain this location? inRegion :: Location -> Region -> Bool instance [safe] Show a => Show (Quadrant a) instance [safe] Read a => Read (Quadrant a) instance [safe] Show a => Show (QuadTree a) instance [safe] Read a => Read (QuadTree a) instance [safe] Functor Quadrant instance [safe] Foldable QuadTree instance [safe] Functor QuadTree