module Knots.Torus where
import Knots.PD
torusLink :: Int -> Int -> PD (Either Int Int)
torusLink m n = close m n $ concatMap (\i -> (map . fmap) (shift i) (turn m)) [0 .. (n1)]
where shift i (Left x) = Left (x + i*m)
shift i (Right x) = Right (x + i*m)
turn :: Int -> PD (Either Int Int)
turn m | m < 0 = mirror (turn ( m))
turn m | m == 1 = []
turn m | m == 2 = [ N (Left 1) (Left 3) (Left 2) (Left 0) ]
turn m | m >= 3 = [ N (Left $ 1) (Right $ 0) (Left $ m+0) (Left $ 0) ]
++ [ N (Left $ x+2) (Right $ x+1) (Left $ m+x+1) (Right $ x+0) | x <- [0..m4] ]
++ [ N (Left $ m1) (Left $ 2*m1) (Left $ 2*m2) (Right $ m3) ]
close m k = (map . fmap) (\case (Left i) -> if (im*k) >= 0 then Left (im*k) else Left i
other -> other)