1
0
forked from HEL/circuiteria

added doc for circuit, util and wire

This commit is contained in:
2024-05-17 09:36:38 +02:00
parent ef4461bd18
commit 7e0209b712
5 changed files with 99 additions and 0 deletions

View File

@ -1,6 +1,23 @@
#import "@preview/cetz:0.2.2": draw, coordinate
#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 signal-width = 1pt
#let bus-width = 1.5pt
@ -89,6 +106,21 @@
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(
id, pts,
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 offset = (
north: (0, length),