circuit-to-canvas 0.0.58 → 0.0.59

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "circuit-to-canvas",
3
3
  "main": "dist/index.js",
4
- "version": "0.0.58",
4
+ "version": "0.0.59",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "build": "tsup-node ./lib/index.ts --format esm --dts",
@@ -0,0 +1,259 @@
1
+ import { expect, test } from "bun:test"
2
+ import { createCanvas } from "@napi-rs/canvas"
3
+ import { CircuitToCanvasDrawer } from "../../lib/drawer"
4
+
5
+ test("draw trace with port hints", async () => {
6
+ const canvas = createCanvas(800, 600)
7
+ const ctx = canvas.getContext("2d")
8
+ const drawer = new CircuitToCanvasDrawer(ctx)
9
+
10
+ drawer.setCameraBounds({ minX: -8, minY: -2, maxX: 0, maxY: 6 })
11
+
12
+ ctx.fillStyle = "#1a1a1a"
13
+ ctx.fillRect(0, 0, 800, 600)
14
+
15
+ const circuit: any = [
16
+ {
17
+ type: "source_component",
18
+ source_component_id: "simple_resistor_0",
19
+ name: "R1",
20
+ supplier_part_numbers: {},
21
+ ftype: "simple_resistor",
22
+ resistance: "10k",
23
+ pcbX: -5,
24
+ pcbY: 0,
25
+ },
26
+ {
27
+ type: "schematic_component",
28
+ source_component_id: "simple_resistor_0",
29
+ schematic_component_id: "schematic_component_simple_resistor_0",
30
+ rotation: 0,
31
+ size: {
32
+ width: 1,
33
+ height: 0.3,
34
+ },
35
+ center: {
36
+ x: 0,
37
+ y: 0,
38
+ },
39
+ },
40
+ {
41
+ type: "source_port",
42
+ name: "left",
43
+ source_port_id: "source_port_0",
44
+ source_component_id: "simple_resistor_0",
45
+ },
46
+ {
47
+ type: "schematic_port",
48
+ schematic_port_id: "schematic_port_0",
49
+ source_port_id: "source_port_0",
50
+ center: {
51
+ x: -0.5,
52
+ y: 0,
53
+ },
54
+ facing_direction: "left",
55
+ schematic_component_id: "schematic_component_simple_resistor_0",
56
+ },
57
+ {
58
+ type: "pcb_port",
59
+ pcb_port_id: "pcb_port_0",
60
+ source_port_id: "source_port_0",
61
+ pcb_component_id: "pcb_component_simple_resistor_0",
62
+ x: -5.95,
63
+ y: 0,
64
+ layers: ["top"],
65
+ },
66
+ {
67
+ type: "source_port",
68
+ name: "right",
69
+ source_port_id: "source_port_1",
70
+ source_component_id: "simple_resistor_0",
71
+ },
72
+ {
73
+ type: "schematic_port",
74
+ schematic_port_id: "schematic_port_1",
75
+ source_port_id: "source_port_1",
76
+ center: {
77
+ x: 0.5,
78
+ y: 0,
79
+ },
80
+ facing_direction: "right",
81
+ schematic_component_id: "schematic_component_simple_resistor_0",
82
+ },
83
+ {
84
+ type: "pcb_port",
85
+ pcb_port_id: "pcb_port_1",
86
+ source_port_id: "source_port_1",
87
+ pcb_component_id: "pcb_component_simple_resistor_0",
88
+ x: -4.05,
89
+ y: 0,
90
+ layers: ["top"],
91
+ },
92
+ {
93
+ type: "schematic_text",
94
+ text: "R1",
95
+ schematic_text_id: "schematic_text_0",
96
+ schematic_component_id: "schematic_component_simple_resistor_0",
97
+ anchor: "left",
98
+ position: {
99
+ x: -0.2,
100
+ y: -0.5,
101
+ },
102
+ rotation: 0,
103
+ },
104
+ {
105
+ type: "schematic_text",
106
+ text: "10k",
107
+ schematic_text_id: "schematic_text_1",
108
+ schematic_component_id: "schematic_component_simple_resistor_0",
109
+ anchor: "left",
110
+ position: {
111
+ x: -0.2,
112
+ y: -0.3,
113
+ },
114
+ rotation: 0,
115
+ },
116
+ {
117
+ type: "pcb_component",
118
+ source_component_id: "simple_resistor_0",
119
+ pcb_component_id: "pcb_component_simple_resistor_0",
120
+ layer: "top",
121
+ center: {
122
+ x: -5,
123
+ y: 0,
124
+ },
125
+ rotation: 0,
126
+ width: 3.1,
127
+ height: 1.2,
128
+ },
129
+ {
130
+ type: "pcb_smtpad",
131
+ pcb_smtpad_id: "pcb_smtpad_0",
132
+ shape: "rect",
133
+ x: -5.95,
134
+ y: 0,
135
+ width: 1.2,
136
+ height: 1.2,
137
+ layer: "top",
138
+ pcb_component_id: "pcb_component_simple_resistor_0",
139
+ port_hints: ["1", "left"],
140
+ pcb_port_id: "pcb_port_0",
141
+ },
142
+ {
143
+ type: "pcb_smtpad",
144
+ pcb_smtpad_id: "pcb_smtpad_1",
145
+ shape: "rect",
146
+ x: -4.05,
147
+ y: 0,
148
+ width: 1.2,
149
+ height: 1.2,
150
+ layer: "top",
151
+ pcb_component_id: "pcb_component_simple_resistor_0",
152
+ port_hints: ["2", "right"],
153
+ pcb_port_id: "pcb_port_1",
154
+ },
155
+ {
156
+ type: "source_trace",
157
+ source_trace_id: "source_trace_0",
158
+ connected_source_port_ids: ["source_port_0", "source_port_1"],
159
+ connected_source_net_ids: [],
160
+ },
161
+ {
162
+ type: "schematic_trace",
163
+ source_trace_id: "source_trace_0",
164
+ schematic_trace_id: "schematic_trace_0",
165
+ edges: [
166
+ {
167
+ from: {
168
+ x: -0.6000000000000001,
169
+ y: 0,
170
+ },
171
+ to: {
172
+ x: -0.6000000000000001,
173
+ y: -0.19999999999999996,
174
+ },
175
+ },
176
+ {
177
+ from: {
178
+ x: -0.6000000000000001,
179
+ y: -0.19999999999999996,
180
+ },
181
+ to: {
182
+ x: 0.7000000000000002,
183
+ y: -0.19999999999999996,
184
+ },
185
+ },
186
+ {
187
+ from: {
188
+ x: 0.7000000000000002,
189
+ y: -0.19999999999999996,
190
+ },
191
+ to: {
192
+ x: 0.7000000000000002,
193
+ y: 0,
194
+ },
195
+ },
196
+ {
197
+ from: {
198
+ x: -0.5,
199
+ y: 0,
200
+ ti: 0,
201
+ },
202
+ to: {
203
+ x: -0.6000000000000001,
204
+ y: 0,
205
+ },
206
+ },
207
+ {
208
+ from: {
209
+ x: 0.5,
210
+ y: 0,
211
+ ti: 1,
212
+ },
213
+ to: {
214
+ x: 0.7000000000000002,
215
+ y: 0,
216
+ },
217
+ },
218
+ ],
219
+ },
220
+ {
221
+ type: "pcb_trace",
222
+ pcb_trace_id: "pcb_trace_0",
223
+ source_trace_id: "source_trace_0",
224
+ route_thickness_mode: "interpolated",
225
+ route: [
226
+ {
227
+ route_type: "wire",
228
+ layer: "top",
229
+ width: 0.2,
230
+ x: -4,
231
+ y: 0,
232
+ start_pcb_port_id: "pcb_port_0",
233
+ },
234
+ {
235
+ route_type: "wire",
236
+ layer: "top",
237
+ width: 0.5,
238
+ x: -5.9,
239
+ y: 4,
240
+ start_pcb_port_id: "pcb_port_1",
241
+ },
242
+ {
243
+ route_type: "wire",
244
+ layer: "top",
245
+ width: 0.5,
246
+ x: -5.9,
247
+ y: 0,
248
+ start_pcb_port_id: "pcb_port_1",
249
+ },
250
+ ],
251
+ },
252
+ ]
253
+
254
+ drawer.drawElements(circuit)
255
+
256
+ await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
257
+ import.meta.path,
258
+ )
259
+ })