Skip to content

Commit a52dce7

Browse files
committed
[change] Draw vertical wires before horizontal wires
This improves the visualization when control wires are colored different from the horizontal ones.
1 parent 2b147f8 commit a52dce7

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

src/quantum-circuit.typ

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,30 @@
434434
return el.size.height
435435
}
436436

437+
438+
for (x, y, target, wire-style, labels) in vertical-wires {
439+
let dx = center-x-coords.at(x)
440+
let (dy1, dy2) = (center-y-coords.at(y), center-y-coords.at(y + target))
441+
dy1 += get-anchor-height(x, y) / 2 * signum(target)
442+
dy2 -= get-anchor-height(x, y + target) / 2 * signum(target)
443+
444+
if labels.len() == 0 {
445+
draw-functions.draw-vertical-wire(
446+
dy1, dy2, dx,
447+
utility.update-stroke(wire, wire-style.stroke),
448+
wire-count: wire-style.count,
449+
)
450+
} else {
451+
let (result, gate-bounds) = draw-functions.draw-vertical-wire-with-labels(
452+
dy1, dy2, dx,
453+
wire, wire-count: wire-style.count,
454+
wire-labels: labels,
455+
draw-params: draw-params
456+
)
457+
result
458+
bounds = layout.update-bounds(bounds, gate-bounds)
459+
}
460+
}
437461

438462

439463
for (row, wire-in) in wire-instructions.enumerate() {
@@ -473,30 +497,6 @@
473497
}
474498

475499

476-
for (x, y, target, wire-style, labels) in vertical-wires {
477-
let dx = center-x-coords.at(x)
478-
let (dy1, dy2) = (center-y-coords.at(y), center-y-coords.at(y + target))
479-
dy1 += get-anchor-height(x, y) / 2 * signum(target)
480-
dy2 -= get-anchor-height(x, y + target) / 2 * signum(target)
481-
482-
if labels.len() == 0 {
483-
draw-functions.draw-vertical-wire(
484-
dy1, dy2, dx,
485-
utility.update-stroke(wire, wire-style.stroke),
486-
wire-count: wire-style.count,
487-
)
488-
} else {
489-
let (result, gate-bounds) = draw-functions.draw-vertical-wire-with-labels(
490-
dy1, dy2, dx,
491-
wire, wire-count: wire-style.count,
492-
wire-labels: labels,
493-
draw-params: draw-params
494-
)
495-
result
496-
bounds = layout.update-bounds(bounds, gate-bounds)
497-
}
498-
}
499-
500500

501501
for gate-info in single-qubit-gates {
502502
let (gate, size, x, y) = gate-info

tests/wire/control-wires/ref/2.png

-5 Bytes
Loading

0 commit comments

Comments
 (0)