drawCirc :: Circuit -> Diagram B
drawCirc c = hsep 0.0 [ txt
                      , gs # centerX <> ls
                      , txt
                      ] # frame 1
  where gs = drawGates (gates c)
        ls = mconcat . map (mkLine.fromIntegral) $ [0..Circuit.size c]
          where mkLine y = ( hrule . width ) gs
                         # lwL lWidth
                         # lc grey
                         # translateY y
        txt = mconcat . zipWith placeText (lineNames c) $ map fromIntegral [0..length (lineNames c)]
          where placeText s y = (mkText s <> phantom (rect 4 1 :: D V2 Double))
                              # translateY y
                mkText s = text s
                         # fontSize (local 0.5)
        drawGates = hsep colSpace . map (mconcat . map drawGate) . getDrawCols
        drawGate g =
          case g of
            Not  t -> drawCnot (fromIntegral t) []
            Cnot c1 t -> drawCnot (fromIntegral t) [fromIntegral c1]
            Toff c1 c2 t -> drawCnot (fromIntegral t) $ map fromIntegral [c1,c2]
            Fred c1 t1 t2 -> drawSwap (fromIntegral t1) (fromIntegral t2) [fromIntegral c1]
            Swap t1 t2 -> drawSwap (fromIntegral t1) (fromIntegral t2) []
            Hadamard n -> drawH (fromIntegral n)
drawCirc :: Circuit -> Diagram B
drawCirc c = hsep 0.0 [ txt
                      , gs # centerX <> ls
                      , txt
                      ] # frame 1
  where gs = drawGates (gates c)
        ls = mconcat . map (mkLine.fromIntegral) $ [0..Circuit.size c]
          where mkLine y = ( hrule . width ) gs
                         # lwL lWidth
                         # lc grey
                         # translateY y
        txt = mconcat . zipWith placeText (lineNames c) $ map fromIntegral [0..length (lineNames c)]
          where placeText s y = (mkText s <> phantom (rect 4 1 :: D V2 Double))
                              # translateY y
                mkText s = text s
                         # fontSize (local 0.5)
        drawGates = hsep colSpace . map (mconcat . map drawGate) . getDrawCols
        drawGate g =
          case g of
            Not  t -> drawCnot (fromIntegral t) []
            Cnot c1 t -> drawCnot (fromIntegral t) [fromIntegral c1]
            Toff c1 c2 t -> drawCnot (fromIntegral t) $ map fromIntegral [c1,c2]
            Fred c1 t1 t2 -> drawSwap (fromIntegral t1) (fromIntegral t2) [fromIntegral c1]
            Swap t1 t2 -> drawSwap (fromIntegral t1) (fromIntegral t2) []
            Hadamard n -> drawH (fromIntegral n)
drawCirc c = hsep 0.0 [ txt
                      , gs # centerX <> ls
                      , txt
                      ] # frame 1
  where gs = drawGates (gates c)
        ls = mconcat . map (mkLine.fromIntegral) $ [0..Circuit.size c]
          where mkLine y = ( hrule . width ) gs
                         # lwL lWidth
                         # lc grey
                         # translateY y
        txt = mconcat . zipWith placeText (lineNames c) $ map fromIntegral [0..length (lineNames c)]
          where placeText s y = (mkText s <> phantom (rect 4 1 :: D V2 Double))
                              # translateY y
                mkText s = text s
                         # fontSize (local 0.5)
        drawGates = hsep colSpace . map (mconcat . map drawGate) . getDrawCols
        drawGate g =
          case g of
            Not  t -> drawCnot (fromIntegral t) []
            Cnot c1 t -> drawCnot (fromIntegral t) [fromIntegral c1]
            Toff c1 c2 t -> drawCnot (fromIntegral t) $ map fromIntegral [c1,c2]
            Fred c1 t1 t2 -> drawSwap (fromIntegral t1) (fromIntegral t2) [fromIntegral c1]
            Swap t1 t2 -> drawSwap (fromIntegral t1) (fromIntegral t2) []
            Hadamard n -> drawH (fromIntegral n)