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
- invert' :: Coord -> Coord
- flipX :: Coord -> Coord
- flipY :: Coord -> Coord
- turnLeft :: Coord -> Coord
- turnRight :: Coord -> Coord
- turnAround :: Coord -> Coord
- manhattan :: Coord -> Coord -> Int
- norm1 :: Coord -> Int
- normInf :: Coord -> Int
- cardinal :: Coord -> [Coord]
- neighbors :: Coord -> [Coord]
- boundingBox :: Foldable f => f Coord -> Maybe (Coord, Coord)
- origin :: Coord
- north :: Coord
- east :: Coord
- south :: Coord
- west :: 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
- charToVec :: Char -> Maybe Coord
Documentation
Two-dimensional coordinate
Instances
HasTrie Coord Source # | |||||
Data Coord Source # | |||||
Defined in Advent.Coord gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Coord -> c Coord # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Coord # dataTypeOf :: Coord -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Coord) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Coord) # gmapT :: (forall b. Data b => b -> b) -> Coord -> Coord # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Coord -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Coord -> r # gmapQ :: (forall d. Data d => d -> u) -> Coord -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Coord -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Coord -> m Coord # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Coord -> m Coord # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Coord -> m Coord # | |||||
Generic Coord Source # | |||||
Defined in Advent.Coord
| |||||
Ix Coord Source # | Row-major coordinate indexing
| ||||
Num Coord Source # | Vector arithmetic | ||||
Read Coord Source # | |||||
Show Coord Source # | |||||
Eq Coord Source # | |||||
Ord Coord Source # | |||||
IArray UArray Coord Source # | |||||
Defined in Advent.Coord bounds :: Ix i => UArray i Coord -> (i, i) # numElements :: Ix i => UArray i Coord -> Int # unsafeArray :: Ix i => (i, i) -> [(Int, Coord)] -> UArray i Coord # unsafeAt :: Ix i => UArray i Coord -> Int -> Coord # unsafeReplace :: Ix i => UArray i Coord -> [(Int, Coord)] -> UArray i Coord # unsafeAccum :: Ix i => (Coord -> e' -> Coord) -> UArray i Coord -> [(Int, e')] -> UArray i Coord # unsafeAccumArray :: Ix i => (Coord -> e' -> Coord) -> Coord -> (i, i) -> [(Int, e')] -> UArray i Coord # | |||||
MArray IOUArray Coord IO Source # | |||||
Defined in Advent.Coord getBounds :: Ix i => IOUArray i Coord -> IO (i, i) # getNumElements :: Ix i => IOUArray i Coord -> IO Int # newArray :: Ix i => (i, i) -> Coord -> IO (IOUArray i Coord) # newArray_ :: Ix i => (i, i) -> IO (IOUArray i Coord) # unsafeNewArray_ :: Ix i => (i, i) -> IO (IOUArray i Coord) # unsafeRead :: Ix i => IOUArray i Coord -> Int -> IO Coord # unsafeWrite :: Ix i => IOUArray i Coord -> Int -> Coord -> IO () # | |||||
MArray (STUArray s) Coord (ST s) Source # | |||||
Defined in Advent.Coord getBounds :: Ix i => STUArray s i Coord -> ST s (i, i) # getNumElements :: Ix i => STUArray s i Coord -> ST s Int # newArray :: Ix i => (i, i) -> Coord -> ST s (STUArray s i Coord) # newArray_ :: Ix i => (i, i) -> ST s (STUArray s i Coord) # unsafeNewArray_ :: Ix i => (i, i) -> ST s (STUArray s i Coord) # unsafeRead :: Ix i => STUArray s i Coord -> Int -> ST s Coord # unsafeWrite :: Ix i => STUArray s i Coord -> Int -> Coord -> ST s () # | |||||
newtype Coord :->: a Source # | |||||
type Rep Coord Source # | |||||
Defined in Advent.Coord type Rep Coord = D1 ('MetaData "Coord" "Advent.Coord" "advent-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))) |
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 :: Foldable f => f 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.
coordLines :: [String] -> [(Coord, Char)] Source #
Given a list of lines pair up each character with its position.