forked from HEL/circuiteria
feat: add anchor-based zigzag bend placement via zigzag-at
Add the `zigzag-at` parameter to place the middle bend of a zigzag wire on the axis of a referenced anchor. It overrides `zigzag-ratio`, which now defaults to `auto` (resolving to 50%) so the two are mutually exclusive. Accepted forms are an anchor name, any CeTZ coordinate, or the scalar offset `(rel: <length>, to: <coord>)`. Add the generic helpers this relies on and that other wire styles reuse: - `normalize-scalar-offset(at, axis)` turns a scalar offset into an x or y offset; `normalize-zigzag-at` is a wrapper around it. - `detect-port-side(anchor, ctx)` deduces the cardinal side a port faces by comparing it with its element's `.center` anchor. Add the `zigzag-at` example.
This commit is contained in:
1 parent
df4c956a0b
commit
2c6e5f44df
3 files changed
+6709
-6355
No files matched your search
@@ -71,6 +71,30 @@ wire.wire("w4", ("p6","p7"), style: "guided",
|
||||
|
||||
```, vertical: true)
|
||||
|
||||
#let zigzag-at = example(
|
||||
```
|
||||
// `zigzag-at` places the middle bend of a zigzag wire
|
||||
// on the axis of a referenced anchor, overriding
|
||||
// `zigzag-ratio`.
|
||||
element.block(x: 0, y: 0, w: 1.5, h: 1.5, id: "src",
|
||||
ports: (east: ((id: "o", name: "O"),),))
|
||||
element.block(x: 3, y: -1.2, w: 1, h: 1, id: "ref",
|
||||
fill: util.colors.pink,
|
||||
ports: (west: ((id: "p", name: "R"),),))
|
||||
element.block(x: 5.5, y: -2, w: 1.5, h: 1.5, id: "dst",
|
||||
ports: (west: ((id: "i", name: "I"),),))
|
||||
// String form: anchor name of a port.
|
||||
wire.wire("w1", ("src-port-o", "dst-port-i"),
|
||||
style: "zigzag",
|
||||
zigzag-at: "ref-port-p")
|
||||
// Ergonomic offset: shift 8pt right of ref.east.
|
||||
wire.wire("w2", ("src-port-o", "dst-port-i"),
|
||||
style: "zigzag",
|
||||
zigzag-at: (rel: 8pt, to: "ref.east"))
|
||||
```,
|
||||
vertical: true,
|
||||
)
|
||||
|
||||
#let stub = example(```
|
||||
draw.circle((0, 0), radius: .1, name: "p")
|
||||
wire.stub("p", "north", name: "north", length: 1)
|
||||
|
||||
Reference in new issue
Block a user