module Math.Combinat.Diagrams.LatticePaths where
import Math.Combinat.LatticePaths
import Linear.Vector
import Data.Colour
import Diagrams.Core
import Diagrams.Prelude
data LatticeConvention
= Hilly
| UpRight
deriving (Eq,Show)
drawLatticePath :: Renderable (Path V2 Double) b => LatticePath -> QDiagram b V2 Double Any
drawLatticePath = drawLatticePath' Hilly red True
drawLatticePath'
:: Renderable (Path V2 Double) b
=> LatticeConvention
-> Colour Double
-> Bool
-> LatticePath
-> QDiagram b V2 Double Any
drawLatticePath' convention color hasgrid xs =
if hasgrid
then path <> grid
else path
where
linewidth = 0.025
path = path0 # lwL (linewidth*2) # lc color
grid = grid0 # lwL (linewidth )
path0 = fromOffsets [ case p of { UpStep -> up ; DownStep -> dn } | p <- xs ]
grid0 = case convention of
Hilly -> drawRectangularGrid (length xs, pathHeight xs)
UpRight -> drawRectangularGrid (b,a)
(a,b) = pathNumberOfUpDownSteps xs
(up,dn) = case convention of
Hilly -> ( r2 (1,1) , r2 (1,1) )
UpRight -> ( r2 (0,1) , r2 (1, 0) )
drawRectangularGrid :: Renderable (Path V2 Double) b => (Int,Int) -> QDiagram b V2 Double Any
drawRectangularGrid (x,y) = grid # lc grey where
grid = horiz <> vert
horiz = mconcat [ translateY (fromIntegral i) hline | i<-[0..y] ]
vert = mconcat [ translateX (fromIntegral j) vline | j<-[0..x] ]
hline = fromOffsets [ (fromIntegral x) *^ unitX ]
vline = fromOffsets [ (fromIntegral y) *^ unitY ]