feature: add IEC gates #11

Merged
HEL merged 7 commits from bono/circuiteria:add_iec_gates into dev 2025-06-29 13:19:57 +00:00
10 changed files with 509 additions and 1 deletions
Showing only changes of commit 8c91ccdd54 - Show all commits

View File

@ -3,40 +3,20 @@
#import "../element.typ"
#let default-draw-shape(id, tl, tr, br, bl, fill, stroke, symbol) = {
bono marked this conversation as resolved
Review

Here you can simplify this function greatly by just drawing a rectangle:

#let draw-shape(id, tl, tr, br, bl, fill, stroke, symbol) = {
  let shapes = draw.rect(
    inset: 0.5em,
    fill: fill,
    stroke: stroke,
    name: id,
    bl, tr
  )
  shapes += draw.content(
    id + ".center",
    [*$ symbol $*]
  )
  return (shapes, tl, tr, br, bl)
}
Here you can simplify this function greatly by just drawing a rectangle: ```typst #let draw-shape(id, tl, tr, br, bl, fill, stroke, symbol) = { let shapes = draw.rect( inset: 0.5em, fill: fill, stroke: stroke, name: id, bl, tr ) shapes += draw.content( id + ".center", [*$ symbol $*] ) return (shapes, tl, tr, br, bl) } ```
let (x, y) = bl
let (width, height) = (tr.at(0) - x, tr.at(1) - y)
let t = (x + width / 2, y + height)
let b = (x + width / 2, y)
let f = draw.group(
let shapes = draw.rect(
inset: 0.5em,
fill: fill,
stroke: stroke,
name: id,
{
draw.merge-path(
inset: 0.5em,
fill: fill,
stroke: stroke,
name: id + "-path",
close: true,
{
draw.line(bl, tl, tr, br)
},
)
draw.content(
(x + width / 2, y + height / 2),
padding: 0.5em,
align(center)[*$ symbol $*],
)
draw.anchor("north", t)
draw.anchor("south", b)
},
bl, tr
)
return (f, tl, tr, br, bl)
shapes += draw.content(
id + ".center",
[*$ symbol $*]
)
return (shapes, tl, tr, br, bl)
}
/// Draws a logic gate. This function is also available as `element.iec-gate()`
///
/// - draw-shape (function): see #doc-ref("element.elmt")