advent-0.1.0.0: Advent of Code common library
Copyright(c) Eric Mertens 2018
LicenseISC
Maintaineremertens@gmail.com
Safe HaskellNone
LanguageHaskell2010

Advent.Coord

Description

2-dimensional coordinates commonly found in AoC problems where y grows down, x grows right.

   -y
    ↑
-x ←0→ +x
    ↓
   +y
Synopsis

Documentation

data Coord Source #

Two-dimensional coordinate

Constructors

C !Int !Int 

Instances

Instances details
HasTrie Coord Source # 
Instance details

Defined in Advent.Coord

Associated Types

newtype Coord :->: a 
Instance details

Defined in Advent.Coord

newtype Coord :->: a = CT (Int :->: (Int :->: a))

Methods

trie :: (Coord -> b) -> Coord :->: b #

untrie :: (Coord :->: b) -> Coord -> b #

enumerate :: (Coord :->: b) -> [(Coord, b)] #

Data Coord Source # 
Instance details

Defined in Advent.Coord

Methods

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 #

toConstr :: Coord -> Constr #

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 # 
Instance details

Defined in Advent.Coord

Associated Types

type Rep Coord 
Instance details

Defined in Advent.Coord

Methods

from :: Coord -> Rep Coord x #

to :: Rep Coord x -> Coord #

Ix Coord Source #

Row-major coordinate indexing

>>> range (C 1 1, C 2 2)
[C 1 1,C 1 2,C 2 1,C 2 2]
>>> index (C 1 1, C 2 2) <$> range (C 1 1, C 2 2)
[0,1,2,3]
Instance details

Defined in Advent.Coord

Num Coord Source #

Vector arithmetic

Instance details

Defined in Advent.Coord

Read Coord Source # 
Instance details

Defined in Advent.Coord

Show Coord Source # 
Instance details

Defined in Advent.Coord

Methods

showsPrec :: Int -> Coord -> ShowS #

show :: Coord -> String #

showList :: [Coord] -> ShowS #

Eq Coord Source # 
Instance details

Defined in Advent.Coord

Methods

(==) :: Coord -> Coord -> Bool #

(/=) :: Coord -> Coord -> Bool #

Ord Coord Source # 
Instance details

Defined in Advent.Coord

Methods

compare :: Coord -> Coord -> Ordering #

(<) :: Coord -> Coord -> Bool #

(<=) :: Coord -> Coord -> Bool #

(>) :: Coord -> Coord -> Bool #

(>=) :: Coord -> Coord -> Bool #

max :: Coord -> Coord -> Coord #

min :: Coord -> Coord -> Coord #

IArray UArray Coord Source # 
Instance details

Defined in Advent.Coord

Methods

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 # 
Instance details

Defined in Advent.Coord

Methods

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 # 
Instance details

Defined in Advent.Coord

Methods

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 # 
Instance details

Defined in Advent.Coord

newtype Coord :->: a = CT (Int :->: (Int :->: a))
type Rep Coord Source # 
Instance details

Defined in Advent.Coord

coordRow :: Coord -> Int Source #

Row (y) of coordinate

coordCol :: Coord -> Int Source #

Column (x) of coordinate

above :: Coord -> Coord Source #

Decrement y coordinate

below :: Coord -> Coord Source #

Increment y coordinate

left :: Coord -> Coord Source #

Decrement x coordinate

right :: Coord -> Coord Source #

Increment x coordinate

invert :: Coord -> Coord Source #

Swap x and y coordinates

invert' :: Coord -> Coord Source #

Swap x and y coordinates

flipX :: Coord -> Coord Source #

Invert the x coordinate

flipY :: Coord -> Coord Source #

Invert the y coordinate

turnLeft :: Coord -> Coord Source #

Rotate coordinate 90-degrees CCW about the origin

turnRight :: Coord -> Coord Source #

Rotate coordinate 90-degrees CW about the origin

turnAround :: Coord -> Coord Source #

Rotate the coordinate 180-degrees about the origin

manhattan :: Coord -> Coord -> Int Source #

Compute the Manhattan distance between two coordinates

norm1 :: Coord -> Int Source #

Compute 1-norm between two coordinates (sum of magnitudes)

normInf :: Coord -> Int Source #

Compute infinity-norm between two coordinates (max of magnitudes)

cardinal :: Coord -> [Coord] Source #

Compute the 4 cardinal neighbors of a coordinate: north, south, east, west

neighbors :: Coord -> [Coord] Source #

Compute the 8 cardinal neighbors and diagonal neighbors

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.

origin :: Coord Source #

Coordinate at the origin

north :: Coord Source #

Unit vector pointing up

east :: Coord Source #

Unit vector pointing right

south :: Coord Source #

Unit vector pointing down

west :: Coord Source #

Unit vector pointing left

scaleCoord :: Int -> Coord -> Coord Source #

Scale a coordinate as a vector from the origin

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.

mapCoord :: (Int -> Int) -> Coord -> Coord Source #

Apply a function to the y and x coordinate

zipCoord :: (Int -> Int -> Int) -> Coord -> Coord -> Coord Source #

Use a function pairwise on x and y coordinates of the two arguments

charToVec :: Char -> Maybe Coord Source #

Generate a unit vector corresponding to the arrow symbol: ^v<>