reworked ports layout + adapted multiplexer
This commit is contained in:
parent
26231b2f48
commit
4930b53c84
Binary file not shown.
@ -17,7 +17,7 @@
|
|||||||
wire.stub("PCBuf.CLK", name: "CLK")
|
wire.stub("PCBuf.CLK", name: "CLK")
|
||||||
wire.stub("PCBuf.EN", name: "PCWrite")
|
wire.stub("PCBuf.EN", name: "PCWrite")
|
||||||
|
|
||||||
/*
|
|
||||||
element.multiplexer(
|
element.multiplexer(
|
||||||
pos: (
|
pos: (
|
||||||
3, (align: "in0", with: "PCBuf.PC")
|
3, (align: "in0", with: "PCBuf.PC")
|
||||||
@ -25,9 +25,10 @@
|
|||||||
size: (1, 2),
|
size: (1, 2),
|
||||||
id: "AdrSrc-MP",
|
id: "AdrSrc-MP",
|
||||||
fill: util.colors.orange,
|
fill: util.colors.orange,
|
||||||
entries: 2
|
entries: 2,
|
||||||
|
debug: (ports: true)
|
||||||
)
|
)
|
||||||
wire.wire(
|
/*wire.wire(
|
||||||
"PCBuf.PC",
|
"PCBuf.PC",
|
||||||
"AdrSrc-MP.in0",
|
"AdrSrc-MP.in0",
|
||||||
id: "wPCBuf-InstDataMgr",
|
id: "wPCBuf-InstDataMgr",
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#let block(
|
#let block(
|
||||||
..args
|
..args
|
||||||
) = element.elmt(
|
) = element.elmt(
|
||||||
|
cls: "block",
|
||||||
draw-shape: draw-shape,
|
draw-shape: draw-shape,
|
||||||
..args
|
..args
|
||||||
)
|
)
|
@ -1,5 +1,5 @@
|
|||||||
#import "@preview/cetz:0.3.2": draw, coordinate, matrix, vector
|
#import "@preview/cetz:0.3.2": draw, coordinate, matrix, vector
|
||||||
#import "ports.typ": add-ports, add-port
|
#import "ports.typ": add-ports, add-port, get-port-pos, get-port-idx
|
||||||
#import "../util.typ"
|
#import "../util.typ"
|
||||||
|
|
||||||
#let find-port(ports, id) = {
|
#let find-port(ports, id) = {
|
||||||
@ -10,7 +10,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
panic("Could not find port with id " + str(id))
|
panic("Could not find port with id '" + str(id) + "'")
|
||||||
}
|
}
|
||||||
|
|
||||||
#let local-to-global(origin, u, v, points) = {
|
#let local-to-global(origin, u, v, points) = {
|
||||||
@ -42,7 +42,7 @@
|
|||||||
return pos.at(axis)
|
return pos.at(axis)
|
||||||
}
|
}
|
||||||
|
|
||||||
#let resolve-align(ctx, elmt, align, with, axis) = {
|
#let resolve-align(ctx, elmt, bounds, align, with, axis) = {
|
||||||
let (align-side, i) = find-port(elmt.ports, align)
|
let (align-side, i) = find-port(elmt.ports, align)
|
||||||
let margins = (0%, 0%)
|
let margins = (0%, 0%)
|
||||||
if align-side in elmt.ports-margins {
|
if align-side in elmt.ports-margins {
|
||||||
@ -67,12 +67,12 @@
|
|||||||
let used-len = len * used-pct / 100%
|
let used-len = len * used-pct / 100%
|
||||||
start-margin = len * margins.at(0) / 100%
|
start-margin = len * margins.at(0) / 100%
|
||||||
|
|
||||||
dl = used-len * (i + 1) / (elmt.ports.at(align-side).len() + 1)
|
//dl = used-len * (i + 1) / (elmt.ports.at(align-side).len() + 1)
|
||||||
|
dl = get-port-pos(elmt, bounds, align-side, align, get-port-idx(elmt, align, side: align-side))
|
||||||
if not elmt.auto-ports {
|
/*if not elmt.auto-ports {
|
||||||
start-margin = 0
|
start-margin = 0
|
||||||
dl = elmt.ports-pos.at(with)(len)
|
dl = elmt.ports-pos.at(align)(len)
|
||||||
}
|
}*/
|
||||||
} else if align-side == ortho-sides.first() {
|
} else if align-side == ortho-sides.first() {
|
||||||
dl = 0
|
dl = 0
|
||||||
start-margin = 0
|
start-margin = 0
|
||||||
@ -89,7 +89,7 @@
|
|||||||
return with-pos.at(axis) - dl + start-margin
|
return with-pos.at(axis) - dl + start-margin
|
||||||
}
|
}
|
||||||
|
|
||||||
#let resolve-coordinate(ctx, elmt, coord, axis) = {
|
#let resolve-coordinate(ctx, elmt, bounds, coord, axis) = {
|
||||||
if type(coord) == dictionary {
|
if type(coord) == dictionary {
|
||||||
let offset = coord.at("offset", default: none)
|
let offset = coord.at("offset", default: none)
|
||||||
let from = coord.at("from", default: none)
|
let from = coord.at("from", default: none)
|
||||||
@ -105,7 +105,7 @@
|
|||||||
return resolve-offset(ctx, offset, from, axis)
|
return resolve-offset(ctx, offset, from, axis)
|
||||||
|
|
||||||
} else if none not in (align, with) {
|
} else if none not in (align, with) {
|
||||||
return resolve-align(ctx, elmt, align, with, axis)
|
return resolve-align(ctx, elmt, bounds, align, with, axis)
|
||||||
} else {
|
} else {
|
||||||
panic("Dictionnary must either provide both 'offset' and 'from', or 'align' and 'with'")
|
panic("Dictionnary must either provide both 'offset' and 'from', or 'align' and 'with'")
|
||||||
}
|
}
|
||||||
@ -116,11 +116,11 @@
|
|||||||
return coord
|
return coord
|
||||||
}
|
}
|
||||||
|
|
||||||
#let make-bounds(x, y, w, h) = {
|
#let make-bounds(elmt, x, y, w, h) = {
|
||||||
let w2 = w / 2
|
let w2 = w / 2
|
||||||
let h2 = h / 2
|
let h2 = h / 2
|
||||||
|
|
||||||
return (
|
let bounds = (
|
||||||
bl: (x, y),
|
bl: (x, y),
|
||||||
tl: (x, y + h),
|
tl: (x, y + h),
|
||||||
tr: (x + w, y + h),
|
tr: (x + w, y + h),
|
||||||
@ -131,6 +131,33 @@
|
|||||||
l: (x, y + h2),
|
l: (x, y + h2),
|
||||||
r: (x + w, y + h2),
|
r: (x + w, y + h2),
|
||||||
)
|
)
|
||||||
|
bounds += (
|
||||||
|
sides: (
|
||||||
|
north: (bounds.tl, bounds.tr),
|
||||||
|
south: (bounds.bl, bounds.br),
|
||||||
|
west: (bounds.tl, bounds.bl),
|
||||||
|
east: (bounds.tr, bounds.br),
|
||||||
|
),
|
||||||
|
lengths: (
|
||||||
|
north: (bounds.tr.at(0) - bounds.tl.at(0)),
|
||||||
|
south: (bounds.br.at(0) - bounds.bl.at(0)),
|
||||||
|
west: (bounds.tl.at(1) - bounds.bl.at(1)),
|
||||||
|
east: (bounds.tr.at(1) - bounds.br.at(1)),
|
||||||
|
),
|
||||||
|
ports: (:)
|
||||||
|
)
|
||||||
|
for (side, props) in bounds.sides.pairs() {
|
||||||
|
let props2 = props
|
||||||
|
if side in elmt.ports-margins {
|
||||||
|
let (pt0, pt1) = props
|
||||||
|
let margins = ports-margins.at(side)
|
||||||
|
a = (pt0, margins.at(0), pt1)
|
||||||
|
b = (pt0, 100% - margins.at(1), pt1)
|
||||||
|
props2 = (a, b)
|
||||||
|
}
|
||||||
|
bounds.ports.insert(side, props2)
|
||||||
|
}
|
||||||
|
return bounds
|
||||||
}
|
}
|
||||||
|
|
||||||
#let render(draw-shape, elmt) = draw.group(name: elmt.id, ctx => {
|
#let render(draw-shape, elmt) = draw.group(name: elmt.id, ctx => {
|
||||||
@ -140,10 +167,10 @@
|
|||||||
let x = elmt.pos.first()
|
let x = elmt.pos.first()
|
||||||
let y = elmt.pos.last()
|
let y = elmt.pos.last()
|
||||||
|
|
||||||
x = resolve-coordinate(ctx, elmt, x, 0)
|
let bounds = make-bounds(elmt, 0, 0, width, height)
|
||||||
y = resolve-coordinate(ctx, elmt, y, 1)
|
x = resolve-coordinate(ctx, elmt, bounds, x, 0)
|
||||||
|
y = resolve-coordinate(ctx, elmt, bounds, y, 1)
|
||||||
let bounds = make-bounds(x, y, width, height)
|
bounds = make-bounds(elmt, x, y, width, height)
|
||||||
|
|
||||||
// Workaround because CeTZ needs to have all draw functions in the body
|
// Workaround because CeTZ needs to have all draw functions in the body
|
||||||
let func = {}
|
let func = {}
|
||||||
@ -171,15 +198,7 @@
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if elmt.auto-ports {
|
add-ports(elmt, bounds)
|
||||||
add-ports(
|
|
||||||
elmt.id,
|
|
||||||
bounds,
|
|
||||||
elmt.ports,
|
|
||||||
elmt.ports-margins,
|
|
||||||
debug: elmt.debug.ports
|
|
||||||
)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
/// Draws an element
|
/// Draws an element
|
||||||
@ -210,6 +229,7 @@
|
|||||||
/// Supported fields include:
|
/// Supported fields include:
|
||||||
/// - `ports`: if true, shows dots on all ports of the element
|
/// - `ports`: if true, shows dots on all ports of the element
|
||||||
#let elmt(
|
#let elmt(
|
||||||
|
cls: "element",
|
||||||
draw-shape: default-draw-shape,
|
draw-shape: default-draw-shape,
|
||||||
pre-process: default-pre-process,
|
pre-process: default-pre-process,
|
||||||
pos: (0, 0),
|
pos: (0, 0),
|
||||||
@ -221,11 +241,11 @@
|
|||||||
fill: none,
|
fill: none,
|
||||||
stroke: black + 1pt,
|
stroke: black + 1pt,
|
||||||
id: auto,
|
id: auto,
|
||||||
auto-ports: true,
|
ports-pos: auto,
|
||||||
ports-y: (:),
|
|
||||||
debug: (
|
debug: (
|
||||||
ports: false
|
ports: false
|
||||||
)
|
),
|
||||||
|
extra: (:)
|
||||||
) = {
|
) = {
|
||||||
for (key, side-ports) in ports.pairs() {
|
for (key, side-ports) in ports.pairs() {
|
||||||
if type(side-ports) == str {
|
if type(side-ports) == str {
|
||||||
@ -249,6 +269,7 @@
|
|||||||
|
|
||||||
|
|
||||||
return ((
|
return ((
|
||||||
|
cls: cls,
|
||||||
id: id,
|
id: id,
|
||||||
draw: render.with(draw-shape),
|
draw: render.with(draw-shape),
|
||||||
pre-process: pre-process,
|
pre-process: pre-process,
|
||||||
@ -260,8 +281,7 @@
|
|||||||
ports-margins: ports-margins,
|
ports-margins: ports-margins,
|
||||||
fill: fill,
|
fill: fill,
|
||||||
stroke: stroke,
|
stroke: stroke,
|
||||||
auto-ports: auto-ports,
|
ports-pos: ports-pos,
|
||||||
ports-y: ports-y,
|
|
||||||
debug: debug
|
debug: debug
|
||||||
),)
|
) + extra,)
|
||||||
}
|
}
|
||||||
|
@ -3,29 +3,29 @@
|
|||||||
#import "element.typ"
|
#import "element.typ"
|
||||||
#import "ports.typ": add-port
|
#import "ports.typ": add-port
|
||||||
|
|
||||||
#let draw-shape(id, tl, tr, br, bl, fill, stroke, h-ratio: 60%) = {
|
#let draw-shape(elmt, bounds) = {
|
||||||
let margin = (100% - h-ratio) / 2
|
let margin = (100% - elmt.l-ratio) / 2
|
||||||
let tr2 = (tr, margin, br)
|
let tr2 = (bounds.tr, margin, bounds.br)
|
||||||
let br2 = (br, margin, tr)
|
let br2 = (bounds.br, margin, bounds.tr)
|
||||||
let f = draw.group(name: id, {
|
let f = draw.group(name: elmt.id, {
|
||||||
draw.merge-path(
|
draw.merge-path(
|
||||||
inset: 0.5em,
|
inset: 0.5em,
|
||||||
fill: fill,
|
fill: elmt.fill,
|
||||||
stroke: stroke,
|
stroke: elmt.stroke,
|
||||||
close: true,
|
close: true,
|
||||||
draw.line(tl, tr2, br2, bl)
|
draw.line(bounds.tl, tr2, br2, bounds.bl)
|
||||||
)
|
)
|
||||||
draw.anchor("north", (tl, 50%, tr2))
|
draw.anchor("north", (bounds.tl, 50%, tr2))
|
||||||
draw.anchor("south", (bl, 50%, br2))
|
draw.anchor("south", (bounds.bl, 50%, br2))
|
||||||
draw.anchor("west", (tl, 50%, bl))
|
draw.anchor("west", (bounds.tl, 50%, bounds.bl))
|
||||||
draw.anchor("east", (tr2, 50%, br2))
|
draw.anchor("east", (tr2, 50%, br2))
|
||||||
draw.anchor("north-west", tl)
|
draw.anchor("north-west", bounds.tl)
|
||||||
draw.anchor("north-east", tr2)
|
draw.anchor("north-east", tr2)
|
||||||
draw.anchor("south-east", br2)
|
draw.anchor("south-east", br2)
|
||||||
draw.anchor("south-west", bl)
|
draw.anchor("south-west", bounds.bl)
|
||||||
})
|
})
|
||||||
|
|
||||||
return (f, tl, tr, br, bl)
|
return (f, bounds)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Draws a multiplexer
|
/// Draws a multiplexer
|
||||||
@ -35,64 +35,44 @@
|
|||||||
/// - entries (int, array): If it is an integer, it defines the number of input ports (automatically named with their binary index). If it is an array of strings, it defines the name of each input.
|
/// - entries (int, array): If it is an integer, it defines the number of input ports (automatically named with their binary index). If it is an array of strings, it defines the name of each input.
|
||||||
/// - h-ratio (ratio): The height ratio of the right side relative to the full height
|
/// - h-ratio (ratio): The height ratio of the right side relative to the full height
|
||||||
#let multiplexer(
|
#let multiplexer(
|
||||||
x: none,
|
|
||||||
y: none,
|
|
||||||
w: none,
|
|
||||||
h: none,
|
|
||||||
name: none,
|
|
||||||
name-anchor: "center",
|
|
||||||
entries: 2,
|
entries: 2,
|
||||||
h-ratio: 60%,
|
l-ratio: 60%,
|
||||||
fill: none,
|
..args
|
||||||
stroke: black + 1pt,
|
|
||||||
id: "",
|
|
||||||
debug: (
|
|
||||||
ports: false
|
|
||||||
)
|
|
||||||
) = {
|
) = {
|
||||||
let ports = ()
|
let in-ports = ()
|
||||||
let ports-y = (
|
let ports-pos = (
|
||||||
out: (h) => {h * 0.5}
|
"east": auto,
|
||||||
)
|
)
|
||||||
|
|
||||||
if (type(entries) == int) {
|
if (type(entries) == int) {
|
||||||
let nbits = calc.ceil(calc.log(entries, base: 2))
|
let nbits = calc.ceil(calc.log(entries, base: 2))
|
||||||
for i in range(entries) {
|
for i in range(entries) {
|
||||||
let bits = util.lpad(str(i, base: 2), nbits)
|
let bits = util.lpad(str(i, base: 2), nbits)
|
||||||
ports.push((id: "in" + str(i), name: bits))
|
in-ports.push((id: "in" + str(i), name: bits))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (i, port) in entries.enumerate() {
|
for (i, port) in entries.enumerate() {
|
||||||
ports.push((id: "in" + str(i), name: port))
|
in-ports.push((id: "in" + str(i), name: port))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let space = 100% / ports.len()
|
let n = in-ports.len()
|
||||||
let l = ports.len()
|
ports-pos.insert("west", (l, i) => {l * (i + 0.5) / n})
|
||||||
for (i, port) in ports.enumerate() {
|
|
||||||
ports-y.insert(port.id, (h) => {h * (i + 0.5) / l})
|
|
||||||
}
|
|
||||||
|
|
||||||
element.elmt(
|
element.elmt(
|
||||||
draw-shape: draw-shape.with(h-ratio: h-ratio),
|
cls: "multiplexer",
|
||||||
x: x,
|
draw-shape: draw-shape,
|
||||||
y: y,
|
ports: (west: in-ports, east: ((id: "out"),)),
|
||||||
w: w,
|
ports-pos: ports-pos,
|
||||||
h: h,
|
extra: (l-ratio: l-ratio),
|
||||||
name: name,
|
..args
|
||||||
name-anchor: name-anchor,
|
|
||||||
ports: (west: ports, east: ((id: "out"),)),
|
|
||||||
fill: fill,
|
|
||||||
stroke: stroke,
|
|
||||||
id: id,
|
|
||||||
ports-y: ports-y,
|
|
||||||
auto-ports: false,
|
|
||||||
debug: debug
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/*
|
||||||
for (i, port) in ports.enumerate() {
|
for (i, port) in ports.enumerate() {
|
||||||
let pct = (i + 0.5) * space
|
let pct = (i + 0.5) * space
|
||||||
add-port(id, "west", port, (id+".north-west", pct, id+".south-west"))
|
add-port(id, "west", port, (id+".north-west", pct, id+".south-west"))
|
||||||
}
|
}
|
||||||
add-port(id, "east", (id: "out"), (id+".north-east", 50%, id+".south-east"))
|
add-port(id, "east", (id: "out"), (id+".north-east", 50%, id+".south-east"))
|
||||||
|
*/
|
||||||
}
|
}
|
@ -1,6 +1,74 @@
|
|||||||
#import "@preview/cetz:0.3.2": draw
|
#import "@preview/cetz:0.3.2": draw
|
||||||
#import "../util.typ": rotate-anchor
|
#import "../util.typ": rotate-anchor
|
||||||
|
|
||||||
|
#let get-port-side(elmt, port) = {
|
||||||
|
for (side, ports) in elmt.ports {
|
||||||
|
for p in ports {
|
||||||
|
if p.id == port {
|
||||||
|
return side
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
panic("Unknown port " + port + " on element " + element.id)
|
||||||
|
}
|
||||||
|
|
||||||
|
#let get-port-idx(elmt, port, side: auto) = {
|
||||||
|
if side == auto {
|
||||||
|
side = get-port-side(elmt, port)
|
||||||
|
}
|
||||||
|
assert(
|
||||||
|
side in elmt.ports,
|
||||||
|
message: "No ports on side '" + side + "' of element '" + elmt.id + "'"
|
||||||
|
)
|
||||||
|
let i = elmt.ports.at(side).position(p => p.id == port)
|
||||||
|
assert(
|
||||||
|
i != none,
|
||||||
|
message: "Could not find port '" + port + "' on side '" + side + "' of element '" + elmt.id + "'"
|
||||||
|
)
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
|
||||||
|
#let get-port-pos(elmt, bounds, side, port, port-i) = {
|
||||||
|
let (pt0, pt1) = bounds.ports.at(side)
|
||||||
|
let side-len = if side in ("north", "south") {
|
||||||
|
pt1.at(0) - pt0.at(0)
|
||||||
|
} else {
|
||||||
|
pt0.at(1) - pt1.at(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
let offset = if (
|
||||||
|
elmt.ports-pos == auto or
|
||||||
|
elmt.ports-pos.at(side, default: auto) == auto
|
||||||
|
) {
|
||||||
|
let space = 100% / (elmt.ports.at(side, default: ()).len() + 1)
|
||||||
|
(port-i + 1) * space
|
||||||
|
} else {
|
||||||
|
assert(
|
||||||
|
side in elmt.ports-pos,
|
||||||
|
message: "Could not reliably compute port position (missing side)"
|
||||||
|
)
|
||||||
|
let side-pos = elmt.ports-pos.at(side)
|
||||||
|
if type(side-pos) == function {
|
||||||
|
(side-pos)(side-len, port-i)
|
||||||
|
} else if type(side-pos) == array {
|
||||||
|
(side-pos.at(i))(side-len)
|
||||||
|
} else if type(side-pos) == dictionary {
|
||||||
|
assert(
|
||||||
|
port in side-pos,
|
||||||
|
message: "Could not reliably compute port position (missing port)"
|
||||||
|
)
|
||||||
|
(side-pos.at(port))(side-len)
|
||||||
|
} else {
|
||||||
|
panic("Could not reliably compute port position (invalid type)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if type(offset) == ratio {
|
||||||
|
offset = offset * side-len / 100%
|
||||||
|
}
|
||||||
|
return offset
|
||||||
|
}
|
||||||
|
|
||||||
#let add-port(
|
#let add-port(
|
||||||
elmt-id, side, port, pos,
|
elmt-id, side, port, pos,
|
||||||
prev: none,
|
prev: none,
|
||||||
@ -54,46 +122,41 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
#let add-ports(
|
#let add-ports(
|
||||||
elmt-id,
|
elmt,
|
||||||
bounds,
|
bounds
|
||||||
ports,
|
|
||||||
ports-margins,
|
|
||||||
debug: false
|
|
||||||
) = {
|
) = {
|
||||||
let sides = (
|
let debug = elmt.debug.ports
|
||||||
"north": (bounds.tl, bounds.tr),
|
|
||||||
"east": (bounds.tr, bounds.br),
|
|
||||||
"south": (bounds.bl, bounds.br),
|
|
||||||
"west": (bounds.tl, bounds.bl)
|
|
||||||
)
|
|
||||||
|
|
||||||
if type(ports) != dictionary {
|
if type(elmt.ports) != dictionary {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for (side, props) in sides {
|
for (side, props) in bounds.ports {
|
||||||
let side-ports = ports.at(side, default: ())
|
let side-ports = elmt.ports.at(side, default: ())
|
||||||
let space = 100% / (side-ports.len() + 1)
|
let space = 100% / (side-ports.len() + 1)
|
||||||
|
|
||||||
for (i, port) in side-ports.enumerate() {
|
let (pt0, pt1) = props
|
||||||
let pct = (i + 1) * space
|
let side-len = if side in ("north", "south") {
|
||||||
let pt0 = props.at(0)
|
pt1.at(0) - pt0.at(0)
|
||||||
let pt1 = props.at(1)
|
} else {
|
||||||
|
pt0.at(1) - pt1.at(1)
|
||||||
if side in ports-margins {
|
|
||||||
let (a, b) = (pt0, pt1)
|
|
||||||
let margins = ports-margins.at(side)
|
|
||||||
a = (pt0, margins.at(0), pt1)
|
|
||||||
b = (pt0, 100% - margins.at(1), pt1)
|
|
||||||
pt0 = a
|
|
||||||
pt1 = b
|
|
||||||
}
|
}
|
||||||
|
for (i, port) in side-ports.enumerate() {
|
||||||
|
let offset = get-port-pos(elmt, bounds, side, port, i)
|
||||||
|
|
||||||
let pos = (pt0, pct, pt1)
|
let pos = (pt0, offset, pt1)
|
||||||
let pct-prev = (i + 0.5) * space
|
let offset-prev = if type(offset) == ratio {
|
||||||
let pct-next = (i + 1.5) * space
|
offset - space / 2
|
||||||
let pos-prev = (pt0, pct-prev, pt1)
|
} else {
|
||||||
let pos-next = (pt0, pct-next, pt1)
|
offset - space * side-len / 200%
|
||||||
|
}
|
||||||
|
let offset-next = if type(offset) == ratio {
|
||||||
|
offset + space / 2
|
||||||
|
} else {
|
||||||
|
offset + space * side-len / 200%
|
||||||
|
}
|
||||||
|
let pos-prev = (pt0, offset-prev, pt1)
|
||||||
|
let pos-next = (pt0, offset-next, pt1)
|
||||||
|
|
||||||
if port.at("small", default: false) {
|
if port.at("small", default: false) {
|
||||||
pos-prev = (pos, 4pt, pt0)
|
pos-prev = (pos, 4pt, pt0)
|
||||||
@ -101,7 +164,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
add-port(
|
add-port(
|
||||||
elmt-id,
|
elmt.id,
|
||||||
side,
|
side,
|
||||||
port,
|
port,
|
||||||
pos,
|
pos,
|
||||||
|
11
src/util.typ
11
src/util.typ
@ -74,14 +74,3 @@
|
|||||||
"center", "north", "east", "west", "south",
|
"center", "north", "east", "west", "south",
|
||||||
"north-east", "north-west", "south-east", "south-west"
|
"north-east", "north-west", "south-east", "south-west"
|
||||||
)
|
)
|
||||||
|
|
||||||
#let get-port-side(element, port) = {
|
|
||||||
for (side, ports) in element.ports {
|
|
||||||
for p in ports {
|
|
||||||
if p.id == port {
|
|
||||||
return side
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
panic("Unknown port " + port + " on element " + element.id)
|
|
||||||
}
|
|
@ -1,5 +1,6 @@
|
|||||||
#import "@preview/cetz:0.3.2": draw, coordinate
|
#import "@preview/cetz:0.3.2": draw, coordinate
|
||||||
#import "util.typ": opposite-anchor, get-port-side
|
#import "util.typ": opposite-anchor
|
||||||
|
#import "elements/ports.typ": get-port-side
|
||||||
#import "elements/element.typ"
|
#import "elements/element.typ"
|
||||||
|
|
||||||
/// List of valid wire styles
|
/// List of valid wire styles
|
||||||
|
Loading…
x
Reference in New Issue
Block a user