feature: add IEC gates #11

Open
bono wants to merge 2 commits from bono/circuiteria:add_iec_gates into dev
First-time contributor

Hey 👋, here is an initial implementation of the IEC gates I mentioned in #10 .

Feel free to suggest/perform any improvement.

Hey 👋, here is an initial implementation of the IEC gates I mentioned in #10 . Feel free to suggest/perform any improvement.
bono added 2 commits 2025-06-22 17:51:33 +00:00
Owner

Hey 👋, this looks pretty good, thanks for contributing !
I would just try to simplify the drawing process, since they are basically rectangles (see following comments)

I'll also add examples for the manual in a future PR, or you can copy those for the other gates (see doc/examples.typ)

Hey 👋, this looks pretty good, thanks for contributing ! I would just try to simplify the drawing process, since they are basically rectangles (see following comments) I'll also add examples for the manual in a future PR, or you can copy those for the other gates (see [doc/examples.typ](https://git.kb28.ch/HEL/circuiteria/src/commit/2bb7e3b5a98577297a53d4aefb8732e3dd761f4a/doc/examples.typ#L78-L116))
HEL reviewed 2025-06-24 22:03:43 +00:00
@ -0,0 +2,4 @@
#import "../ports.typ": add-ports, add-port
#import "../element.typ"
#let default-draw-shape(id, tl, tr, br, bl, fill, stroke, symbol) = {
Owner

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) } ```
HEL reviewed 2025-06-24 22:06:28 +00:00
@ -0,0 +112,4 @@
func
let space = 100% / inputs
for i in range(inputs) {
Owner

This for loop can also be simplified because we don't need to find intersections with the gate's contour (rectangular):

#{  // <- just for syntax highlighting

for i in range(inputs) {
  let pct = (i + 0.5) * space
  let port-pos = (tl, pct, bl)
  let port-name = "in" + str(i)
  if inverted == "all" or port-name in inverted {
    draw.circle(
      port-pos,
      radius: inverted-radius,
      anchor: "east",
      stroke: stroke
    )
    port-pos = (rel: (-2 * inverted-radius, 0), to: port-pos)
  }
  add-port(
    id, "west",
    (id: port-name), port-pos,
    debug: debug.ports
  )
}

}  // <- idem
This for loop can also be simplified because we don't need to find intersections with the gate's contour (rectangular): ```typst #{ // <- just for syntax highlighting for i in range(inputs) { let pct = (i + 0.5) * space let port-pos = (tl, pct, bl) let port-name = "in" + str(i) if inverted == "all" or port-name in inverted { draw.circle( port-pos, radius: inverted-radius, anchor: "east", stroke: stroke ) port-pos = (rel: (-2 * inverted-radius, 0), to: port-pos) } add-port( id, "west", (id: port-name), port-pos, debug: debug.ports ) } } // <- idem ```
HEL approved these changes 2025-06-24 22:12:53 +00:00
HEL left a comment
Owner

Typos in documentation refs

Typos in documentation refs
@ -0,0 +2,4 @@
#import "iec_gate.typ" as iec-gate
/// Draws an IEC buffer gate. This function is also available as `element.iec-gate-buf()`
Owner

Should be element.gate-iec-buf instead of element.iec-gate-buf

Should be `element.gate-iec-buf` instead of `element.iec-gate-buf`
@ -0,0 +35,4 @@
)
}
/// Draws an IEC NOT gate. This function is also available as `element.iec-gate-not()`
Owner

Should be element.gate-iec-not instead of element.iec-gate-not

Should be `element.gate-iec-not` instead of `element.iec-gate-not`
@ -0,0 +1,67 @@
#import "@preview/cetz:0.3.2": draw
#import "iec_gate.typ" as iec-gate
/// Draws an IEC-OR gate. This function is also available as `element.iec-gate-or()`
Owner

Should be element.gate-iec-or instead of element.iec-gate-or

Should be `element.gate-iec-or` instead of `element.iec-gate-or`
@ -0,0 +34,4 @@
)
}
/// Draws an IEC-NOR gate. This function is also available as `element.iec-gate-nor()`
Owner

Should be element.gate-iec-nor instead of element.iec-gate-nor

Should be `element.gate-iec-nor` instead of `element.iec-gate-nor`
@ -0,0 +1,67 @@
#import "@preview/cetz:0.3.2": draw
#import "iec_gate.typ" as iec-gate
/// Draws an IEC-XOR gate. This function is also available as `element.iec-gate-xor()`
Owner

Should be element.gate-iec-xor instead of element.iec-gate-xor

Should be `element.gate-iec-xor` instead of `element.iec-gate-xor`
@ -0,0 +34,4 @@
)
}
/// Draws an IEC-NXOR gate. This function is also available as `element.iec-gate-nxor()`
Owner

Should be element.gate-iec-xnor instead of element.iec-gate-xnor

Should be `element.gate-iec-xnor` instead of `element.iec-gate-xnor`
HEL requested review from HEL 2025-06-24 22:13:44 +00:00
HEL added the
new component
label 2025-06-24 22:14:59 +00:00
HEL changed target branch from main to dev 2025-06-24 22:18:19 +00:00
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u add_iec_gates:bono-add_iec_gates
git checkout bono-add_iec_gates
Sign in to join this conversation.
No Reviewers
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: HEL/circuiteria#11
No description provided.