forked from HEL/circuiteria
added doc for circuit, util and wire
This commit is contained in:
parent
ef4461bd18
commit
7e0209b712
BIN
manual.pdf
Normal file
BIN
manual.pdf
Normal file
Binary file not shown.
28
manual.typ
Normal file
28
manual.typ
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#import "@preview/tidy:0.3.0"
|
||||||
|
#import "@preview/cetz:0.2.2": draw
|
||||||
|
#import "src/circuit.typ": circuit
|
||||||
|
#import "src/util.typ"
|
||||||
|
#import "src/wire.typ"
|
||||||
|
|
||||||
|
#let circuit-docs = tidy.parse-module(
|
||||||
|
read("src/circuit.typ"),
|
||||||
|
name: "circuit",
|
||||||
|
require-all-parameters: true
|
||||||
|
)
|
||||||
|
#tidy.show-module(circuit-docs)
|
||||||
|
|
||||||
|
#let util-docs = tidy.parse-module(
|
||||||
|
read("src/util.typ"),
|
||||||
|
name: "util",
|
||||||
|
require-all-parameters: true,
|
||||||
|
scope: (util: util)
|
||||||
|
)
|
||||||
|
#tidy.show-module(util-docs)
|
||||||
|
|
||||||
|
#let wire-docs = tidy.parse-module(
|
||||||
|
read("src/wire.typ"),
|
||||||
|
name: "wire",
|
||||||
|
require-all-parameters: true,
|
||||||
|
scope: (wire: wire, circuit: circuit, draw: draw)
|
||||||
|
)
|
||||||
|
#tidy.show-module(wire-docs)
|
@ -1,5 +1,11 @@
|
|||||||
#import "@preview/cetz:0.2.2": canvas
|
#import "@preview/cetz:0.2.2": canvas
|
||||||
|
#import "@preview/tidy:0.3.0"
|
||||||
|
|
||||||
|
/// Draws a block circuit diagram
|
||||||
|
///
|
||||||
|
/// - body (none, array, element): A code block in which draw functions have been called
|
||||||
|
/// - length (length, ratio): Optional base unit
|
||||||
|
/// -> none
|
||||||
#let circuit(body, length: 2em) = {
|
#let circuit(body, length: 2em) = {
|
||||||
set text(font: "Source Sans 3")
|
set text(font: "Source Sans 3")
|
||||||
canvas(length: length, body)
|
canvas(length: length, body)
|
||||||
|
19
src/util.typ
19
src/util.typ
@ -1,3 +1,4 @@
|
|||||||
|
/// Predefined color palette
|
||||||
#let colors = (
|
#let colors = (
|
||||||
orange: rgb(245, 180, 147),
|
orange: rgb(245, 180, 147),
|
||||||
yellow: rgb(250, 225, 127),
|
yellow: rgb(250, 225, 127),
|
||||||
@ -6,11 +7,24 @@
|
|||||||
purple: rgb(189, 151, 255)
|
purple: rgb(189, 151, 255)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/// Pads a string on the left with 0s to the given length
|
||||||
|
///
|
||||||
|
/// #example(`#util.lpad("0100", 8)`, mode: "markup")
|
||||||
|
///
|
||||||
|
/// - s (str): The string to pad
|
||||||
|
/// - len (int): The target length
|
||||||
|
/// -> str
|
||||||
#let lpad(s, len) = {
|
#let lpad(s, len) = {
|
||||||
let res = "0" * len + s
|
let res = "0" * len + s
|
||||||
return res.slice(-len)
|
return res.slice(-len)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the anchor on the opposite side of the given one
|
||||||
|
///
|
||||||
|
/// #example(`#util.opposite-anchor("west")`, mode: "markup")
|
||||||
|
///
|
||||||
|
/// - anchor (str): The input anchor
|
||||||
|
/// -> str
|
||||||
#let opposite-anchor(anchor) = {
|
#let opposite-anchor(anchor) = {
|
||||||
return (
|
return (
|
||||||
north: "south",
|
north: "south",
|
||||||
@ -25,6 +39,11 @@
|
|||||||
).at(anchor)
|
).at(anchor)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the anchor rotated 90 degrees clockwise relative to the given one
|
||||||
|
///
|
||||||
|
/// #example(`#util.rotate-anchor("west")`, mode: "markup")
|
||||||
|
/// - anchor (str): The anchor to rotate
|
||||||
|
/// -> str
|
||||||
#let rotate-anchor(anchor) = {
|
#let rotate-anchor(anchor) = {
|
||||||
return (
|
return (
|
||||||
north: "east",
|
north: "east",
|
||||||
|
46
src/wire.typ
46
src/wire.typ
@ -1,6 +1,23 @@
|
|||||||
#import "@preview/cetz:0.2.2": draw, coordinate
|
#import "@preview/cetz:0.2.2": draw, coordinate
|
||||||
#import "util.typ": opposite-anchor
|
#import "util.typ": opposite-anchor
|
||||||
|
|
||||||
|
/// List of valid wire styles
|
||||||
|
/// #box(width: 100%, align(center)[
|
||||||
|
/// #circuit({
|
||||||
|
/// draw.circle((0, 0), radius: .1, name: "p1")
|
||||||
|
/// draw.circle((2, 1), radius: .1, name: "p2")
|
||||||
|
/// draw.circle((3, 0), radius: .1, name: "p3")
|
||||||
|
/// draw.circle((5, 1), radius: .1, name: "p4")
|
||||||
|
/// draw.circle((6, 0), radius: .1, name: "p5")
|
||||||
|
/// draw.circle((8, 1), radius: .1, name: "p6")
|
||||||
|
/// wire.wire("w1", ("p1", "p2"), style: "direct")
|
||||||
|
/// wire.wire("w2", ("p3", "p4"), style: "zigzag")
|
||||||
|
/// wire.wire("w3", ("p5", "p6"), style: "dodge", dodge-y: -0.5, dodge-margins: (0.5, 0.5))
|
||||||
|
/// draw.content((1, -1), [`direct`])
|
||||||
|
/// draw.content((4, -1), [`zigzag`])
|
||||||
|
/// draw.content((7, -1), [`dodge`])
|
||||||
|
/// })
|
||||||
|
/// ])
|
||||||
#let wire-styles = ("direct", "zigzag", "dodge")
|
#let wire-styles = ("direct", "zigzag", "dodge")
|
||||||
#let signal-width = 1pt
|
#let signal-width = 1pt
|
||||||
#let bus-width = 1.5pt
|
#let bus-width = 1.5pt
|
||||||
@ -89,6 +106,21 @@
|
|||||||
return (points, anchors)
|
return (points, anchors)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Draws a wire between two points
|
||||||
|
/// - id (str): The wire's id, for future reference (anchors)
|
||||||
|
/// - pts (array): The two points (as CeTZ compatible coordinates, i.e. XY, relative positions, ids, etc.)
|
||||||
|
/// - bus (bool): Whether the wire is a bus (multiple bits) or a simple signal (single bit)
|
||||||
|
/// - name (none, str, array): Optional name of the wire. If it is an array, the first name will be put at the start of the wire, and the second at the end
|
||||||
|
/// - name-pos (str): Position of the name. One of: "middle", "start" or "end"
|
||||||
|
/// - slice (none, array): Optional bits slice (start and end bit indices). If set, it will be displayed at the start of the wire
|
||||||
|
/// - color (color): The stroke color
|
||||||
|
/// - dashed (bool): Whether the stroke is dashed or not
|
||||||
|
/// - style (str): The wire's style (see `wire-styles` for possible values)
|
||||||
|
/// - reverse (bool): If true, the start and end points will be swapped (useful in cases where the start point depends on the end point, for example with perpendiculars)
|
||||||
|
/// - zigzag-ratio (ratio): Position of the zigzag vertical relative to the horizontal span (only with style "zigzag")
|
||||||
|
/// - dodge-y (int, float, length, ratio): Y position to dodge the wire to (only with style "dodge")
|
||||||
|
/// - dodge-sides (array): The start and end sides (going out of the connected element) of the wire (only with style "dodge")
|
||||||
|
/// - dodge-margins (array): The start and end margins (i.e. space before dodging) of the wire (only with style "dodge")
|
||||||
#let wire(
|
#let wire(
|
||||||
id, pts,
|
id, pts,
|
||||||
bus: false,
|
bus: false,
|
||||||
@ -199,6 +231,20 @@
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/// Draws a wire stub (useful for unlinked ports)
|
||||||
|
///
|
||||||
|
/// #box(width: 100%, align(center)[
|
||||||
|
/// #circuit({
|
||||||
|
/// draw.circle((0, 0), radius: .1, name: "p")
|
||||||
|
/// wire.stub("p", "east", name: "port")
|
||||||
|
/// })
|
||||||
|
/// ])
|
||||||
|
///
|
||||||
|
/// - port-id (str): The port anchor
|
||||||
|
/// - side (str): The side on which the port is (one of "north", "east", "south", "west")
|
||||||
|
/// - name (none, str): Optional name displayed at the end of the stub
|
||||||
|
/// - vertical (bool): Whether the name should be displayed vertically
|
||||||
|
/// - length (number): The length of the stub
|
||||||
#let stub(port-id, side, name: none, vertical: false, length: 1em) = {
|
#let stub(port-id, side, name: none, vertical: false, length: 1em) = {
|
||||||
let offset = (
|
let offset = (
|
||||||
north: (0, length),
|
north: (0, length),
|
||||||
|
Loading…
Reference in New Issue
Block a user