never executed always true always false
1 module HelVM.HelMA.Automata.Piet.Types.Orientation
2 ( Orientation (..)
3 , codelChooser
4 , directionPointer
5 , furthest
6 , initialOrientation
7 , rotateDirectionPointer
8 , rotateToggle
9 , toggleCodelChooser
10 ) where
11
12 import HelVM.HelMA.Automata.Piet.Types.CodelChooser
13 import HelVM.HelMA.Automata.Piet.Types.Coordinates
14 import HelVM.HelMA.Automata.Piet.Types.DirectionPointer
15
16 import Lens.Micro ( (%~) )
17 import Lens.Micro.TH ( makeLenses )
18
19 data Orientation
20 = Orientation
21 { _directionPointer :: !DirectionPointer
22 , _codelChooser :: !CodelChooser
23 }
24
25 makeLenses ''Orientation
26
27 furthest ∷ Orientation → Coordinates → Coordinates → Ordering
28 furthest (Orientation DPLeft CCLeft) = flip (comparing fst) <> comparing snd
29 furthest (Orientation DPRight CCLeft) = comparing fst <> flip (comparing snd)
30 furthest (Orientation DPUp CCLeft) = flip (comparing snd <> comparing fst)
31 furthest (Orientation DPDown CCLeft) = comparing snd <> comparing fst
32 furthest (Orientation DPLeft CCRight) = flip (comparing fst <> comparing snd)
33 furthest (Orientation DPRight CCRight) = comparing fst <> comparing snd
34 furthest (Orientation DPUp CCRight) = flip (comparing snd) <> comparing fst
35 furthest (Orientation DPDown CCRight) = comparing snd <> flip (comparing fst)
36
37 rotateDirectionPointer ∷ Int → Orientation → Orientation
38 rotateDirectionPointer n = directionPointer %~ rotate n
39
40 toggleCodelChooser ∷ Int → Orientation → Orientation
41 toggleCodelChooser n = codelChooser %~ toggle n
42
43 rotateToggle ∷ Coordinates → Orientation → Orientation
44 rotateToggle (r, t) = rotateDirectionPointer r . toggleCodelChooser t
45
46 initialOrientation ∷ Orientation
47 initialOrientation = Orientation DPRight CCLeft