Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/decorations.typ
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@

// align: "left" (for rstick) or "right" (for lstick)
// brace: auto, none, "{", "}", "|", "[", ...
#let lrstick(content, n, align, brace, label, pad: 0pt, x: auto, y: auto) = gate(
#let lrstick(content, n, align, brace, label, pad: 0pt, x: auto, y: auto, fill: auto) = gate(
content,
x: x,
y: y,
draw-function: draw-functions.draw-lrstick,
size-hint: layout.lrstick-size-hint,
box: false,
fill: fill,
floating: true,
multi: if n == 1 { none } else {
(
Expand Down Expand Up @@ -64,6 +65,10 @@
/// -> length
pad: 0pt,

/// How to color the brace.
/// -> auto | color
fill: auto,

/// One or more labels to add to the gate. See @gate.label.
/// -> none | array | str | content | dictionary
label: none,
Expand All @@ -72,7 +77,7 @@

y: auto

) = lrstick(body, n, right, brace, label, pad: pad, x: x, y: y)
) = lrstick(body, n, right, brace, label, pad: pad, x: x, y: y, fill: fill)



Expand Down Expand Up @@ -109,6 +114,10 @@
/// -> length
pad: 0pt,

/// How to color the brace.
/// -> auto | color
fill: auto,

/// One or more labels to add to the gate. See @gate.
/// -> none | array | str | content | dictionary
label: none,
Expand All @@ -117,7 +126,7 @@

y: auto

) = lrstick(body, n, left, brace, label, pad: pad, x: x, y: y)
) = lrstick(body, n, left, brace, label, pad: pad, x: x, y: y, fill: fill)



Expand Down
28 changes: 19 additions & 9 deletions src/draw-functions.typ
Original file line number Diff line number Diff line change
Expand Up @@ -90,22 +90,26 @@
#let draw-targ(item, draw-params) = {
let size = item.data.size
box({
set circle(stroke: draw-params.wire)
set line(stroke: draw-params.wire)
set circle(stroke: item.stroke) if item.stroke != auto
set line(stroke: item.stroke) if item.stroke != auto
circle(
radius: size,
stroke: draw-params.wire,
fill: utility.if-auto(item.fill, draw-params.background)
)
place(line(start: (size, 0pt), length: 2*size, angle: -90deg, stroke: draw-params.wire))
place(line(start: (0pt, -size), length: 2*size, stroke: draw-params.wire))
place(line(start: (size, 0pt), length: 2*size, angle: -90deg))
place(line(start: (0pt, -size), length: 2*size))
})
}

#let draw-ctrl(gate, draw-params) = {
let color = utility.if-auto(gate.fill, draw-params.color)
if "show-dot" in gate.data and not gate.data.show-dot { return none }
if gate.data.open {
let stroke = utility.if-auto(gate.fill, draw-params.wire)
box(circle(stroke: stroke, fill: draw-params.background, radius: gate.data.size))
let stroke = utility.update-stroke(draw-params.wire, gate.stroke)
let fill = utility.if-auto(gate.fill, draw-params.background)
box(circle(stroke: stroke, fill: fill, radius: gate.data.size))
} else {
box(circle(fill: color, radius: gate.data.size))
}
Expand All @@ -114,10 +118,11 @@
#let draw-swap(gate, draw-params) = {
box({
let d = gate.data.size
let stroke = draw-params.wire
set line(stroke: draw-params.wire)
set line(stroke: gate.stroke) if gate.stroke != auto
box(width: d, height: d, {
place(line(start: (-0pt, -0pt), end: (d, d), stroke: stroke))
place(line(start: (d, 0pt), end: (0pt, d), stroke: stroke))
place(line(start: (-0pt, -0pt), end: (d, d)))
place(line(start: (d, 0pt), end: (0pt, d)))
})
})
}
Expand Down Expand Up @@ -149,6 +154,8 @@
set align(top)
set curve(stroke: draw-params.wire)
set line(stroke: draw-params.wire)
set curve(stroke: gate.stroke) if gate.stroke != auto
set line(stroke: gate.stroke) if gate.stroke != auto
set rect(width: width, height: height)

utility.if-auto(gate.content, meter-symbol)
Expand Down Expand Up @@ -241,7 +248,10 @@
if brace-symbol == auto and gate.multi == none {
brace-symbol = none
}
brace = utility.create-brace(brace-symbol, gate.data.align, brace-height)
brace = {
set text(gate.fill) if gate.fill != auto
utility.create-brace(brace-symbol, gate.data.align, brace-height)
}
}

let brace-size = measure(brace)
Expand Down
44 changes: 36 additions & 8 deletions src/gates.typ
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,10 @@
/// -> none | int
target: none,

/// How to stroke the meter.
/// -> auto | stroke
stroke: auto,

