aoc2020-0.1.0.0: Development environment for Advent of Code challenges
Safe HaskellNone
LanguageHaskell2010

AOC.Common.Point

Synopsis

Points

type Point = V2 Int Source #

2D Coordinate

type FinPoint n = V2 (Finite n) Source #

fullNeighbs :: (Applicative f, Num a, Traversable f) => f a -> [f a] Source #

fullNeighbsSet :: (Applicative f, Num a, Ord (f a), Traversable f) => f a -> Set (f a) Source #

mannDist :: (Foldable f, Num a, Num (f a)) => f a -> f a -> a Source #

mulPoint :: Num a => V2 a -> V2 a -> V2 a Source #

Treat as complex number multiplication. useful for rotations

lineTo :: Point -> Point -> [Point] Source #

Lattice points for line between points, not including endpoints

Directions

data Dir Source #

Constructors

North 
East 
South 
West 

Instances

Instances details
Enum Dir Source # 
Instance details

Defined in AOC.Common.Point

Methods

succ :: Dir -> Dir #

pred :: Dir -> Dir #

toEnum :: Int -> Dir #

fromEnum :: Dir -> Int #

enumFrom :: Dir -> [Dir] #

enumFromThen :: Dir -> Dir -> [Dir] #

enumFromTo :: Dir -> Dir -> [Dir] #

enumFromThenTo :: Dir -> Dir -> Dir -> [Dir] #

Eq Dir Source # 
Instance details

Defined in AOC.Common.Point

Methods

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

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

Ord Dir Source # 
Instance details

Defined in AOC.Common.Point

Methods

compare :: Dir -> Dir -> Ordering #

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

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

(>) :: Dir -> Dir -> Bool #

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

max :: Dir -> Dir -> Dir #

min :: Dir -> Dir -> Dir #

Show Dir Source # 
Instance details

Defined in AOC.Common.Point

Methods

showsPrec :: Int -> Dir -> ShowS #

show :: Dir -> String #

showList :: [Dir] -> ShowS #

Generic Dir Source # 
Instance details

Defined in AOC.Common.Point

Associated Types

type Rep Dir :: Type -> Type #

Methods

from :: Dir -> Rep Dir x #

to :: Rep Dir x -> Dir #

Semigroup Dir Source #

<> is mulDir.

Instance details

Defined in AOC.Common.Point

Methods

(<>) :: Dir -> Dir -> Dir #

sconcat :: NonEmpty Dir -> Dir #

stimes :: Integral b => b -> Dir -> Dir #

Monoid Dir Source # 
Instance details

Defined in AOC.Common.Point

Methods

mempty :: Dir #

mappend :: Dir -> Dir -> Dir #

mconcat :: [Dir] -> Dir #

NFData Dir Source # 
Instance details

Defined in AOC.Common.Point

Methods

rnf :: Dir -> () #

Hashable Dir Source # 
Instance details

Defined in AOC.Common.Point

Methods

hashWithSalt :: Int -> Dir -> Int

hash :: Dir -> Int

Finitary Dir Source # 
Instance details

Defined in AOC.Common.Point

Associated Types

type Cardinality Dir :: Nat

Methods

fromFinite :: Finite (Cardinality Dir) -> Dir

toFinite :: Dir -> Finite (Cardinality Dir)

start :: Dir

end :: Dir

previous :: Dir -> Maybe Dir

next :: Dir -> Maybe Dir

Abelian Dir Source # 
Instance details

Defined in AOC.Common.Point

Group Dir Source # 
Instance details

Defined in AOC.Common.Point

Methods

invert :: Dir -> Dir

(~~) :: Dir -> Dir -> Dir

pow :: Integral x => Dir -> x -> Dir

type Rep Dir Source # 
Instance details

Defined in AOC.Common.Point

