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))
Here you can simplify this function greatly by just drawing a rectangle:
#letdraw-shape(id,tl,tr,br,bl,fill,stroke,symbol)={letshapes=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)
}
```
This for loop can also be simplified because we don't need to find intersections with the gate's contour (rectangular):
#{// <- just for syntax highlightingforiinrange(inputs){letpct=(i+0.5)*spaceletport-pos=(tl,pct,bl)letport-name="in"+str(i)ifinverted=="all"orport-nameininverted{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
```
bono marked this conversation as resolved
HEL
approved these changes 2025-06-24 22:12:53 +00:00
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Hey 👋, here is an initial implementation of the IEC gates I mentioned in #10 .
Feel free to suggest/perform any improvement.
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)
@@ -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) = {Here you can simplify this function greatly by just drawing a rectangle:
@@ -0,0 +112,4 @@funclet space = 100% / inputsfor i in range(inputs) {This for loop can also be simplified because we don't need to find intersections with the gate's contour (rectangular):
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()`Should be
element.gate-iec-bufinstead ofelement.iec-gate-buf@@ -0,0 +35,4 @@)}/// Draws an IEC NOT gate. This function is also available as `element.iec-gate-not()`Should be
element.gate-iec-notinstead ofelement.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()`Should be
element.gate-iec-orinstead ofelement.iec-gate-or@@ -0,0 +34,4 @@)}/// Draws an IEC-NOR gate. This function is also available as `element.iec-gate-nor()`Should be
element.gate-iec-norinstead ofelement.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()`Should be
element.gate-iec-xorinstead ofelement.iec-gate-xor@@ -0,0 +34,4 @@)}/// Draws an IEC-NXOR gate. This function is also available as `element.iec-gate-nxor()`Should be
element.gate-iec-xnorinstead ofelement.iec-gate-xnorThanks for your comments, I added all requested changes, so it's ready for review again @HEL