/// The number of qubits that the meter spans.
/// -> int
n: 1,
Expand Down Expand Up @@ -346,9 +350,9 @@
}
label = process-args.process-label-arg(label, default-dy: 0.5em, default-pos: top)
if target == none and n == 1 {
gate(body, x: x, y: y, fill: fill, radius: radius, draw-function: draw-functions.draw-meter, label: label)
gate(body, x: x, y: y, fill: fill, stroke: stroke, radius: radius, draw-function: draw-functions.draw-meter, label: label)
} else {
mqgate(body, x: x, y: y, n: n, target: target, fill: fill, radius: radius, box: true, wire-count: wire-count, wire-stroke: wire-stroke, draw-function: draw-functions.draw-meter, label: label)
mqgate(body, x: x, y: y, n: n, target: target, fill: fill, stroke: stroke, radius: radius, box: true, wire-count: wire-count, wire-stroke: wire-stroke, draw-function: draw-functions.draw-meter, label: label)
}
}

Expand Down Expand Up @@ -484,6 +488,10 @@
/// -> none | auto | color | gradient | tiling
fill: none,

/// How to stroke the target.
/// -> auto | stroke
stroke: auto,

/// Radius of the target symbol.
/// -> length
size: 4.3pt,
Expand Down Expand Up @@ -521,6 +529,7 @@
wire-count: wire-count,
wire-stroke: wire-stroke,
fill: if fill == true {auto} else if fill == false {none} else {fill},
stroke: stroke,
data: (size: size),
label: label,
wire-label: wire-label
Expand All @@ -546,10 +555,15 @@
/// -> bool
open: false,

/// How to fill or stroke the circle if `open: true`.
/// -> none | color | stroke
/// How to fill the circle.
/// -> auto | none | color
fill: auto,


/// How to stroke the circle if `open: true`.
/// -> auto | stroke | color
stroke: auto,

/// The radius of the circle.
/// -> length
size: 2.3pt,
Expand All @@ -568,6 +582,7 @@
draw-functions.draw-ctrl(gate, draw-params)
),
fill: fill,
stroke: stroke,
data: (open: open, size: size),
label: process-args.process-label-arg(label, default-pos: top + right, default-dx: -.5em)
)
Expand All @@ -588,13 +603,19 @@
/// How many wires up or down the target wire lives.
/// -> int
..n,


/// Wire count for the control wire.
/// -> int
wire-count: 1,

/// The size of the target symbol.
/// -> length.
size: 7pt,

/// How to stroke the swap gate.
/// -> auto | stroke
stroke: auto,

label: none,

/// One or more labels to add to the control wire. See @mqgate.wire-label.
Expand Down Expand Up @@ -625,7 +646,8 @@
wire-stroke: wire-stroke,
data: (size: size),
label: label,
wire-label: wire-label
wire-label: wire-label,
stroke: stroke
)
}

Expand Down Expand Up @@ -657,10 +679,15 @@
/// -> bool
open: false,

/// How to fill or stroke the circle if `open: true`.
/// none | color
/// How to fill the circle.
/// -> auto | none | color
fill: auto,


/// How to stroke the circle if `open: true`.
/// -> auto | stroke | color
stroke: auto,

/// The radius of the control circle.
/// -> length
size: 2.3pt,
Expand Down Expand Up @@ -694,6 +721,7 @@
draw-function: draw-functions.draw-ctrl,
wire-count: wire-count,
fill: fill,
stroke: stroke,
data: (open: open, size: size, show-dot: show-dot),
label: label,
wire-label: wire-label,
Expand Down
Binary file added tests/gates/custom-colors/ref/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 11 additions & 1 deletion tests/gates/custom-colors/test.typ
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,15 @@


#quantum-circuit(
gate($X$, fill: gray), phase($text(a, fill: #red)$, fill: red), phase($text(a, fill: #red)$, fill: .7pt + red, open: true), gate($F_m$, radius: 100%), gate($F#h(.2em)$, radius: (right: 100%), fill: green), targ(fill: auto), targ(fill: blue), ctrl(fill: blue), ctrl(fill: .7pt + blue, open: true), ctrl(fill: blue), ctrl(fill: .7pt + blue, open: true), 1
// setwire(2),
gate($X$, fill: gray), phase($text(a, fill: #red)$, fill: red), phase($text(a, fill: #red)$, stroke: .7pt + red, open: true), gate($F_m$, radius: 100%), gate($F#h(.2em)$, radius: (right: 100%), fill: green), targ(fill: auto), targ(fill: blue), ctrl(fill: blue), ctrl(stroke: .7pt + blue, open: true), ctrl(fill: blue), ctrl(stroke: .7pt + blue, open: true), 1
)

#pagebreak()

#quantum-circuit(
lstick(fill: blue, n: 2)[], swap(0, stroke: 2pt), targ(0, stroke: red), 1, meter(stroke: blue),
rstick(fill: blue, n: 2)[], [\ ],
1, ctrl(open: true, fill: red, stroke: green),
phase(open: true, fill: red, stroke: green)[],
)