Copyright | (c) Justin Le 2020 |
---|---|
License | BSD3 |
Maintainer | justin@jle.im |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
Internal utility functions for Advent.OCR.
Synopsis
- data V2 a = V2 {}
- type Point = V2 Int
- parseLettersV2 :: LetterMap -> Set Point -> Maybe String
- parseLettersEitherV2 :: LetterMap -> Set Point -> Maybe [Either (Set Point) Char]
- parseAsciiMapV2 :: Set Char -> String -> Set Point
- newtype LetterMap = LetterMap {
- getLetterMap :: Map (Set Point) Char
- lookupLetterMap :: Set Point -> LetterMap -> Maybe Char
- defaultLetterMap :: LetterMap
- rawLetterforms1 :: (String, String)
- rawLetterforms2 :: (String, String)
- parseLetterMap :: [Char] -> String -> LetterMap
- contiguousShapes :: Set Point -> Map (V2 Double) (Set (Set Point))
- contiguousShapesBy :: Ord a => (V2 Double -> a) -> Set Point -> [Set Point]
Parse
Type used internally to represent points; useful for its Num
and
Applicative
instances.
Instances
Functor V2 Source # | |
Applicative V2 Source # | |
Lift a => Lift (V2 a :: Type) Source # | |
Eq a => Eq (V2 a) Source # | |
Fractional a => Fractional (V2 a) Source # | |
Data a => Data (V2 a) Source # | |
Defined in Advent.OCR.LetterMap gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> V2 a -> c (V2 a) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (V2 a) # dataTypeOf :: V2 a -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (V2 a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (V2 a)) # gmapT :: (forall b. Data b => b -> b) -> V2 a -> V2 a # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> V2 a -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> V2 a -> r # gmapQ :: (forall d. Data d => d -> u) -> V2 a -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> V2 a -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> V2 a -> m (V2 a) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> V2 a -> m (V2 a) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> V2 a -> m (V2 a) # | |
Num a => Num (V2 a) Source # | |
Ord a => Ord (V2 a) Source # | |
Show a => Show (V2 a) Source # | |
Generic (V2 a) Source # | |
type Rep (V2 a) Source # | |
Defined in Advent.OCR.LetterMap type Rep (V2 a) = D1 ('MetaData "V2" "Advent.OCR.LetterMap" "advent-of-code-ocr-0.1.0.0-9ILQdx7MbF3F1UZJWgl7dB" 'False) (C1 ('MetaCons "V2" 'PrefixI 'True) (S1 ('MetaSel ('Just "v2x") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 a) :*: S1 ('MetaSel ('Just "v2y") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 a))) |
parseLettersV2 :: LetterMap -> Set Point -> Maybe String Source #
A version of parseLetters
taking Point
. Used
internally.
parseLettersEitherV2 :: LetterMap -> Set Point -> Maybe [Either (Set Point) Char] Source #
A version of parseLettersEither
taking (and returning)
Point
. Used internally.
Parse raw ASCII art into a set of points, usable with
parseLettersV2
.
Letter Map
A database associating a set of "on" points to the letter they represent.
See defaultLetterMap
for a database compatible
with Advent of Code 2015-2019.
Instances
Eq LetterMap Source # | |
Data LetterMap Source # | |
Defined in Advent.OCR.LetterMap gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> LetterMap -> c LetterMap # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c LetterMap # toConstr :: LetterMap -> Constr # dataTypeOf :: LetterMap -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c LetterMap) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c LetterMap) # gmapT :: (forall b. Data b => b -> b) -> LetterMap -> LetterMap # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> LetterMap -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> LetterMap -> r # gmapQ :: (forall d. Data d => d -> u) -> LetterMap -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> LetterMap -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> LetterMap -> m LetterMap # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> LetterMap -> m LetterMap # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> LetterMap -> m LetterMap # | |
Ord LetterMap Source # | |
Defined in Advent.OCR.LetterMap | |
Show LetterMap Source # | |
Generic LetterMap Source # | |
Semigroup LetterMap Source # | |
Monoid LetterMap Source # | |
Default LetterMap Source # | Default is compatible with all challenges in Advent of Code 2015 to 2019. |
Defined in Advent.OCR.Internal | |
Lift LetterMap Source # | |
type Rep LetterMap Source # | |
Defined in Advent.OCR.LetterMap |
lookupLetterMap :: Set Point -> LetterMap -> Maybe Char Source #
Lookup a set of points for the letter it represents in a LetterMap
.
The set is expected to be aligned with (0,0) as the upper left corner of
its obunding box.
defaultLetterMap :: LetterMap Source #
The default lettermap compatible all challenges in Advent of Code 2015 - 2019.
rawLetterforms1 :: (String, String) Source #
Seen in 2016 Day 8, 2019 Day 8 and 11. 4x6 glyphs.
Load using uncurry
.parseLetterMap
rawLetterforms2 :: (String, String) Source #
Based on https://gist.github.com/usbpc/5fa0be48ad7b4b0594b3b8b029bc47b4. 6x10 glyphs.
Seen in 2018 Day 10.
Load using uncurry
.parseLetterMap
parseLetterMap :: [Char] -> String -> LetterMap Source #
Given a list of characters and ASCII art for all those characters
(from left to right), builds the appropriate LetterMap
.
An example usage would be:
parseLetterMap
ABC abcArt
where abcArt
is:
.##..###...##. #..#.#..#.#..# #..#.###..#... ####.#..#.#... #..#.#..#.#..# #..#.###...##.
Expects ASCII art where #
is the "on"/included character.
Utility
contiguousShapes :: Set Point -> Map (V2 Double) (Set (Set Point)) Source #
The set of unconnected shapes, indexed by their original center of mass
contiguousShapesBy :: Ord a => (V2 Double -> a) -> Set Point -> [Set Point] Source #
The set of unconnected shapes, sorted against some function on their original center of masses.