{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-}
module XMonad.Layout.Dwindle (
Dwindle(..)
, Direction2D(..)
, Chirality(..)
) where
import XMonad.Prelude ( unfoldr )
import XMonad
import XMonad.StackSet ( integrate, Stack )
import XMonad.Util.Types ( Direction2D(..) )
data Dwindle a = Dwindle !Direction2D !Chirality !Rational !Rational
| Spiral !Direction2D !Chirality !Rational !Rational
| Squeeze !Direction2D !Rational !Rational
deriving (ReadPrec [Dwindle a]
ReadPrec (Dwindle a)
Int -> ReadS (Dwindle a)
ReadS [Dwindle a]
(Int -> ReadS (Dwindle a))
-> ReadS [Dwindle a]
-> ReadPrec (Dwindle a)
-> ReadPrec [Dwindle a]
-> Read (Dwindle a)
forall a. ReadPrec [Dwindle a]
forall a. ReadPrec (Dwindle a)
forall a. Int -> ReadS (Dwindle a)
forall a. ReadS [Dwindle a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: forall a. Int -> ReadS (Dwindle a)
readsPrec :: Int -> ReadS (Dwindle a)
$creadList :: forall a. ReadS [Dwindle a]
readList :: ReadS [Dwindle a]
$creadPrec :: forall a. ReadPrec (Dwindle a)
readPrec :: ReadPrec (Dwindle a)
$creadListPrec :: forall a. ReadPrec [Dwindle a]
readListPrec :: ReadPrec [Dwindle a]
Read, Int -> Dwindle a -> ShowS
[Dwindle a] -> ShowS
Dwindle a -> String
(Int -> Dwindle a -> ShowS)
-> (Dwindle a -> String)
-> ([Dwindle a] -> ShowS)
-> Show (Dwindle a)
forall a. Int -> Dwindle a -> ShowS
forall a. [Dwindle a] -> ShowS
forall a. Dwindle a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Int -> Dwindle a -> ShowS
showsPrec :: Int -> Dwindle a -> ShowS
$cshow :: forall a. Dwindle a -> String
show :: Dwindle a -> String
$cshowList :: forall a. [Dwindle a] -> ShowS
showList :: [Dwindle a] -> ShowS
Show)
data Chirality = CW | CCW
deriving (ReadPrec [Chirality]
ReadPrec Chirality
Int -> ReadS Chirality
ReadS [Chirality]
(Int -> ReadS Chirality)
-> ReadS [Chirality]
-> ReadPrec Chirality
-> ReadPrec [Chirality]
-> Read Chirality
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS Chirality
readsPrec :: Int -> ReadS Chirality
$creadList :: ReadS [Chirality]
readList :: ReadS [Chirality]
$creadPrec :: ReadPrec Chirality
readPrec :: ReadPrec Chirality
$creadListPrec :: ReadPrec [Chirality]
readListPrec :: ReadPrec [Chirality]
Read, Int -> Chirality -> ShowS
[Chirality] -> ShowS
Chirality -> String
(Int -> Chirality -> ShowS)
-> (Chirality -> String)
-> ([Chirality] -> ShowS)
-> Show Chirality
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Chirality -> ShowS
showsPrec :: Int -> Chirality -> ShowS
$cshow :: Chirality -> String
show :: Chirality -> String
$cshowList :: [Chirality] -> ShowS
showList :: [Chirality] -> ShowS
Show)
instance LayoutClass Dwindle a where
pureLayout :: Dwindle a -> Rectangle -> Stack a -> [(a, Rectangle)]
pureLayout (Dwindle Direction2D
dir Chirality
rot Ratio Integer
ratio Ratio Integer
_) = AxesGenerator
-> Direction2D
-> Chirality
-> Ratio Integer
-> Rectangle
-> Stack a
-> [(a, Rectangle)]
forall a.
AxesGenerator
-> Direction2D
-> Chirality
-> Ratio Integer
-> Rectangle
-> Stack a
-> [(a, Rectangle)]
dwindle AxesGenerator
alternate Direction2D
dir Chirality
rot Ratio Integer
ratio
pureLayout (Spiral Direction2D
dir Chirality
rot Ratio Integer
ratio Ratio Integer
_) = AxesGenerator
-> Direction2D
-> Chirality
-> Ratio Integer
-> Rectangle
-> Stack a
-> [(a, Rectangle)]
forall a.
AxesGenerator
-> Direction2D
-> Chirality
-> Ratio Integer
-> Rectangle
-> Stack a
-> [(a, Rectangle)]
dwindle AxesGenerator
rotate Direction2D
dir Chirality
rot Ratio Integer
ratio
pureLayout (Squeeze Direction2D
dir Ratio Integer
ratio Ratio Integer
_) = Direction2D
-> Ratio Integer -> Rectangle -> Stack a -> [(a, Rectangle)]
forall a.
Direction2D
-> Ratio Integer -> Rectangle -> Stack a -> [(a, Rectangle)]
squeeze Direction2D
dir Ratio Integer
ratio
pureMessage :: Dwindle a -> SomeMessage -> Maybe (Dwindle a)
pureMessage (Dwindle Direction2D
dir Chirality
rot Ratio Integer
ratio Ratio Integer
delta) =
(Ratio Integer -> Dwindle a)
-> Maybe (Ratio Integer) -> Maybe (Dwindle a)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\Ratio Integer
ratio' -> Direction2D
-> Chirality -> Ratio Integer -> Ratio Integer -> Dwindle a
forall a.
Direction2D
-> Chirality -> Ratio Integer -> Ratio Integer -> Dwindle a
Dwindle Direction2D
dir Chirality
rot Ratio Integer
ratio' Ratio Integer
delta) (Maybe (Ratio Integer) -> Maybe (Dwindle a))
-> (SomeMessage -> Maybe (Ratio Integer))
-> SomeMessage
-> Maybe (Dwindle a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ratio Integer
-> Ratio Integer -> SomeMessage -> Maybe (Ratio Integer)
changeRatio Ratio Integer
ratio Ratio Integer
delta
pureMessage (Spiral Direction2D
dir Chirality
rot Ratio Integer
ratio Ratio Integer
delta) =
(Ratio Integer -> Dwindle a)
-> Maybe (Ratio Integer) -> Maybe (Dwindle a)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\Ratio Integer
ratio' -> Direction2D
-> Chirality -> Ratio Integer -> Ratio Integer -> Dwindle a
forall a.
Direction2D
-> Chirality -> Ratio Integer -> Ratio Integer -> Dwindle a
Spiral Direction2D
dir Chirality
rot Ratio Integer
ratio' Ratio Integer
delta) (Maybe (Ratio Integer) -> Maybe (Dwindle a))
-> (SomeMessage -> Maybe (Ratio Integer))
-> SomeMessage
-> Maybe (Dwindle a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ratio Integer
-> Ratio Integer -> SomeMessage -> Maybe (Ratio Integer)
changeRatio Ratio Integer
ratio Ratio Integer
delta
pureMessage (Squeeze Direction2D
dir Ratio Integer
ratio Ratio Integer
delta) =
(Ratio Integer -> Dwindle a)
-> Maybe (Ratio Integer) -> Maybe (Dwindle a)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\Ratio Integer
ratio' -> Direction2D -> Ratio Integer -> Ratio Integer -> Dwindle a
forall a.
Direction2D -> Ratio Integer -> Ratio Integer -> Dwindle a
Squeeze Direction2D
dir Ratio Integer
ratio' Ratio Integer
delta) (Maybe (Ratio Integer) -> Maybe (Dwindle a))
-> (SomeMessage -> Maybe (Ratio Integer))
-> SomeMessage
-> Maybe (Dwindle a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ratio Integer
-> Ratio Integer -> SomeMessage -> Maybe (Ratio Integer)
changeRatio Ratio Integer
ratio Ratio Integer
delta
changeRatio :: Rational -> Rational -> SomeMessage -> Maybe Rational
changeRatio :: Ratio Integer
-> Ratio Integer -> SomeMessage -> Maybe (Ratio Integer)
changeRatio Ratio Integer
ratio Ratio Integer
delta = (Resize -> Ratio Integer) -> Maybe Resize -> Maybe (Ratio Integer)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Resize -> Ratio Integer
f (Maybe Resize -> Maybe (Ratio Integer))
-> (SomeMessage -> Maybe Resize)
-> SomeMessage
-> Maybe (Ratio Integer)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SomeMessage -> Maybe Resize
forall m. Message m => SomeMessage -> Maybe m
fromMessage
where f :: Resize -> Ratio Integer
f Resize
Expand = Ratio Integer
ratio Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Num a => a -> a -> a
* Ratio Integer
delta
f Resize
Shrink = Ratio Integer
ratio Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Fractional a => a -> a -> a
/ Ratio Integer
delta
dwindle :: AxesGenerator -> Direction2D -> Chirality -> Rational -> Rectangle -> Stack a ->
[(a, Rectangle)]
dwindle :: forall a.
AxesGenerator
-> Direction2D
-> Chirality
-> Ratio Integer
-> Rectangle
-> Stack a
-> [(a, Rectangle)]
dwindle AxesGenerator
trans Direction2D
dir Chirality
rot Ratio Integer
ratio Rectangle
rect Stack a
st = (([a], Rectangle, (Int, Int), Chirality)
-> Maybe ((a, Rectangle), ([a], Rectangle, (Int, Int), Chirality)))
-> ([a], Rectangle, (Int, Int), Chirality) -> [(a, Rectangle)]
forall b a. (b -> Maybe (a, b)) -> b -> [a]
unfoldr ([a], Rectangle, (Int, Int), Chirality)
-> Maybe ((a, Rectangle), ([a], Rectangle, (Int, Int), Chirality))
forall {a}.
([a], Rectangle, (Int, Int), Chirality)
-> Maybe ((a, Rectangle), ([a], Rectangle, (Int, Int), Chirality))
genRects (Stack a -> [a]
forall a. Stack a -> [a]
integrate Stack a
st, Rectangle
rect, Direction2D -> (Int, Int)
dirAxes Direction2D
dir, Chirality
rot)
where genRects :: ([a], Rectangle, (Int, Int), Chirality)
-> Maybe ((a, Rectangle), ([a], Rectangle, (Int, Int), Chirality))
genRects ([], Rectangle
_, (Int, Int)
_, Chirality
_ ) = Maybe ((a, Rectangle), ([a], Rectangle, (Int, Int), Chirality))
forall a. Maybe a
Nothing
genRects ([a
w], Rectangle
r, (Int, Int)
a, Chirality
rt) = ((a, Rectangle), ([a], Rectangle, (Int, Int), Chirality))
-> Maybe ((a, Rectangle), ([a], Rectangle, (Int, Int), Chirality))
forall a. a -> Maybe a
Just ((a
w, Rectangle
r), ([], Rectangle
r, (Int, Int)
a, Chirality
rt))
genRects (a
w:[a]
ws, Rectangle
r, (Int, Int)
a, Chirality
rt) = ((a, Rectangle), ([a], Rectangle, (Int, Int), Chirality))
-> Maybe ((a, Rectangle), ([a], Rectangle, (Int, Int), Chirality))
forall a. a -> Maybe a
Just ((a
w, Rectangle
r'), ([a]
ws, Rectangle
r'', (Int, Int)
a', Chirality
rt'))
where (Rectangle
r', Rectangle
r'') = Rectangle -> Ratio Integer -> (Int, Int) -> (Rectangle, Rectangle)
splitRect Rectangle
r Ratio Integer
ratio (Int, Int)
a
((Int, Int)
a', Chirality
rt') = AxesGenerator
trans (Int, Int)
a Chirality
rt
squeeze :: Direction2D -> Rational -> Rectangle -> Stack a -> [(a, Rectangle)]
squeeze :: forall a.
Direction2D
-> Ratio Integer -> Rectangle -> Stack a -> [(a, Rectangle)]
squeeze Direction2D
dir Ratio Integer
ratio Rectangle
rect Stack a
st = [a] -> [Rectangle] -> [(a, Rectangle)]
forall a b. [a] -> [b] -> [(a, b)]
zip [a]
wins [Rectangle]
rects
where wins :: [a]
wins = Stack a -> [a]
forall a. Stack a -> [a]
integrate Stack a
st
nwins :: Int
nwins = [a] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [a]
wins
sizes :: [Ratio Integer]
sizes = Int -> [Ratio Integer] -> [Ratio Integer]
forall a. Int -> [a] -> [a]
take Int
nwins ([Ratio Integer] -> [Ratio Integer])
-> [Ratio Integer] -> [Ratio Integer]
forall a b. (a -> b) -> a -> b
$ (Ratio Integer -> Maybe (Ratio Integer, Ratio Integer))
-> Ratio Integer -> [Ratio Integer]
forall b a. (b -> Maybe (a, b)) -> b -> [a]
unfoldr (\Ratio Integer
r -> (Ratio Integer, Ratio Integer)
-> Maybe (Ratio Integer, Ratio Integer)
forall a. a -> Maybe a
Just (Ratio Integer
r Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Num a => a -> a -> a
* Ratio Integer
ratio, Ratio Integer
r Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Num a => a -> a -> a
* Ratio Integer
ratio)) Ratio Integer
1
totals' :: [Ratio Integer]
totals' = Ratio Integer
0 Ratio Integer -> [Ratio Integer] -> [Ratio Integer]
forall a. a -> [a] -> [a]
: (Ratio Integer -> Ratio Integer -> Ratio Integer)
-> [Ratio Integer] -> [Ratio Integer] -> [Ratio Integer]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Num a => a -> a -> a
(+) [Ratio Integer]
sizes [Ratio Integer]
totals'
totals :: [Ratio Integer]
totals = Int -> [Ratio Integer] -> [Ratio Integer]
forall a. Int -> [a] -> [a]
drop Int
1 [Ratio Integer]
totals'
splits :: [(Ratio Integer, Ratio Integer)]
splits = [Ratio Integer]
-> [Ratio Integer] -> [(Ratio Integer, Ratio Integer)]
forall a b. [a] -> [b] -> [(a, b)]
zip (Int -> [Ratio Integer] -> [Ratio Integer]
forall a. Int -> [a] -> [a]
drop Int
1 [Ratio Integer]
sizes) [Ratio Integer]
totals
ratios :: [Ratio Integer]
ratios = [Ratio Integer] -> [Ratio Integer]
forall a. [a] -> [a]
reverse ([Ratio Integer] -> [Ratio Integer])
-> [Ratio Integer] -> [Ratio Integer]
forall a b. (a -> b) -> a -> b
$ ((Ratio Integer, Ratio Integer) -> Ratio Integer)
-> [(Ratio Integer, Ratio Integer)] -> [Ratio Integer]
forall a b. (a -> b) -> [a] -> [b]
map ((Ratio Integer -> Ratio Integer -> Ratio Integer)
-> (Ratio Integer, Ratio Integer) -> Ratio Integer
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Fractional a => a -> a -> a
(/)) [(Ratio Integer, Ratio Integer)]
splits
rects :: [Rectangle]
rects = Rectangle -> [Ratio Integer] -> [Rectangle]
genRects Rectangle
rect [Ratio Integer]
ratios
genRects :: Rectangle -> [Ratio Integer] -> [Rectangle]
genRects Rectangle
r [] = [Rectangle
r]
genRects Rectangle
r (Ratio Integer
x:[Ratio Integer]
xs) = Rectangle
r' Rectangle -> [Rectangle] -> [Rectangle]
forall a. a -> [a] -> [a]
: Rectangle -> [Ratio Integer] -> [Rectangle]
genRects Rectangle
r'' [Ratio Integer]
xs
where (Rectangle
r', Rectangle
r'') = Rectangle -> Ratio Integer -> (Int, Int) -> (Rectangle, Rectangle)
splitRect Rectangle
r Ratio Integer
x (Direction2D -> (Int, Int)
dirAxes Direction2D
dir)
splitRect :: Rectangle -> Rational -> Axes -> (Rectangle, Rectangle)
splitRect :: Rectangle -> Ratio Integer -> (Int, Int) -> (Rectangle, Rectangle)
splitRect (Rectangle Position
x Position
y Dimension
w Dimension
h) Ratio Integer
ratio (Int
ax, Int
ay) = (Position -> Position -> Dimension -> Dimension -> Rectangle
Rectangle Position
x' Position
y' Dimension
w' Dimension
h', Position -> Position -> Dimension -> Dimension -> Rectangle
Rectangle Position
x'' Position
y'' Dimension
w'' Dimension
h'')
where portion :: Ratio Integer
portion = Ratio Integer
ratio Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Fractional a => a -> a -> a
/ (Ratio Integer
ratio Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Num a => a -> a -> a
+ Ratio Integer
1)
w1 :: Int
w1 = (Ratio Integer -> Int
forall b. Integral b => Ratio Integer -> b
forall a b. (RealFrac a, Integral b) => a -> b
round (Ratio Integer -> Int) -> Ratio Integer -> Int
forall a b. (a -> b) -> a -> b
$ Dimension -> Ratio Integer
forall b a. (Num b, Integral a) => a -> b
fi Dimension
w Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Num a => a -> a -> a
* Ratio Integer
portion) :: Int
w2 :: Int
w2 = Dimension -> Int
forall b a. (Num b, Integral a) => a -> b
fi Dimension
w Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
w1
h1 :: Int
h1 = (Ratio Integer -> Int
forall b. Integral b => Ratio Integer -> b
forall a b. (RealFrac a, Integral b) => a -> b
round (Ratio Integer -> Int) -> Ratio Integer -> Int
forall a b. (a -> b) -> a -> b
$ Dimension -> Ratio Integer
forall b a. (Num b, Integral a) => a -> b
fi Dimension
h Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Num a => a -> a -> a
* Ratio Integer
portion) :: Int
h2 :: Int
h2 = Dimension -> Int
forall b a. (Num b, Integral a) => a -> b
fi Dimension
h Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
h1
x' :: Position
x' = Position
x Position -> Position -> Position
forall a. Num a => a -> a -> a
+ Int -> Position
forall b a. (Num b, Integral a) => a -> b
fi (Int -> Int
forall a. Num a => a -> a
negate Int
ax Int -> Int -> Int
forall a. Num a => a -> a -> a
* (Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
ax) Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
w2 Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
2)
y' :: Position
y' = Position
y Position -> Position -> Position
forall a. Num a => a -> a -> a
+ Int -> Position
forall b a. (Num b, Integral a) => a -> b
fi (Int -> Int
forall a. Num a => a -> a
negate Int
ay Int -> Int -> Int
forall a. Num a => a -> a -> a
* (Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
ay) Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
h2 Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
2)
w' :: Dimension
w' = Int -> Dimension
forall b a. (Num b, Integral a) => a -> b
fi (Int -> Dimension) -> Int -> Dimension
forall a b. (a -> b) -> a -> b
$ Int
w1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ (Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int -> Int
forall a. Num a => a -> a
abs Int
ax) Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
w2
h' :: Dimension
h' = Int -> Dimension
forall b a. (Num b, Integral a) => a -> b
fi (Int -> Dimension) -> Int -> Dimension
forall a b. (a -> b) -> a -> b
$ Int
h1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ (Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int -> Int
forall a. Num a => a -> a
abs Int
ay) Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
h2
x'' :: Position
x'' = Position
x Position -> Position -> Position
forall a. Num a => a -> a -> a
+ Int -> Position
forall b a. (Num b, Integral a) => a -> b
fi (Int
ax Int -> Int -> Int
forall a. Num a => a -> a -> a
* (Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
ax) Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
w1 Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
2)
y'' :: Position
y'' = Position
y Position -> Position -> Position
forall a. Num a => a -> a -> a
+ Int -> Position
forall b a. (Num b, Integral a) => a -> b
fi (Int
ay Int -> Int -> Int
forall a. Num a => a -> a -> a
* (Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
ay) Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
h1 Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
2)
w'' :: Dimension
w'' = Int -> Dimension
forall b a. (Num b, Integral a) => a -> b
fi (Int -> Dimension) -> Int -> Dimension
forall a b. (a -> b) -> a -> b
$ Int
w2 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ (Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int -> Int
forall a. Num a => a -> a
abs Int
ax) Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
w1
h'' :: Dimension
h'' = Int -> Dimension
forall b a. (Num b, Integral a) => a -> b
fi (Int -> Dimension) -> Int -> Dimension
forall a b. (a -> b) -> a -> b
$ Int
h2 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ (Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int -> Int
forall a. Num a => a -> a
abs Int
ay) Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
h1
fi :: (Num b, Integral a) => a -> b
fi :: forall b a. (Num b, Integral a) => a -> b
fi = a -> b
forall a b. (Integral a, Num b) => a -> b
fromIntegral
type Axes = (Int, Int)
type AxesGenerator = Axes -> Chirality -> (Axes, Chirality)
dirAxes :: Direction2D -> Axes
dirAxes :: Direction2D -> (Int, Int)
dirAxes Direction2D
L = (-Int
1, Int
0)
dirAxes Direction2D
R = ( Int
1, Int
0)
dirAxes Direction2D
U = ( Int
0, -Int
1)
dirAxes Direction2D
D = ( Int
0, Int
1)
alternate :: AxesGenerator
alternate :: AxesGenerator
alternate = (Chirality -> Chirality) -> AxesGenerator
chDir Chirality -> Chirality
alt
rotate :: AxesGenerator
rotate :: AxesGenerator
rotate = (Chirality -> Chirality) -> AxesGenerator
chDir Chirality -> Chirality
forall a. a -> a
id
chDir :: (Chirality -> Chirality) -> AxesGenerator
chDir :: (Chirality -> Chirality) -> AxesGenerator
chDir Chirality -> Chirality
f (Int
x, Int
y) Chirality
r = (Chirality -> (Int, Int)
a' Chirality
r, Chirality
r')
where a' :: Chirality -> (Int, Int)
a' Chirality
CW = (-Int
y, Int
x)
a' Chirality
CCW = ( Int
y, -Int
x)
r' :: Chirality
r' = Chirality -> Chirality
f Chirality
r
alt :: Chirality -> Chirality
alt :: Chirality -> Chirality
alt Chirality
CW = Chirality
CCW
alt Chirality
CCW = Chirality
CW