circuit-to-canvas 0.0.46 → 0.0.48
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/dist/index.d.ts +3 -2
- package/dist/index.js +272 -6
- package/lib/drawer/elements/pcb-copper-pour.ts +235 -2
- package/lib/drawer/elements/pcb-plated-hole.ts +40 -5
- package/lib/drawer/elements/pcb-smtpad.ts +29 -4
- package/lib/drawer/elements/soldermask-margin.ts +130 -0
- package/lib/drawer/types.ts +3 -1
- package/package.json +1 -1
- package/tests/elements/__snapshots__/brep-copper-pours.snap.png +0 -0
- package/tests/elements/__snapshots__/pcb-comprehensive-soldermask-margin.snap.png +0 -0
- package/tests/elements/__snapshots__/pcb-plated-hole-soldermask-margin.snap.png +0 -0
- package/tests/elements/__snapshots__/pcb-smtpad-soldermask-margin.snap.png +0 -0
- package/tests/elements/pcb-comprehensive-soldermask-margin.test.ts +1034 -83
- package/tests/elements/pcb-copper-pour.test.ts +171 -0
|
@@ -119,3 +119,174 @@ test("draw copper pour with trace", async () => {
|
|
|
119
119
|
"copper-pour-with-trace",
|
|
120
120
|
)
|
|
121
121
|
})
|
|
122
|
+
|
|
123
|
+
test("draw brep copper pours", async () => {
|
|
124
|
+
const canvas = createCanvas(200, 200)
|
|
125
|
+
const ctx = canvas.getContext("2d")
|
|
126
|
+
const drawer = new CircuitToCanvasDrawer(ctx)
|
|
127
|
+
|
|
128
|
+
// Set camera bounds to fit all elements
|
|
129
|
+
drawer.setCameraBounds({
|
|
130
|
+
minX: -100,
|
|
131
|
+
maxX: 100,
|
|
132
|
+
minY: -50,
|
|
133
|
+
maxY: 50,
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
ctx.fillStyle = "#1a1a1a"
|
|
137
|
+
ctx.fillRect(0, 0, 200, 200)
|
|
138
|
+
|
|
139
|
+
const soup: any[] = [
|
|
140
|
+
{
|
|
141
|
+
type: "pcb_board",
|
|
142
|
+
pcb_board_id: "board1",
|
|
143
|
+
center: { x: 0, y: 0 },
|
|
144
|
+
width: 200,
|
|
145
|
+
height: 100,
|
|
146
|
+
material: "fr4",
|
|
147
|
+
num_layers: 2,
|
|
148
|
+
thickness: 1.6,
|
|
149
|
+
},
|
|
150
|
+
// pour_brep_1: square with rounded-square hole
|
|
151
|
+
{
|
|
152
|
+
type: "pcb_copper_pour",
|
|
153
|
+
pcb_copper_pour_id: "pour_brep_1",
|
|
154
|
+
layer: "top",
|
|
155
|
+
shape: "brep",
|
|
156
|
+
source_net_id: "net1",
|
|
157
|
+
brep_shape: {
|
|
158
|
+
outer_ring: {
|
|
159
|
+
vertices: [
|
|
160
|
+
{ x: -30, y: 30 },
|
|
161
|
+
{ x: -50, y: 30 },
|
|
162
|
+
{ x: -50, y: 10 },
|
|
163
|
+
{ x: -30, y: 10 },
|
|
164
|
+
],
|
|
165
|
+
},
|
|
166
|
+
inner_rings: [
|
|
167
|
+
{
|
|
168
|
+
vertices: [
|
|
169
|
+
{ x: -35, y: 25, bulge: 0.5 },
|
|
170
|
+
{ x: -45, y: 25 },
|
|
171
|
+
{ x: -45, y: 15 },
|
|
172
|
+
{ x: -35, y: 15 },
|
|
173
|
+
],
|
|
174
|
+
},
|
|
175
|
+
],
|
|
176
|
+
},
|
|
177
|
+
} as PcbCopperPour,
|
|
178
|
+
// pour_brep_2: Bulgy outer ring, two holes
|
|
179
|
+
{
|
|
180
|
+
type: "pcb_copper_pour",
|
|
181
|
+
pcb_copper_pour_id: "pour_brep_2",
|
|
182
|
+
layer: "top",
|
|
183
|
+
shape: "brep",
|
|
184
|
+
source_net_id: "net2",
|
|
185
|
+
brep_shape: {
|
|
186
|
+
outer_ring: {
|
|
187
|
+
vertices: [
|
|
188
|
+
{ x: 10, y: 30, bulge: -0.5 },
|
|
189
|
+
{ x: -10, y: 30 },
|
|
190
|
+
{ x: -10, y: 10, bulge: 0.5 },
|
|
191
|
+
{ x: 10, y: 10 },
|
|
192
|
+
],
|
|
193
|
+
},
|
|
194
|
+
inner_rings: [
|
|
195
|
+
{
|
|
196
|
+
// square hole
|
|
197
|
+
vertices: [
|
|
198
|
+
{ x: -5, y: 25 },
|
|
199
|
+
{ x: -8, y: 25 },
|
|
200
|
+
{ x: -8, y: 22 },
|
|
201
|
+
{ x: -5, y: 22 },
|
|
202
|
+
],
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
// triangular hole
|
|
206
|
+
vertices: [
|
|
207
|
+
{ x: 5, y: 25 },
|
|
208
|
+
{ x: 8, y: 22 },
|
|
209
|
+
{ x: 5, y: 22 },
|
|
210
|
+
],
|
|
211
|
+
},
|
|
212
|
+
],
|
|
213
|
+
},
|
|
214
|
+
} as PcbCopperPour,
|
|
215
|
+
// pour_brep_3: Circular pour with square hole
|
|
216
|
+
{
|
|
217
|
+
type: "pcb_copper_pour",
|
|
218
|
+
pcb_copper_pour_id: "pour_brep_3",
|
|
219
|
+
layer: "top",
|
|
220
|
+
shape: "brep",
|
|
221
|
+
source_net_id: "net3",
|
|
222
|
+
brep_shape: {
|
|
223
|
+
outer_ring: {
|
|
224
|
+
vertices: [
|
|
225
|
+
{ x: 30, y: 20, bulge: 1 },
|
|
226
|
+
{ x: 50, y: 20, bulge: 1 },
|
|
227
|
+
],
|
|
228
|
+
},
|
|
229
|
+
inner_rings: [
|
|
230
|
+
{
|
|
231
|
+
vertices: [
|
|
232
|
+
{ x: 38, y: 22 },
|
|
233
|
+
{ x: 42, y: 22 },
|
|
234
|
+
{ x: 42, y: 18 },
|
|
235
|
+
{ x: 38, y: 18 },
|
|
236
|
+
],
|
|
237
|
+
},
|
|
238
|
+
],
|
|
239
|
+
},
|
|
240
|
+
} as PcbCopperPour,
|
|
241
|
+
// pour_brep_4: bottom layer pour
|
|
242
|
+
{
|
|
243
|
+
type: "pcb_copper_pour",
|
|
244
|
+
pcb_copper_pour_id: "pour_brep_4",
|
|
245
|
+
layer: "bottom",
|
|
246
|
+
shape: "brep",
|
|
247
|
+
source_net_id: "net4",
|
|
248
|
+
brep_shape: {
|
|
249
|
+
outer_ring: {
|
|
250
|
+
vertices: [
|
|
251
|
+
{ x: -30, y: -10 },
|
|
252
|
+
{ x: -50, y: -10 },
|
|
253
|
+
{ x: -50, y: -30 },
|
|
254
|
+
{ x: -30, y: -30, bulge: 0.5 },
|
|
255
|
+
],
|
|
256
|
+
},
|
|
257
|
+
},
|
|
258
|
+
} as PcbCopperPour,
|
|
259
|
+
// pour_rect_1: A rect pour with rotation
|
|
260
|
+
{
|
|
261
|
+
type: "pcb_copper_pour",
|
|
262
|
+
pcb_copper_pour_id: "pour_rect_1",
|
|
263
|
+
layer: "top",
|
|
264
|
+
shape: "rect",
|
|
265
|
+
source_net_id: "net5",
|
|
266
|
+
center: { x: 0, y: -20 },
|
|
267
|
+
width: 20,
|
|
268
|
+
height: 10,
|
|
269
|
+
rotation: 15,
|
|
270
|
+
} as PcbCopperPour,
|
|
271
|
+
// pour_polygon_1: A polygon pour (triangle)
|
|
272
|
+
{
|
|
273
|
+
type: "pcb_copper_pour",
|
|
274
|
+
pcb_copper_pour_id: "pour_polygon_1",
|
|
275
|
+
layer: "top",
|
|
276
|
+
shape: "polygon",
|
|
277
|
+
source_net_id: "net6",
|
|
278
|
+
points: [
|
|
279
|
+
{ x: 30, y: -10 },
|
|
280
|
+
{ x: 50, y: -30 },
|
|
281
|
+
{ x: 30, y: -30 },
|
|
282
|
+
],
|
|
283
|
+
} as PcbCopperPour,
|
|
284
|
+
]
|
|
285
|
+
|
|
286
|
+
drawer.drawElements(soup)
|
|
287
|
+
|
|
288
|
+
await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
|
|
289
|
+
import.meta.path,
|
|
290
|
+
"brep-copper-pours",
|
|
291
|
+
)
|
|
292
|
+
})
|