forked from HEL/circuiteria
		
	Compare commits
	
		
			3 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 3aca407ce5 | |||
| 64278c924c | |||
| 4e125ef40c | 
| @@ -9,6 +9,6 @@ | ||||
| /// - length (length, ratio): Optional base unit | ||||
| /// -> none | ||||
| #let circuit(body, length: 2em) = { | ||||
|   set text(font: "Source Sans 3") | ||||
|   // set text(font: "Source Sans 3") | ||||
|   canvas(length: length, body) | ||||
| } | ||||
| @@ -56,18 +56,22 @@ | ||||
|   } | ||||
|  | ||||
|   if (type(y) == dictionary) { | ||||
|     let from = y.from | ||||
|     let offset = y.rel | ||||
|     let to = y.to | ||||
|     let (ctx, to-pos) = coordinate.resolve(ctx, (rel: (0, offset), to: to)) | ||||
|     y = to-pos.at(1) | ||||
|     // let from = y.from | ||||
|     // let to = y.to | ||||
|  | ||||
|     let dy | ||||
|     if to == "out" { | ||||
|       dy = height / 2 | ||||
|     } else { | ||||
|       dy = height * (i + 0.5) / inputs | ||||
|     } | ||||
|     // let dy | ||||
|     // if to == "out" { | ||||
|     //   dy = height / 2 | ||||
|     // } else { | ||||
|     //   dy = height * (i + 0.5) / inputs | ||||
|     // } | ||||
|  | ||||
|     let (ctx, from-pos) = coordinate.resolve(ctx, from) | ||||
|     y = from-pos.at(1) + dy - height | ||||
|     // let (ctx, from-pos) = coordinate.resolve(ctx, from) | ||||
|     // y = from-pos.at(1) + dy - height | ||||
|   } | ||||
|  | ||||
|   let tl = (x, y + height) | ||||
|   | ||||
							
								
								
									
										74
									
								
								src/wire.typ
									
									
									
									
									
								
							
							
						
						
									
										74
									
								
								src/wire.typ
									
									
									
									
									
								
							| @@ -19,7 +19,7 @@ | ||||
