Copyright | (c) Eric Mertens 2018 |
---|---|
License | ISC |
Maintainer | emertens@gmail.com |
Safe Haskell | None |
Language | Haskell2010 |
2-dimensional coordinates commonly found in AoC problems where y grows down, x grows right.
-y ↑ -x ←0→ +x ↓ +y
Synopsis
- data Coord = C !Int !Int
- coordRow :: Coord -> Int
- coordCol :: Coord -> Int
- above :: Coord -> Coord
- below :: Coord -> Coord
- left :: Coord -> Coord
- right :: Coord -> Coord
- invert :: Coord -> Coord
- flipX :: Coord -> Coord
- flipY :: Coord -> Coord
- turnLeft :: Coord -> Coord
- turnRight :: Coord -> Coord
- turnAround :: Coord -> Coord
- manhattan :: Coord -> Coord -> Int
- cardinal :: Coord -> [Coord]
- neighbors :: Coord -> [Coord]
- boundingBox :: [Coord] -> Maybe (Coord, Coord)
- origin :: Coord
- north :: Coord
- east :: Coord
- south :: Coord
- west :: Coord
- addCoord :: Coord -> Coord -> Coord
- scaleCoord :: Int -> Coord -> Coord
- drawPicture :: Map Coord Char -> String
- drawCoords :: Foldable t => t Coord -> String
- coordLines :: [String] -> [(Coord, Char)]
- mapCoord :: (Int -> Int) -> Coord -> Coord
- zipCoord :: (Int -> Int -> Int) -> Coord -> Coord -> Coord
Documentation
Two-dimensional coordinate
Instances
Eq Coord Source # | |
Num Coord Source # | Paisewise treatment of coordinates |
Ord Coord Source # | |
Read Coord Source # | |
Show Coord Source # | |
Ix Coord Source # | Row-major coordinate indexing
|
Generic Coord Source # | |
HasTrie Coord Source # | |
type Rep Coord Source # | |
Defined in Advent.Coord type Rep Coord = D1 ('MetaData "Coord" "Advent.Coord" "advent2021-0.1.0.0-inplace" 'False) (C1 ('MetaCons "C" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Int) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Int))) | |
newtype Coord :->: a Source # | |
Defined in Advent.Coord |
turnAround :: Coord -> Coord Source #
Rotate the coordinate 180-degrees about the origin
cardinal :: Coord -> [Coord] Source #
Compute the 4 cardinal neighbors of a coordinate: north, south, east, west
boundingBox :: [Coord] -> Maybe (Coord, Coord) Source #
Find the upper-left and lower-right coordinates that inclusively contain all the coordinates in a list of coordinates.
drawPicture :: Map Coord Char -> String Source #
Render a minimal bounding box containing all the characters at the given coordinates. Empty space filled with space characters.
drawCoords :: Foldable t => t Coord -> String Source #
Render a minimal bounding box containing boxes at the given coordinates.