type Rep Dir = D1 ('MetaData "Dir" "AOC.Common.Point" "aoc2020-0.1.0.0-FyPlSv9LBbs5G4MoObRXVm" 'False) ((C1 ('MetaCons "North" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "East" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "South" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "West" 'PrefixI 'False) (U1 :: Type -> Type)))
type Cardinality Dir Source # 
Instance details

Defined in AOC.Common.Point

type Cardinality Dir = GCardinality (Rep Dir)

dirPoint :: Num a => Dir -> V2 a Source #

dirPoint' :: Num a => Dir -> V2 a Source #

dirPoint but with inverted y axis

rotPoint :: Num a => Dir -> V2 a -> V2 a Source #

Rotate a point by a direction

rotFin :: KnownNat n => Dir -> FinPoint n -> FinPoint n Source #

Rotate a point by a direction

mulDir :: Dir -> Dir -> Dir Source #

Multiply headings, taking North as straight, East as clockwise turn, West as counter-clockwise turn, and South as reverse.

Should be a commutative group; it's essentially complex number multiplication like mulPoint, with North = 1, West = i. The identity is North and the inverse is the opposite direction.

Orientations

data D8 Source #

Represents an orientation of a 2d tile.

Constructors

D8 

Fields

Instances

Instances details
Eq D8 Source # 
Instance details

Defined in AOC.Common.Point

Methods

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

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

Ord D8 Source # 
Instance details

Defined in AOC.Common.Point

Methods

compare :: D8 -> D8 -> Ordering #

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

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

(>) :: D8 -> D8 -> Bool #

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

max :: D8 -> D8 -> D8 #

min :: D8 -> D8 -> D8 #

Show D8 Source # 
Instance details

Defined in AOC.Common.Point

Methods

showsPrec :: Int -> D8 -> ShowS #

show :: D8 -> String #

showList :: [D8] -> ShowS #

Generic D8 Source # 
Instance details

Defined in AOC.Common.Point

Associated Types

type Rep D8 :: Type -> Type #

Methods

from :: D8 -> Rep D8 x #

to :: Rep D8 x -> D8 #

Semigroup D8 Source #

<> is mulDir.

Instance details

Defined in AOC.Common.Point

Methods

(<>) :: D8 -> D8 -> D8 #

sconcat :: NonEmpty D8 -> D8 #

stimes :: Integral b => b -> D8 -> D8 #

Monoid D8 Source # 
Instance details

Defined in AOC.Common.Point

Methods

mempty :: D8 #

mappend :: D8 -> D8 -> D8 #

mconcat :: [D8] -> D8 #

NFData D8 Source # 
Instance details

Defined in AOC.Common.Point

Methods

rnf :: D8 -> () #

Hashable D8 Source # 
Instance details

Defined in AOC.Common.Point

Methods

hashWithSalt :: Int -> D8 -> Int

hash :: D8 -> Int

Finitary D8 Source # 
Instance details

Defined in AOC.Common.Point

Associated Types

type Cardinality D8 :: Nat

Methods

fromFinite :: Finite (Cardinality D8) -> D8

toFinite :: D8 -> Finite (Cardinality D8)

start :: D8

end :: D8

previous :: D8 -> Maybe D8

next :: D8 -> Maybe D8

Group D8 Source # 
Instance details

Defined in AOC.Common.Point

Methods

invert :: D8 -> D8

(~~) :: D8 -> D8 -> D8

pow :: Integral x => D8 -> x -> D8

type Rep D8 Source # 
Instance details

Defined in AOC.Common.Point

type Rep D8 = D1 ('MetaData "D8" "AOC.Common.Point" "aoc2020-0.1.0.0-FyPlSv9LBbs5G4MoObRXVm" 'False) (C1 ('MetaCons "D8" 'PrefixI 'True) (S1 ('MetaSel ('Just "d8Rot") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Dir) :*: S1 ('MetaSel ('Just "d8Flip") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Bool)))
type Cardinality D8 Source # 
Instance details

Defined in AOC.Common.Point

type Cardinality D8 = GCardinality (Rep D8)

mulD8 :: D8 -> D8 -> D8 Source #

a mulD8 b represents applying b, then a.

orientPoint :: Num a => D8 -> V2 a -> V2 a Source #

Rotate and flip a point by a D8

2D Maps

boundingBox :: (Foldable1 f, Applicative g, Ord a) => f (g a) -> V2 (g a) Source #

Find the minimum and maximum x and y from a collection of points.

Returns V2 (V2 xMin yMin) (V2 xMax yMax).

boundingBox' :: (Foldable f, Applicative g, Ord a) => f (g a) -> Maybe (V2 (g a)) Source #

A version of boundingBox that works for normal possibly-empty lists.

inBoundingBox :: (Applicative g, Foldable g, Ord a) => V2 (g a) -> g a -> Bool Source #

minCorner :: (Foldable1 f, Applicative g, Ord a) => f (g a) -> g a Source #

minCorner' :: (Foldable f, Applicative g, Ord a) => f (g a) -> Maybe (g a) Source #

shiftToZero :: (Applicative f, Num a, Ord a) => NESet (f a) -> NESet (f a) Source #

Shift corner to (0,0)

shiftToZero' :: (Applicative f, Num a, Ord a) => Set (f a) -> Set (f a) Source #

Shift corner to (0,0)

newtype ScanPoint Source #

It's Point, but with a newtype wrapper so we have an Ord that sorts by y first, then x

Constructors

SP 

Fields

Instances

Instances details
Eq ScanPoint Source # 
Instance details

Defined in AOC.Common.Point

Num ScanPoint Source # 
Instance details

Defined in AOC.Common.Point

Ord ScanPoint Source # 
Instance details

Defined in AOC.Common.Point

Show ScanPoint Source # 
Instance details

Defined in AOC.Common.Point

Generic ScanPoint Source # 
Instance details

Defined in AOC.Common.Point

Associated Types

type Rep ScanPoint :: Type -> Type #

NFData ScanPoint Source # 
Instance details

Defined in AOC.Common.Point

Methods

rnf :: ScanPoint -> () #

Hashable ScanPoint Source # 
Instance details

Defined in AOC.Common.Point

type Rep ScanPoint Source # 
Instance details

Defined in AOC.Common.Point

type Rep ScanPoint = D1 ('MetaData "ScanPoint" "AOC.Common.Point" "aoc2020-0.1.0.0-FyPlSv9LBbs5G4MoObRXVm" 'True) (C1 ('MetaCons "SP" 'PrefixI 'True) (S1 ('MetaSel ('Just "_getSP") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Point)))

displayAsciiMap Source #

Arguments

:: Char

default tile

-> Map Point Char

tile map

-> String 

displayAsciiSet Source #

Arguments

:: Char

missing tile

-> Char

present tile

-> Set Point

tile set

-> String 

Util

Orphan instances

(Finitary a, KnownNat (Cardinality a), KnownNat (Cardinality a * Cardinality a)) => Finitary (V2 a) Source # 
Instance details

Associated Types

type Cardinality (V2 a) :: Nat

Methods

fromFinite :: Finite (Cardinality (V2 a)) -> V2 a

toFinite :: V2 a -> Finite (Cardinality (V2 a))

start :: V2 a

end :: V2 a

previous :: V2 a -> Maybe (V2 a)

next :: V2 a -> Maybe (V2 a)

(Finitary a, KnownNat (Cardinality a), KnownNat (Cardinality a * (Cardinality a * Cardinality a))) => Finitary (V3 a) Source # 
Instance details

Associated Types

type Cardinality (V3 a) :: Nat

Methods

fromFinite :: Finite (Cardinality (V3 a)) -> V3 a

toFinite :: V3 a -> Finite (Cardinality (V3 a))

start :: V3 a

end :: V3 a

previous :: V3 a -> Maybe (V3 a)

next :: V3 a -> Maybe (V3 a)

(Finitary a, KnownNat (Cardinality a), KnownNat ((Cardinality a * Cardinality a) * (Cardinality a * Cardinality a))) => Finitary (V4 a) Source # 
Instance details

Associated Types

type Cardinality (V4 a) :: Nat

Methods

fromFinite :: Finite (Cardinality (V4 a)) -> V4 a

toFinite :: V4 a -> Finite (Cardinality (V4 a))

start :: V4 a

end :: V4 a

previous :: V4 a -> Maybe (V4 a)

next :: V4 a -> Maybe (V4 a)