| #let get-direct-wire(pts) = { | ||||
|   let anchors = ( | ||||
|     "start": pts.first(), | ||||
|     "end": pts.last() | ||||
|     "end": pts.last(), | ||||
|   ) | ||||
|   return (pts, anchors) | ||||
| } | ||||
| @@ -38,21 +38,21 @@ | ||||
|       start, | ||||
|       (horizontal: mid, vertical: ()), | ||||
|       (horizontal: (), vertical: end), | ||||
|       end | ||||
|       end, | ||||
|     ) | ||||
|   } else { | ||||
|     ( | ||||
|       start, | ||||
|       (horizontal: (), vertical: mid), | ||||
|       (horizontal: end, vertical: ()), | ||||
|       end | ||||
|       end, | ||||
|     ) | ||||
|   } | ||||
|   let anchors = ( | ||||
|     "start": start, | ||||
|     "zig": points.at(1), | ||||
|     "zag": points.at(2), | ||||
|     "end": end | ||||
|     "end": end, | ||||
|   ) | ||||
|   return (points, anchors) | ||||
| } | ||||
| @@ -95,7 +95,7 @@ | ||||
|     (horizontal: (), vertical: (0, dodge-y)), | ||||
|     (horizontal: p2, vertical: ()), | ||||
|     (horizontal: (), vertical: end), | ||||
|     end | ||||
|     end, | ||||
|   ) | ||||
|   let anchors = ( | ||||
|     "start": start, | ||||
| @@ -103,7 +103,7 @@ | ||||
|     "dodge-start": points.at(2), | ||||
|     "dodge-end": points.at(3), | ||||
|     "end2": points.at(4), | ||||
|     "end": end | ||||
|     "end": end, | ||||
|   ) | ||||
|  | ||||
|   return (points, anchors) | ||||
| @@ -128,7 +128,8 @@ | ||||
| /// - dodge-sides (array): The start and end sides (going out of the connected element) of the wire (only with style "dodge") | ||||
| /// - dodge-margins (array): The start and end margins (i.e. space before dodging) of the wire (only with style "dodge") | ||||
| #let wire( | ||||
|   id, pts, | ||||
|   id, | ||||
|   pts, | ||||
|   bus: false, | ||||
|   name: none, | ||||
|   name-pos: "middle", | ||||
| @@ -143,7 +144,7 @@ | ||||
|   zigzag-dir: "vertical", | ||||
|   dodge-y: 0, | ||||
|   dodge-sides: ("east", "west"), | ||||
|   dodge-margins: (5%, 5%) | ||||
|   dodge-margins: (5%, 5%), | ||||
| ) = draw.get-ctx(ctx => { | ||||
|   if not style in wire-styles { | ||||
|     panic("Invalid wire style '" + style + "'") | ||||
| @@ -155,7 +156,11 @@ | ||||
|  | ||||
|   let stroke = ( | ||||
|     paint: color, | ||||
|     thickness: if bus {bus-width} else {signal-width} | ||||
|     thickness: if bus { | ||||
|       bus-width | ||||
|     } else { | ||||
|       signal-width | ||||
|     }, | ||||
|   ) | ||||
|   if dashed { | ||||
|     stroke.insert("dash", "dashed") | ||||
| @@ -176,7 +181,7 @@ | ||||
|       dodge-y, | ||||
|       dodge-margins, | ||||
|       dodge-sides, | ||||
|       ctx | ||||
|       ctx, | ||||
|     ) | ||||
|   } | ||||
|  | ||||
| @@ -184,12 +189,15 @@ | ||||
|   if directed { | ||||
|     mark = (end: ">", fill: color) | ||||
|   } | ||||
|   draw.group(name: id, { | ||||
|   draw.group( | ||||
|     name: id, | ||||
|     { | ||||
|       draw.line(..points, stroke: stroke, mark: mark) | ||||
|       for (anchor-name, anchor-pos) in anchors { | ||||
|         draw.anchor(anchor-name, anchor-pos) | ||||
|       } | ||||
|   }) | ||||
|     }, | ||||
|   ) | ||||
|  | ||||
|   let first-pt = id + ".start" | ||||
|   let last-pt = id + ".end" | ||||
| @@ -215,13 +223,13 @@ | ||||
|   if name != none { | ||||
|     let names = () | ||||
|  | ||||
|     if type(name) == str { | ||||
|     if type(name) == str or type(name) == content { | ||||
|       names = ((name, name-pos),) | ||||
|  | ||||
|     } else if type(name) == array { | ||||
|       names = ( | ||||
|         (name.at(0), "start"), | ||||
|         (name.at(1), "end") | ||||
|         (name.at(1), "end"), | ||||
|       ) | ||||
|     } | ||||
|  | ||||
| @@ -253,7 +261,7 @@ | ||||
|       first-pt, | ||||
|       anchor: "south-west", | ||||
|       padding: 3pt, | ||||
|       text(slice-txt, size: 0.75em) | ||||
|       text(slice-txt, size: 0.75em), | ||||
|     ) | ||||
|   } | ||||
| }) | ||||
| @@ -267,24 +275,38 @@ | ||||
| /// - vertical (bool): Whether the name should be displayed vertically | ||||
| /// - length (number): The length of the stub | ||||
| /// - name-offset (number): The name offset, perpendicular to the stub | ||||
| #let stub(port-id, side, name: none, vertical: false, length: 1em, name-offset: 0) = { | ||||
| #let stub( | ||||
|   port-id, | ||||
|   side, | ||||
|   name: none, | ||||
|   vertical: false, | ||||
|   length: 1em, | ||||
|   name-offset: 0, | ||||
|   color: black, | ||||
|   directed: none, | ||||
| ) = { | ||||
|   let end-offset = ( | ||||
|     north: (0, length), | ||||
|     east: (length, 0), | ||||
|     south: (0, -length), | ||||
|     west: (-length, 0) | ||||
|     west: (-length, 0), | ||||
|   ).at(side) | ||||
|  | ||||
|   let name-offset = ( | ||||
|     north: (name-offset, length), | ||||
|     east: (length, name-offset), | ||||
|     south: (name-offset, -length), | ||||
|     west: (-length, name-offset) | ||||
|     west: (-length, name-offset), | ||||
|   ).at(side) | ||||
|  | ||||
|   let mark = (fill: color) | ||||
|   if directed != none { | ||||
|     mark = ((directed): ">", fill: color) | ||||
|   } | ||||
|   draw.line( | ||||
|     port-id, | ||||
|     (rel: end-offset, to: port-id) | ||||
|     (rel: end-offset, to: port-id), | ||||
|     mark: mark, | ||||
|   ) | ||||
|   if name != none { | ||||
|     let text-anchor = if vertical { | ||||
| @@ -292,15 +314,21 @@ | ||||
|         "north": "west", | ||||
|         "south": "east", | ||||
|         "west": "south", | ||||
|         "east": "north" | ||||
|         "east": "north", | ||||
|       ).at(side) | ||||
|     } else { opposite-anchor(side) } | ||||
|     } else { | ||||
|       opposite-anchor(side) | ||||
|     } | ||||
|     draw.content( | ||||
|       anchor: text-anchor, | ||||
|       padding: 0.2em, | ||||
|       angle: if vertical {90deg} else {0deg}, | ||||
|       angle: if vertical { | ||||
|         90deg | ||||
|       } else { | ||||
|         0deg | ||||
|       }, | ||||
|       (rel: name-offset, to: port-id), | ||||
|       name | ||||
|       name, | ||||
|     ) | ||||
|   } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user