示例#1
0
def _render(diagram: circuits.TextDiagramDrawer) -> str:
    w = diagram.width()
    h = diagram.height()

    qwx = {(x, y + 1)
           for x, y1, y2 in diagram.vertical_lines for y in range(y1, y2)}

    qw = {(x, y)
          for y, x1, x2 in diagram.horizontal_lines for x in range(x1, x2)}

    rows = []
    for y in range(h):
        row = []
        for x in range(w):
            cell = []
            key = (x, y)
            v = diagram.entries.get(key)
            if v is not None:
                cell.append(' ' + v + ' ')
            if key in qw:
                cell.append('\\qw ')
            if key in qwx:
                cell.append('\\qwx ')
            row.append(''.join(cell))
        rows.append('&'.join(row) + '\qw')

    grid = '\\\\\n'.join(rows)

    output = '\Qcircuit @R=1em @C=0.75em { \\\\ \n' + grid + ' \\\\ \n \\\\ }'

    return output
示例#2
0
def _render(diagram: circuits.TextDiagramDrawer) -> str:
    w = diagram.width()
    h = diagram.height()

    qwx = {(x, y + 1)
           for x, y1, y2, _ in diagram.vertical_lines for y in range(y1, y2)}

    qw = {(x, y)
          for y, x1, x2, _ in diagram.horizontal_lines for x in range(x1, x2)}

    diagram2 = circuits.TextDiagramDrawer()
    for y in range(h):
        for x in range(max(0, w - 1)):
            key = (x, y)
            diagram_text = diagram.entries.get(key)
            v = '&' + (diagram_text.text if diagram_text else '') + ' '
            diagram2.write(2 * x + 1, y, v)
            post1 = '\\qw' if key in qw else ''
            post2 = '\\qwx' if key in qwx else ''
            diagram2.write(2 * x + 2, y, post1 + post2)
        diagram2.write(2 * w - 1, y, '&\\qw\\\\')
    grid = diagram2.render(horizontal_spacing=0, vertical_spacing=0)

    output = '\Qcircuit @R=1em @C=0.75em {\n \\\\\n' + grid + '\n \\\\\n}'

    return output
示例#3
0
def _render(diagram: circuits.TextDiagramDrawer) -> str:
    w = diagram.width()
    h = diagram.height()

    qwx = {(x, y + 1)
           for x, y1, y2, _ in diagram.vertical_lines
           for y in range(y1, y2)}

    qw = {(x, y)
          for y, x1, x2, _ in diagram.horizontal_lines
          for x in range(x1, x2)}

    rows = []
    for y in range(h):
        row = []
        for x in range(w):
            cell = []
            key = (x, y)
            v = diagram.entries.get(key)
            if v is not None:
                cell.append(' ' + v + ' ')
            if key in qw:
                cell.append('\\qw ')
            if key in qwx:
                cell.append('\\qwx ')
            row.append(''.join(cell))
        rows.append('&'.join(row) + '\qw')

    grid = '\\\\\n'.join(rows)

    output = '\Qcircuit @R=1em @C=0.75em { \\\\ \n' + grid + ' \\\\ \n \\\\ }'

    return output