Skip to content

Commit 5e3ce38

Browse files
committed
[add] possibility to specify negative values for gate groups, so that their end counts from the back/bottom.
Closes #36
1 parent 65a720b commit 5e3ce38

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

src/decorations.typ

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,11 +232,11 @@
232232
/// them.
233233
#let gategroup(
234234

235-
/// Number of wires to include.
235+
/// Number of wires to include. If negative, the end is counted from the back.
236236
/// -> int
237237
wires,
238238

239-
/// Number of columns to include.
239+
/// Number of columns to include. If negative, the end is counted from the bottom.
240240
/// -> int
241241
steps,
242242

src/quantum-circuit.typ

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,12 @@
365365
for (item, x, y) in meta-instructions {
366366
let (the-content, decoration-bounds) = (none, none)
367367
if item.qc-instr == "gategroup" {
368+
if item.steps < 0 {
369+
item.steps = num-cols - x + item.steps + 1
370+
}
371+
if item.wires < 0 {
372+
item.wires = num-rows - y + item.wires + 1
373+
}
368374
verifications.verify-gategroup(item, x, y, num-rows, num-cols)
369375
let (dy1, dy2) = layout.get-cell-coords(center-y-coords, row-heights, (y, y + item.wires - 1e-9))
370376
let (dx1, dx2) = layout.get-cell-coords(center-x-coords, col-widths, (x, x + item.steps - 1e-9))
1.34 KB
Loading

tests/decorations/gategroup/test.typ

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,14 @@
55
gategroup(1, 2, label: ((pos: top, content: "A"), (pos: left, content: "B")),), $K$, 1, 5pt, swap(), [\ ],
66
2, swap(-1),
77
gategroup(2, 1, x: 2, y: 0, label: "swap", stroke: .5pt + blue, radius: 4pt, fill: blue)
8+
)
9+
10+
#pagebreak()
11+
12+
13+
#quantum-circuit(
14+
gategroup(1, -1), $X$, $Y$, $p$, [\ ],
15+
gategroup(-1, -2), $X$, $Y$, $p$, [\ ],
16+
[\ ],
17+
gategroup(x: 2, y: 1, -2, 1)
818
)

0 commit comments

Comments
 (0)