circuit-to-canvas 0.0.23 → 0.0.24
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 +1 -1
- package/tests/elements/__snapshots__/fabrication-note-text-full-charset.snap.png +0 -0
- package/tests/elements/__snapshots__/pcb-board.snap.png +0 -0
- package/tests/elements/pcb-silkscreen-circle.test.ts +29 -0
- package/tests/elements/pcb-silkscreen-line.test.ts +31 -0
- package/tests/elements/pcb-silkscreen-on-component.test.ts +75 -0
- package/tests/elements/pcb-silkscreen-path.test.ts +36 -0
- package/tests/elements/pcb-silkscreen-rect.test.ts +30 -0
- package/tests/elements/pcb-silkscreen-text-bottom-rotated.test.ts +84 -0
- package/tests/elements/pcb-silkscreen-text-bottom.test.ts +31 -0
- package/tests/elements/pcb-silkscreen-text-rotated.test.ts +32 -0
- package/tests/elements/pcb-silkscreen-text.test.ts +31 -0
- package/tests/elements/pcb-smtpad-bottom-layer.test.ts +30 -0
- package/tests/elements/pcb-smtpad-circle.test.ts +29 -0
- package/tests/elements/pcb-smtpad-pill.test.ts +31 -0
- package/tests/elements/pcb-smtpad-polygon.test.ts +34 -0
- package/tests/elements/pcb-smtpad-rect-border-radius.test.ts +31 -0
- package/tests/elements/pcb-smtpad-rect.test.ts +30 -0
- package/tests/elements/pcb-smtpad-rotated-rect.test.ts +31 -0
- package/tests/elements/pcb-silkscreen.test.ts +0 -362
- package/tests/elements/pcb-smtpad.test.ts +0 -198
- /package/tests/elements/__snapshots__/{silkscreen-circle.snap.png → pcb-silkscreen-circle.snap.png} +0 -0
- /package/tests/elements/__snapshots__/{silkscreen-line.snap.png → pcb-silkscreen-line.snap.png} +0 -0
- /package/tests/elements/__snapshots__/{silkscreen-on-component.snap.png → pcb-silkscreen-on-component.snap.png} +0 -0
- /package/tests/elements/__snapshots__/{silkscreen-path.snap.png → pcb-silkscreen-path.snap.png} +0 -0
- /package/tests/elements/__snapshots__/{silkscreen-rect.snap.png → pcb-silkscreen-rect.snap.png} +0 -0
- /package/tests/elements/__snapshots__/{silkscreen-text-bottom-rotated.snap.png → pcb-silkscreen-text-bottom-rotated.snap.png} +0 -0
- /package/tests/elements/__snapshots__/{silkscreen-text-bottom.snap.png → pcb-silkscreen-text-bottom.snap.png} +0 -0
- /package/tests/elements/__snapshots__/{silkscreen-text-rotated.snap.png → pcb-silkscreen-text-rotated.snap.png} +0 -0
- /package/tests/elements/__snapshots__/{pcb-silkscreen.snap.png → pcb-silkscreen-text.snap.png} +0 -0
- /package/tests/elements/__snapshots__/{bottom-layer-pad.snap.png → pcb-smtpad-bottom-layer.snap.png} +0 -0
- /package/tests/elements/__snapshots__/{circular-pad.snap.png → pcb-smtpad-circle.snap.png} +0 -0
- /package/tests/elements/__snapshots__/{pill-pad.snap.png → pcb-smtpad-pill.snap.png} +0 -0
- /package/tests/elements/__snapshots__/{polygon-pad.snap.png → pcb-smtpad-polygon.snap.png} +0 -0
- /package/tests/elements/__snapshots__/{rect-pad-with-border-radius.snap.png → pcb-smtpad-rect-border-radius.snap.png} +0 -0
- /package/tests/elements/__snapshots__/{pcb-smtpad.snap.png → pcb-smtpad-rect.snap.png} +0 -0
- /package/tests/elements/__snapshots__/{rotated-rect-pad.snap.png → pcb-smtpad-rotated-rect.snap.png} +0 -0
package/package.json
CHANGED
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
|
+
import { createCanvas } from "@napi-rs/canvas"
|
|
3
|
+
import type { PcbSilkscreenCircle } from "circuit-json"
|
|
4
|
+
import { CircuitToCanvasDrawer } from "../../lib/drawer"
|
|
5
|
+
|
|
6
|
+
test("draw silkscreen circle", async () => {
|
|
7
|
+
const canvas = createCanvas(100, 100)
|
|
8
|
+
const ctx = canvas.getContext("2d")
|
|
9
|
+
const drawer = new CircuitToCanvasDrawer(ctx)
|
|
10
|
+
|
|
11
|
+
ctx.fillStyle = "#1a1a1a"
|
|
12
|
+
ctx.fillRect(0, 0, 100, 100)
|
|
13
|
+
|
|
14
|
+
const circle: PcbSilkscreenCircle = {
|
|
15
|
+
type: "pcb_silkscreen_circle",
|
|
16
|
+
pcb_silkscreen_circle_id: "circle1",
|
|
17
|
+
pcb_component_id: "component1",
|
|
18
|
+
layer: "top",
|
|
19
|
+
center: { x: 50, y: 50 },
|
|
20
|
+
radius: 20,
|
|
21
|
+
stroke_width: 0.2,
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
drawer.drawElements([circle])
|
|
25
|
+
|
|
26
|
+
await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
|
|
27
|
+
import.meta.path,
|
|
28
|
+
)
|
|
29
|
+
})
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
|
+
import { createCanvas } from "@napi-rs/canvas"
|
|
3
|
+
import type { PcbSilkscreenLine } from "circuit-json"
|
|
4
|
+
import { CircuitToCanvasDrawer } from "../../lib/drawer"
|
|
5
|
+
|
|
6
|
+
test("draw silkscreen line", async () => {
|
|
7
|
+
const canvas = createCanvas(100, 100)
|
|
8
|
+
const ctx = canvas.getContext("2d")
|
|
9
|
+
const drawer = new CircuitToCanvasDrawer(ctx)
|
|
10
|
+
|
|
11
|
+
ctx.fillStyle = "#1a1a1a"
|
|
12
|
+
ctx.fillRect(0, 0, 100, 100)
|
|
13
|
+
|
|
14
|
+
const line: PcbSilkscreenLine = {
|
|
15
|
+
type: "pcb_silkscreen_line",
|
|
16
|
+
pcb_silkscreen_line_id: "line1",
|
|
17
|
+
pcb_component_id: "component1",
|
|
18
|
+
layer: "top",
|
|
19
|
+
x1: 20,
|
|
20
|
+
y1: 20,
|
|
21
|
+
x2: 80,
|
|
22
|
+
y2: 80,
|
|
23
|
+
stroke_width: 2,
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
drawer.drawElements([line])
|
|
27
|
+
|
|
28
|
+
await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
|
|
29
|
+
import.meta.path,
|
|
30
|
+
)
|
|
31
|
+
})
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
|
+
import { createCanvas } from "@napi-rs/canvas"
|
|
3
|
+
import { CircuitToCanvasDrawer } from "../../lib/drawer"
|
|
4
|
+
|
|
5
|
+
test("draw silkscreen on component", async () => {
|
|
6
|
+
const canvas = createCanvas(150, 100)
|
|
7
|
+
const ctx = canvas.getContext("2d")
|
|
8
|
+
const drawer = new CircuitToCanvasDrawer(ctx)
|
|
9
|
+
|
|
10
|
+
ctx.fillStyle = "#1a1a1a"
|
|
11
|
+
ctx.fillRect(0, 0, 150, 100)
|
|
12
|
+
|
|
13
|
+
const elements = [
|
|
14
|
+
// Component outline
|
|
15
|
+
{
|
|
16
|
+
type: "pcb_silkscreen_rect" as const,
|
|
17
|
+
pcb_silkscreen_rect_id: "outline1",
|
|
18
|
+
pcb_component_id: "component1",
|
|
19
|
+
layer: "top" as const,
|
|
20
|
+
center: { x: 75, y: 50 },
|
|
21
|
+
width: 60,
|
|
22
|
+
height: 30,
|
|
23
|
+
stroke_width: 0.2,
|
|
24
|
+
},
|
|
25
|
+
// Pin 1 indicator
|
|
26
|
+
{
|
|
27
|
+
type: "pcb_silkscreen_circle" as const,
|
|
28
|
+
pcb_silkscreen_circle_id: "pin1marker",
|
|
29
|
+
pcb_component_id: "component1",
|
|
30
|
+
layer: "top" as const,
|
|
31
|
+
center: { x: 55, y: 40 },
|
|
32
|
+
radius: 3,
|
|
33
|
+
stroke_width: 0.2,
|
|
34
|
+
},
|
|
35
|
+
// Component label
|
|
36
|
+
{
|
|
37
|
+
type: "pcb_silkscreen_text" as const,
|
|
38
|
+
pcb_silkscreen_text_id: "label1",
|
|
39
|
+
pcb_component_id: "component1",
|
|
40
|
+
layer: "top" as const,
|
|
41
|
+
text: "IC1",
|
|
42
|
+
anchor_position: { x: 75, y: 50 },
|
|
43
|
+
anchor_alignment: "center" as const,
|
|
44
|
+
font: "tscircuit2024" as const,
|
|
45
|
+
font_size: 8,
|
|
46
|
+
},
|
|
47
|
+
// SMT pads
|
|
48
|
+
{
|
|
49
|
+
type: "pcb_smtpad" as const,
|
|
50
|
+
pcb_smtpad_id: "pad1",
|
|
51
|
+
shape: "rect" as const,
|
|
52
|
+
x: 55,
|
|
53
|
+
y: 50,
|
|
54
|
+
width: 10,
|
|
55
|
+
height: 5,
|
|
56
|
+
layer: "top" as const,
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
type: "pcb_smtpad" as const,
|
|
60
|
+
pcb_smtpad_id: "pad2",
|
|
61
|
+
shape: "rect" as const,
|
|
62
|
+
x: 95,
|
|
63
|
+
y: 50,
|
|
64
|
+
width: 10,
|
|
65
|
+
height: 5,
|
|
66
|
+
layer: "top" as const,
|
|
67
|
+
},
|
|
68
|
+
]
|
|
69
|
+
|
|
70
|
+
drawer.drawElements(elements)
|
|
71
|
+
|
|
72
|
+
await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
|
|
73
|
+
import.meta.path,
|
|
74
|
+
)
|
|
75
|
+
})
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
|
+
import { createCanvas } from "@napi-rs/canvas"
|
|
3
|
+
import type { PcbSilkscreenPath } from "circuit-json"
|
|
4
|
+
import { CircuitToCanvasDrawer } from "../../lib/drawer"
|
|
5
|
+
|
|
6
|
+
test("draw silkscreen path", async () => {
|
|
7
|
+
const canvas = createCanvas(100, 100)
|
|
8
|
+
const ctx = canvas.getContext("2d")
|
|
9
|
+
const drawer = new CircuitToCanvasDrawer(ctx)
|
|
10
|
+
|
|
11
|
+
ctx.fillStyle = "#1a1a1a"
|
|
12
|
+
ctx.fillRect(0, 0, 100, 100)
|
|
13
|
+
|
|
14
|
+
const path: PcbSilkscreenPath = {
|
|
15
|
+
type: "pcb_silkscreen_path",
|
|
16
|
+
pcb_silkscreen_path_id: "path1",
|
|
17
|
+
pcb_component_id: "component1",
|
|
18
|
+
layer: "top",
|
|
19
|
+
route: [
|
|
20
|
+
{ x: 10, y: 50 },
|
|
21
|
+
{ x: 30, y: 20 },
|
|
22
|
+
{ x: 70, y: 20 },
|
|
23
|
+
{ x: 90, y: 50 },
|
|
24
|
+
{ x: 70, y: 80 },
|
|
25
|
+
{ x: 30, y: 80 },
|
|
26
|
+
{ x: 10, y: 50 },
|
|
27
|
+
],
|
|
28
|
+
stroke_width: 2,
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
drawer.drawElements([path])
|
|
32
|
+
|
|
33
|
+
await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
|
|
34
|
+
import.meta.path,
|
|
35
|
+
)
|
|
36
|
+
})
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
|
+
import { createCanvas } from "@napi-rs/canvas"
|
|
3
|
+
import type { PcbSilkscreenRect } from "circuit-json"
|
|
4
|
+
import { CircuitToCanvasDrawer } from "../../lib/drawer"
|
|
5
|
+
|
|
6
|
+
test("draw silkscreen rect", async () => {
|
|
7
|
+
const canvas = createCanvas(100, 100)
|
|
8
|
+
const ctx = canvas.getContext("2d")
|
|
9
|
+
const drawer = new CircuitToCanvasDrawer(ctx)
|
|
10
|
+
|
|
11
|
+
ctx.fillStyle = "#1a1a1a"
|
|
12
|
+
ctx.fillRect(0, 0, 100, 100)
|
|
13
|
+
|
|
14
|
+
const rect: PcbSilkscreenRect = {
|
|
15
|
+
type: "pcb_silkscreen_rect",
|
|
16
|
+
pcb_silkscreen_rect_id: "rect1",
|
|
17
|
+
pcb_component_id: "component1",
|
|
18
|
+
layer: "top",
|
|
19
|
+
center: { x: 50, y: 50 },
|
|
20
|
+
width: 40,
|
|
21
|
+
height: 20,
|
|
22
|
+
stroke_width: 0.2,
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
drawer.drawElements([rect])
|
|
26
|
+
|
|
27
|
+
await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
|
|
28
|
+
import.meta.path,
|
|
29
|
+
)
|
|
30
|
+
})
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
|
+
import { createCanvas } from "@napi-rs/canvas"
|
|
3
|
+
import type { PcbSilkscreenText } from "circuit-json"
|
|
4
|
+
import { CircuitToCanvasDrawer } from "../../lib/drawer"
|
|
5
|
+
|
|
6
|
+
test("draw silkscreen text bottom layer with rotation - tests transform order", async () => {
|
|
7
|
+
const canvas = createCanvas(150, 150)
|
|
8
|
+
const ctx = canvas.getContext("2d")
|
|
9
|
+
const drawer = new CircuitToCanvasDrawer(ctx)
|
|
10
|
+
|
|
11
|
+
ctx.fillStyle = "#1a1a1a"
|
|
12
|
+
ctx.fillRect(0, 0, 150, 150)
|
|
13
|
+
|
|
14
|
+
// This test verifies the transform order (translate -> rotate -> scale) is correct
|
|
15
|
+
// by testing bottom layer text with various rotations
|
|
16
|
+
const texts: PcbSilkscreenText[] = [
|
|
17
|
+
{
|
|
18
|
+
type: "pcb_silkscreen_text",
|
|
19
|
+
pcb_silkscreen_text_id: "text1",
|
|
20
|
+
pcb_component_id: "component1",
|
|
21
|
+
layer: "bottom",
|
|
22
|
+
text: "0",
|
|
23
|
+
anchor_position: { x: 75, y: 30 },
|
|
24
|
+
anchor_alignment: "center",
|
|
25
|
+
font: "tscircuit2024",
|
|
26
|
+
font_size: 6,
|
|
27
|
+
ccw_rotation: 0,
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
type: "pcb_silkscreen_text",
|
|
31
|
+
pcb_silkscreen_text_id: "text2",
|
|
32
|
+
pcb_component_id: "component1",
|
|
33
|
+
layer: "bottom",
|
|
34
|
+
text: "90",
|
|
35
|
+
anchor_position: { x: 120, y: 75 },
|
|
36
|
+
anchor_alignment: "center",
|
|
37
|
+
font: "tscircuit2024",
|
|
38
|
+
font_size: 6,
|
|
39
|
+
ccw_rotation: 90,
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
type: "pcb_silkscreen_text",
|
|
43
|
+
pcb_silkscreen_text_id: "text3",
|
|
44
|
+
pcb_component_id: "component1",
|
|
45
|
+
layer: "bottom",
|
|
46
|
+
text: "180",
|
|
47
|
+
anchor_position: { x: 75, y: 120 },
|
|
48
|
+
anchor_alignment: "center",
|
|
49
|
+
font: "tscircuit2024",
|
|
50
|
+
font_size: 6,
|
|
51
|
+
ccw_rotation: 180,
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
type: "pcb_silkscreen_text",
|
|
55
|
+
pcb_silkscreen_text_id: "text4",
|
|
56
|
+
pcb_component_id: "component1",
|
|
57
|
+
layer: "bottom",
|
|
58
|
+
text: "270",
|
|
59
|
+
anchor_position: { x: 30, y: 75 },
|
|
60
|
+
anchor_alignment: "center",
|
|
61
|
+
font: "tscircuit2024",
|
|
62
|
+
font_size: 6,
|
|
63
|
+
ccw_rotation: 270,
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
type: "pcb_silkscreen_text",
|
|
67
|
+
pcb_silkscreen_text_id: "text5",
|
|
68
|
+
pcb_component_id: "component1",
|
|
69
|
+
layer: "bottom",
|
|
70
|
+
text: "BTM",
|
|
71
|
+
anchor_position: { x: 75, y: 75 },
|
|
72
|
+
anchor_alignment: "center",
|
|
73
|
+
font: "tscircuit2024",
|
|
74
|
+
font_size: 8,
|
|
75
|
+
ccw_rotation: 45,
|
|
76
|
+
},
|
|
77
|
+
]
|
|
78
|
+
|
|
79
|
+
drawer.drawElements(texts)
|
|
80
|
+
|
|
81
|
+
await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
|
|
82
|
+
import.meta.path,
|
|
83
|
+
)
|
|
84
|
+
})
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
|
+
import { createCanvas } from "@napi-rs/canvas"
|
|
3
|
+
import type { PcbSilkscreenText } from "circuit-json"
|
|
4
|
+
import { CircuitToCanvasDrawer } from "../../lib/drawer"
|
|
5
|
+
|
|
6
|
+
test("draw silkscreen text bottom layer", async () => {
|
|
7
|
+
const canvas = createCanvas(100, 100)
|
|
8
|
+
const ctx = canvas.getContext("2d")
|
|
9
|
+
const drawer = new CircuitToCanvasDrawer(ctx)
|
|
10
|
+
|
|
11
|
+
ctx.fillStyle = "#1a1a1a"
|
|
12
|
+
ctx.fillRect(0, 0, 100, 100)
|
|
13
|
+
|
|
14
|
+
const text: PcbSilkscreenText = {
|
|
15
|
+
type: "pcb_silkscreen_text",
|
|
16
|
+
pcb_silkscreen_text_id: "text1",
|
|
17
|
+
pcb_component_id: "component1",
|
|
18
|
+
layer: "bottom",
|
|
19
|
+
text: "BOTTOM",
|
|
20
|
+
anchor_position: { x: 50, y: 50 },
|
|
21
|
+
anchor_alignment: "center",
|
|
22
|
+
font: "tscircuit2024",
|
|
23
|
+
font_size: 8,
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
drawer.drawElements([text])
|
|
27
|
+
|
|
28
|
+
await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
|
|
29
|
+
import.meta.path,
|
|
30
|
+
)
|
|
31
|
+
})
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
|
+
import { createCanvas } from "@napi-rs/canvas"
|
|
3
|
+
import type { PcbSilkscreenText } from "circuit-json"
|
|
4
|
+
import { CircuitToCanvasDrawer } from "../../lib/drawer"
|
|
5
|
+
|
|
6
|
+
test("draw silkscreen text with rotation", async () => {
|
|
7
|
+
const canvas = createCanvas(100, 100)
|
|
8
|
+
const ctx = canvas.getContext("2d")
|
|
9
|
+
const drawer = new CircuitToCanvasDrawer(ctx)
|
|
10
|
+
|
|
11
|
+
ctx.fillStyle = "#1a1a1a"
|
|
12
|
+
ctx.fillRect(0, 0, 100, 100)
|
|
13
|
+
|
|
14
|
+
const text: PcbSilkscreenText = {
|
|
15
|
+
type: "pcb_silkscreen_text",
|
|
16
|
+
pcb_silkscreen_text_id: "text1",
|
|
17
|
+
pcb_component_id: "component1",
|
|
18
|
+
layer: "top",
|
|
19
|
+
text: "ROT45",
|
|
20
|
+
anchor_position: { x: 50, y: 50 },
|
|
21
|
+
anchor_alignment: "center",
|
|
22
|
+
font: "tscircuit2024",
|
|
23
|
+
font_size: 8,
|
|
24
|
+
ccw_rotation: 45,
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
drawer.drawElements([text])
|
|
28
|
+
|
|
29
|
+
await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
|
|
30
|
+
import.meta.path,
|
|
31
|
+
)
|
|
32
|
+
})
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
|
+
import { createCanvas } from "@napi-rs/canvas"
|
|
3
|
+
import type { PcbSilkscreenText } from "circuit-json"
|
|
4
|
+
import { CircuitToCanvasDrawer } from "../../lib/drawer"
|
|
5
|
+
|
|
6
|
+
test("draw silkscreen text", async () => {
|
|
7
|
+
const canvas = createCanvas(100, 100)
|
|
8
|
+
const ctx = canvas.getContext("2d")
|
|
9
|
+
const drawer = new CircuitToCanvasDrawer(ctx)
|
|
10
|
+
|
|
11
|
+
ctx.fillStyle = "#1a1a1a"
|
|
12
|
+
ctx.fillRect(0, 0, 100, 100)
|
|
13
|
+
|
|
14
|
+
const text: PcbSilkscreenText = {
|
|
15
|
+
type: "pcb_silkscreen_text",
|
|
16
|
+
pcb_silkscreen_text_id: "text1",
|
|
17
|
+
pcb_component_id: "component1",
|
|
18
|
+
layer: "top",
|
|
19
|
+
text: "U1",
|
|
20
|
+
anchor_position: { x: 50, y: 50 },
|
|
21
|
+
anchor_alignment: "center",
|
|
22
|
+
font: "tscircuit2024",
|
|
23
|
+
font_size: 8,
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
drawer.drawElements([text])
|
|
27
|
+
|
|
28
|
+
await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
|
|
29
|
+
import.meta.path,
|
|
30
|
+
)
|
|
31
|
+
})
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
|
+
import { createCanvas } from "@napi-rs/canvas"
|
|
3
|
+
import type { PcbSmtPad } from "circuit-json"
|
|
4
|
+
import { CircuitToCanvasDrawer } from "../../lib/drawer"
|
|
5
|
+
|
|
6
|
+
test("draw bottom layer smt pad", async () => {
|
|
7
|
+
const canvas = createCanvas(100, 100)
|
|
8
|
+
const ctx = canvas.getContext("2d")
|
|
9
|
+
const drawer = new CircuitToCanvasDrawer(ctx)
|
|
10
|
+
|
|
11
|
+
ctx.fillStyle = "#1a1a1a"
|
|
12
|
+
ctx.fillRect(0, 0, 100, 100)
|
|
13
|
+
|
|
14
|
+
const pad: PcbSmtPad = {
|
|
15
|
+
type: "pcb_smtpad",
|
|
16
|
+
pcb_smtpad_id: "pad1",
|
|
17
|
+
shape: "rect",
|
|
18
|
+
x: 50,
|
|
19
|
+
y: 50,
|
|
20
|
+
width: 40,
|
|
21
|
+
height: 20,
|
|
22
|
+
layer: "bottom",
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
drawer.drawElements([pad])
|
|
26
|
+
|
|
27
|
+
await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
|
|
28
|
+
import.meta.path,
|
|
29
|
+
)
|
|
30
|
+
})
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
|
+
import { createCanvas } from "@napi-rs/canvas"
|
|
3
|
+
import type { PcbSmtPad } from "circuit-json"
|
|
4
|
+
import { CircuitToCanvasDrawer } from "../../lib/drawer"
|
|
5
|
+
|
|
6
|
+
test("draw circular smt pad", async () => {
|
|
7
|
+
const canvas = createCanvas(100, 100)
|
|
8
|
+
const ctx = canvas.getContext("2d")
|
|
9
|
+
const drawer = new CircuitToCanvasDrawer(ctx)
|
|
10
|
+
|
|
11
|
+
ctx.fillStyle = "#1a1a1a"
|
|
12
|
+
ctx.fillRect(0, 0, 100, 100)
|
|
13
|
+
|
|
14
|
+
const pad: PcbSmtPad = {
|
|
15
|
+
type: "pcb_smtpad",
|
|
16
|
+
pcb_smtpad_id: "pad1",
|
|
17
|
+
shape: "circle",
|
|
18
|
+
x: 50,
|
|
19
|
+
y: 50,
|
|
20
|
+
radius: 20,
|
|
21
|
+
layer: "top",
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
drawer.drawElements([pad])
|
|
25
|
+
|
|
26
|
+
await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
|
|
27
|
+
import.meta.path,
|
|
28
|
+
)
|
|
29
|
+
})
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
|
+
import { createCanvas } from "@napi-rs/canvas"
|
|
3
|
+
import type { PcbSmtPad } from "circuit-json"
|
|
4
|
+
import { CircuitToCanvasDrawer } from "../../lib/drawer"
|
|
5
|
+
|
|
6
|
+
test("draw pill smt pad", async () => {
|
|
7
|
+
const canvas = createCanvas(100, 100)
|
|
8
|
+
const ctx = canvas.getContext("2d")
|
|
9
|
+
const drawer = new CircuitToCanvasDrawer(ctx)
|
|
10
|
+
|
|
11
|
+
ctx.fillStyle = "#1a1a1a"
|
|
12
|
+
ctx.fillRect(0, 0, 100, 100)
|
|
13
|
+
|
|
14
|
+
const pad: PcbSmtPad = {
|
|
15
|
+
type: "pcb_smtpad",
|
|
16
|
+
pcb_smtpad_id: "pad1",
|
|
17
|
+
shape: "pill",
|
|
18
|
+
x: 50,
|
|
19
|
+
y: 50,
|
|
20
|
+
width: 50,
|
|
21
|
+
height: 25,
|
|
22
|
+
radius: 12.5,
|
|
23
|
+
layer: "top",
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
drawer.drawElements([pad])
|
|
27
|
+
|
|
28
|
+
await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
|
|
29
|
+
import.meta.path,
|
|
30
|
+
)
|
|
31
|
+
})
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
|
+
import { createCanvas } from "@napi-rs/canvas"
|
|
3
|
+
import type { PcbSmtPad } from "circuit-json"
|
|
4
|
+
import { CircuitToCanvasDrawer } from "../../lib/drawer"
|
|
5
|
+
|
|
6
|
+
test("draw polygon smt pad", async () => {
|
|
7
|
+
const canvas = createCanvas(100, 100)
|
|
8
|
+
const ctx = canvas.getContext("2d")
|
|
9
|
+
const drawer = new CircuitToCanvasDrawer(ctx)
|
|
10
|
+
|
|
11
|
+
ctx.fillStyle = "#1a1a1a"
|
|
12
|
+
ctx.fillRect(0, 0, 100, 100)
|
|
13
|
+
|
|
14
|
+
const pad: PcbSmtPad = {
|
|
15
|
+
type: "pcb_smtpad",
|
|
16
|
+
pcb_smtpad_id: "pad1",
|
|
17
|
+
shape: "polygon",
|
|
18
|
+
layer: "top",
|
|
19
|
+
points: [
|
|
20
|
+
{ x: 30, y: 30 },
|
|
21
|
+
{ x: 70, y: 30 },
|
|
22
|
+
{ x: 80, y: 50 },
|
|
23
|
+
{ x: 70, y: 70 },
|
|
24
|
+
{ x: 30, y: 70 },
|
|
25
|
+
{ x: 20, y: 50 },
|
|
26
|
+
],
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
drawer.drawElements([pad])
|
|
30
|
+
|
|
31
|
+
await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
|
|
32
|
+
import.meta.path,
|
|
33
|
+
)
|
|
34
|
+
})
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
|
+
import { createCanvas } from "@napi-rs/canvas"
|
|
3
|
+
import type { PcbSmtPad } from "circuit-json"
|
|
4
|
+
import { CircuitToCanvasDrawer } from "../../lib/drawer"
|
|
5
|
+
|
|
6
|
+
test("draw rectangular smt pad with border radius", async () => {
|
|
7
|
+
const canvas = createCanvas(100, 100)
|
|
8
|
+
const ctx = canvas.getContext("2d")
|
|
9
|
+
const drawer = new CircuitToCanvasDrawer(ctx)
|
|
10
|
+
|
|
11
|
+
ctx.fillStyle = "#1a1a1a"
|
|
12
|
+
ctx.fillRect(0, 0, 100, 100)
|
|
13
|
+
|
|
14
|
+
const pad: PcbSmtPad = {
|
|
15
|
+
type: "pcb_smtpad",
|
|
16
|
+
pcb_smtpad_id: "pad1",
|
|
17
|
+
shape: "rect",
|
|
18
|
+
x: 50,
|
|
19
|
+
y: 50,
|
|
20
|
+
width: 40,
|
|
21
|
+
height: 20,
|
|
22
|
+
layer: "top",
|
|
23
|
+
rect_border_radius: 5,
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
drawer.drawElements([pad])
|
|
27
|
+
|
|
28
|
+
await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
|
|
29
|
+
import.meta.path,
|
|
30
|
+
)
|
|
31
|
+
})
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
|
+
import { createCanvas } from "@napi-rs/canvas"
|
|
3
|
+
import type { PcbSmtPad } from "circuit-json"
|
|
4
|
+
import { CircuitToCanvasDrawer } from "../../lib/drawer"
|
|
5
|
+
|
|
6
|
+
test("draw rectangular smt pad", async () => {
|
|
7
|
+
const canvas = createCanvas(100, 100)
|
|
8
|
+
const ctx = canvas.getContext("2d")
|
|
9
|
+
const drawer = new CircuitToCanvasDrawer(ctx)
|
|
10
|
+
|
|
11
|
+
ctx.fillStyle = "#1a1a1a"
|
|
12
|
+
ctx.fillRect(0, 0, 100, 100)
|
|
13
|
+
|
|
14
|
+
const pad: PcbSmtPad = {
|
|
15
|
+
type: "pcb_smtpad",
|
|
16
|
+
pcb_smtpad_id: "pad1",
|
|
17
|
+
shape: "rect",
|
|
18
|
+
x: 50,
|
|
19
|
+
y: 50,
|
|
20
|
+
width: 40,
|
|
21
|
+
height: 20,
|
|
22
|
+
layer: "top",
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
drawer.drawElements([pad])
|
|
26
|
+
|
|
27
|
+
await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
|
|
28
|
+
import.meta.path,
|
|
29
|
+
)
|
|
30
|
+
})
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
|
+
import { createCanvas } from "@napi-rs/canvas"
|
|
3
|
+
import type { PcbSmtPad } from "circuit-json"
|
|
4
|
+
import { CircuitToCanvasDrawer } from "../../lib/drawer"
|
|
5
|
+
|
|
6
|
+
test("draw rotated rectangular smt pad", async () => {
|
|
7
|
+
const canvas = createCanvas(100, 100)
|
|
8
|
+
const ctx = canvas.getContext("2d")
|
|
9
|
+
const drawer = new CircuitToCanvasDrawer(ctx)
|
|
10
|
+
|
|
11
|
+
ctx.fillStyle = "#1a1a1a"
|
|
12
|
+
ctx.fillRect(0, 0, 100, 100)
|
|
13
|
+
|
|
14
|
+
const pad: PcbSmtPad = {
|
|
15
|
+
type: "pcb_smtpad",
|
|
16
|
+
pcb_smtpad_id: "pad1",
|
|
17
|
+
shape: "rotated_rect",
|
|
18
|
+
x: 50,
|
|
19
|
+
y: 50,
|
|
20
|
+
width: 40,
|
|
21
|
+
height: 20,
|
|
22
|
+
layer: "top",
|
|
23
|
+
ccw_rotation: 45,
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
drawer.drawElements([pad])
|
|
27
|
+
|
|
28
|
+
await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
|
|
29
|
+
import.meta.path,
|
|
30
|
+
)
|
|
31
|
+
})
|
|
@@ -1,362 +0,0 @@
|
|
|
1
|
-
import { expect, test } from "bun:test"
|
|
2
|
-
import { createCanvas } from "@napi-rs/canvas"
|
|
3
|
-
import type {
|
|
4
|
-
PcbSilkscreenText,
|
|
5
|
-
PcbSilkscreenRect,
|
|
6
|
-
PcbSilkscreenCircle,
|
|
7
|
-
PcbSilkscreenLine,
|
|
8
|
-
PcbSilkscreenPath,
|
|
9
|
-
} from "circuit-json"
|
|
10
|
-
import { CircuitToCanvasDrawer } from "../../lib/drawer"
|
|
11
|
-
|
|
12
|
-
test("draw silkscreen text", async () => {
|
|
13
|
-
const canvas = createCanvas(100, 100)
|
|
14
|
-
const ctx = canvas.getContext("2d")
|
|
15
|
-
const drawer = new CircuitToCanvasDrawer(ctx)
|
|
16
|
-
|
|
17
|
-
ctx.fillStyle = "#1a1a1a"
|
|
18
|
-
ctx.fillRect(0, 0, 100, 100)
|
|
19
|
-
|
|
20
|
-
const text: PcbSilkscreenText = {
|
|
21
|
-
type: "pcb_silkscreen_text",
|
|
22
|
-
pcb_silkscreen_text_id: "text1",
|
|
23
|
-
pcb_component_id: "component1",
|
|
24
|
-
layer: "top",
|
|
25
|
-
text: "U1",
|
|
26
|
-
anchor_position: { x: 50, y: 50 },
|
|
27
|
-
anchor_alignment: "center",
|
|
28
|
-
font: "tscircuit2024",
|
|
29
|
-
font_size: 8,
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
drawer.drawElements([text])
|
|
33
|
-
|
|
34
|
-
await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
|
|
35
|
-
import.meta.path,
|
|
36
|
-
)
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
test("draw silkscreen text bottom layer", async () => {
|
|
40
|
-
const canvas = createCanvas(100, 100)
|
|
41
|
-
const ctx = canvas.getContext("2d")
|
|
42
|
-
const drawer = new CircuitToCanvasDrawer(ctx)
|
|
43
|
-
|
|
44
|
-
ctx.fillStyle = "#1a1a1a"
|
|
45
|
-
ctx.fillRect(0, 0, 100, 100)
|
|
46
|
-
|
|
47
|
-
const text: PcbSilkscreenText = {
|
|
48
|
-
type: "pcb_silkscreen_text",
|
|
49
|
-
pcb_silkscreen_text_id: "text1",
|
|
50
|
-
pcb_component_id: "component1",
|
|
51
|
-
layer: "bottom",
|
|
52
|
-
text: "BOTTOM",
|
|
53
|
-
anchor_position: { x: 50, y: 50 },
|
|
54
|
-
anchor_alignment: "center",
|
|
55
|
-
font: "tscircuit2024",
|
|
56
|
-
font_size: 8,
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
drawer.drawElements([text])
|
|
60
|
-
|
|
61
|
-
await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
|
|
62
|
-
import.meta.path,
|
|
63
|
-
"silkscreen-text-bottom",
|
|
64
|
-
)
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
test("draw silkscreen text with rotation", async () => {
|
|
68
|
-
const canvas = createCanvas(100, 100)
|
|
69
|
-
const ctx = canvas.getContext("2d")
|
|
70
|
-
const drawer = new CircuitToCanvasDrawer(ctx)
|
|
71
|
-
|
|
72
|
-
ctx.fillStyle = "#1a1a1a"
|
|
73
|
-
ctx.fillRect(0, 0, 100, 100)
|
|
74
|
-
|
|
75
|
-
const text: PcbSilkscreenText = {
|
|
76
|
-
type: "pcb_silkscreen_text",
|
|
77
|
-
pcb_silkscreen_text_id: "text1",
|
|
78
|
-
pcb_component_id: "component1",
|
|
79
|
-
layer: "top",
|
|
80
|
-
text: "ROT45",
|
|
81
|
-
anchor_position: { x: 50, y: 50 },
|
|
82
|
-
anchor_alignment: "center",
|
|
83
|
-
font: "tscircuit2024",
|
|
84
|
-
font_size: 8,
|
|
85
|
-
ccw_rotation: 45,
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
drawer.drawElements([text])
|
|
89
|
-
|
|
90
|
-
await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
|
|
91
|
-
import.meta.path,
|
|
92
|
-
"silkscreen-text-rotated",
|
|
93
|
-
)
|
|
94
|
-
})
|
|
95
|
-
|
|
96
|
-
test("draw silkscreen text bottom layer with rotation - tests transform order", async () => {
|
|
97
|
-
const canvas = createCanvas(150, 150)
|
|
98
|
-
const ctx = canvas.getContext("2d")
|
|
99
|
-
const drawer = new CircuitToCanvasDrawer(ctx)
|
|
100
|
-
|
|
101
|
-
ctx.fillStyle = "#1a1a1a"
|
|
102
|
-
ctx.fillRect(0, 0, 150, 150)
|
|
103
|
-
|
|
104
|
-
// This test verifies the transform order (translate -> rotate -> scale) is correct
|
|
105
|
-
// by testing bottom layer text with various rotations
|
|
106
|
-
const texts: PcbSilkscreenText[] = [
|
|
107
|
-
{
|
|
108
|
-
type: "pcb_silkscreen_text",
|
|
109
|
-
pcb_silkscreen_text_id: "text1",
|
|
110
|
-
pcb_component_id: "component1",
|
|
111
|
-
layer: "bottom",
|
|
112
|
-
text: "0",
|
|
113
|
-
anchor_position: { x: 75, y: 30 },
|
|
114
|
-
anchor_alignment: "center",
|
|
115
|
-
font: "tscircuit2024",
|
|
116
|
-
font_size: 6,
|
|
117
|
-
ccw_rotation: 0,
|
|
118
|
-
},
|
|
119
|
-
{
|
|
120
|
-
type: "pcb_silkscreen_text",
|
|
121
|
-
pcb_silkscreen_text_id: "text2",
|
|
122
|
-
pcb_component_id: "component1",
|
|
123
|
-
layer: "bottom",
|
|
124
|
-
text: "90",
|
|
125
|
-
anchor_position: { x: 120, y: 75 },
|
|
126
|
-
anchor_alignment: "center",
|
|
127
|
-
font: "tscircuit2024",
|
|
128
|
-
font_size: 6,
|
|
129
|
-
ccw_rotation: 90,
|
|
130
|
-
},
|
|
131
|
-
{
|
|
132
|
-
type: "pcb_silkscreen_text",
|
|
133
|
-
pcb_silkscreen_text_id: "text3",
|
|
134
|
-
pcb_component_id: "component1",
|
|
135
|
-
layer: "bottom",
|
|
136
|
-
text: "180",
|
|
137
|
-
anchor_position: { x: 75, y: 120 },
|
|
138
|
-
anchor_alignment: "center",
|
|
139
|
-
font: "tscircuit2024",
|
|
140
|
-
font_size: 6,
|
|
141
|
-
ccw_rotation: 180,
|
|
142
|
-
},
|
|
143
|
-
{
|
|
144
|
-
type: "pcb_silkscreen_text",
|
|
145
|
-
pcb_silkscreen_text_id: "text4",
|
|
146
|
-
pcb_component_id: "component1",
|
|
147
|
-
layer: "bottom",
|
|
148
|
-
text: "270",
|
|
149
|
-
anchor_position: { x: 30, y: 75 },
|
|
150
|
-
anchor_alignment: "center",
|
|
151
|
-
font: "tscircuit2024",
|
|
152
|
-
font_size: 6,
|
|
153
|
-
ccw_rotation: 270,
|
|
154
|
-
},
|
|
155
|
-
{
|
|
156
|
-
type: "pcb_silkscreen_text",
|
|
157
|
-
pcb_silkscreen_text_id: "text5",
|
|
158
|
-
pcb_component_id: "component1",
|
|
159
|
-
layer: "bottom",
|
|
160
|
-
text: "BTM",
|
|
161
|
-
anchor_position: { x: 75, y: 75 },
|
|
162
|
-
anchor_alignment: "center",
|
|
163
|
-
font: "tscircuit2024",
|
|
164
|
-
font_size: 8,
|
|
165
|
-
ccw_rotation: 45,
|
|
166
|
-
},
|
|
167
|
-
]
|
|
168
|
-
|
|
169
|
-
drawer.drawElements(texts)
|
|
170
|
-
|
|
171
|
-
await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
|
|
172
|
-
import.meta.path,
|
|
173
|
-
"silkscreen-text-bottom-rotated",
|
|
174
|
-
)
|
|
175
|
-
})
|
|
176
|
-
|
|
177
|
-
test("draw silkscreen rect", async () => {
|
|
178
|
-
const canvas = createCanvas(100, 100)
|
|
179
|
-
const ctx = canvas.getContext("2d")
|
|
180
|
-
const drawer = new CircuitToCanvasDrawer(ctx)
|
|
181
|
-
|
|
182
|
-
ctx.fillStyle = "#1a1a1a"
|
|
183
|
-
ctx.fillRect(0, 0, 100, 100)
|
|
184
|
-
|
|
185
|
-
const rect: PcbSilkscreenRect = {
|
|
186
|
-
type: "pcb_silkscreen_rect",
|
|
187
|
-
pcb_silkscreen_rect_id: "rect1",
|
|
188
|
-
pcb_component_id: "component1",
|
|
189
|
-
layer: "top",
|
|
190
|
-
center: { x: 50, y: 50 },
|
|
191
|
-
width: 40,
|
|
192
|
-
height: 20,
|
|
193
|
-
stroke_width: 0.2,
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
drawer.drawElements([rect])
|
|
197
|
-
|
|
198
|
-
await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
|
|
199
|
-
import.meta.path,
|
|
200
|
-
"silkscreen-rect",
|
|
201
|
-
)
|
|
202
|
-
})
|
|
203
|
-
|
|
204
|
-
test("draw silkscreen circle", async () => {
|
|
205
|
-
const canvas = createCanvas(100, 100)
|
|
206
|
-
const ctx = canvas.getContext("2d")
|
|
207
|
-
const drawer = new CircuitToCanvasDrawer(ctx)
|
|
208
|
-
|
|
209
|
-
ctx.fillStyle = "#1a1a1a"
|
|
210
|
-
ctx.fillRect(0, 0, 100, 100)
|
|
211
|
-
|
|
212
|
-
const circle: PcbSilkscreenCircle = {
|
|
213
|
-
type: "pcb_silkscreen_circle",
|
|
214
|
-
pcb_silkscreen_circle_id: "circle1",
|
|
215
|
-
pcb_component_id: "component1",
|
|
216
|
-
layer: "top",
|
|
217
|
-
center: { x: 50, y: 50 },
|
|
218
|
-
radius: 20,
|
|
219
|
-
stroke_width: 0.2,
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
drawer.drawElements([circle])
|
|
223
|
-
|
|
224
|
-
await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
|
|
225
|
-
import.meta.path,
|
|
226
|
-
"silkscreen-circle",
|
|
227
|
-
)
|
|
228
|
-
})
|
|
229
|
-
|
|
230
|
-
test("draw silkscreen line", async () => {
|
|
231
|
-
const canvas = createCanvas(100, 100)
|
|
232
|
-
const ctx = canvas.getContext("2d")
|
|
233
|
-
const drawer = new CircuitToCanvasDrawer(ctx)
|
|
234
|
-
|
|
235
|
-
ctx.fillStyle = "#1a1a1a"
|
|
236
|
-
ctx.fillRect(0, 0, 100, 100)
|
|
237
|
-
|
|
238
|
-
const line: PcbSilkscreenLine = {
|
|
239
|
-
type: "pcb_silkscreen_line",
|
|
240
|
-
pcb_silkscreen_line_id: "line1",
|
|
241
|
-
pcb_component_id: "component1",
|
|
242
|
-
layer: "top",
|
|
243
|
-
x1: 20,
|
|
244
|
-
y1: 20,
|
|
245
|
-
x2: 80,
|
|
246
|
-
y2: 80,
|
|
247
|
-
stroke_width: 2,
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
drawer.drawElements([line])
|
|
251
|
-
|
|
252
|
-
await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
|
|
253
|
-
import.meta.path,
|
|
254
|
-
"silkscreen-line",
|
|
255
|
-
)
|
|
256
|
-
})
|
|
257
|
-
|
|
258
|
-
test("draw silkscreen path", async () => {
|
|
259
|
-
const canvas = createCanvas(100, 100)
|
|
260
|
-
const ctx = canvas.getContext("2d")
|
|
261
|
-
const drawer = new CircuitToCanvasDrawer(ctx)
|
|
262
|
-
|
|
263
|
-
ctx.fillStyle = "#1a1a1a"
|
|
264
|
-
ctx.fillRect(0, 0, 100, 100)
|
|
265
|
-
|
|
266
|
-
const path: PcbSilkscreenPath = {
|
|
267
|
-
type: "pcb_silkscreen_path",
|
|
268
|
-
pcb_silkscreen_path_id: "path1",
|
|
269
|
-
pcb_component_id: "component1",
|
|
270
|
-
layer: "top",
|
|
271
|
-
route: [
|
|
272
|
-
{ x: 10, y: 50 },
|
|
273
|
-
{ x: 30, y: 20 },
|
|
274
|
-
{ x: 70, y: 20 },
|
|
275
|
-
{ x: 90, y: 50 },
|
|
276
|
-
{ x: 70, y: 80 },
|
|
277
|
-
{ x: 30, y: 80 },
|
|
278
|
-
{ x: 10, y: 50 },
|
|
279
|
-
],
|
|
280
|
-
stroke_width: 2,
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
drawer.drawElements([path])
|
|
284
|
-
|
|
285
|
-
await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
|
|
286
|
-
import.meta.path,
|
|
287
|
-
"silkscreen-path",
|
|
288
|
-
)
|
|
289
|
-
})
|
|
290
|
-
|
|
291
|
-
test("draw silkscreen on component", async () => {
|
|
292
|
-
const canvas = createCanvas(150, 100)
|
|
293
|
-
const ctx = canvas.getContext("2d")
|
|
294
|
-
const drawer = new CircuitToCanvasDrawer(ctx)
|
|
295
|
-
|
|
296
|
-
ctx.fillStyle = "#1a1a1a"
|
|
297
|
-
ctx.fillRect(0, 0, 150, 100)
|
|
298
|
-
|
|
299
|
-
const elements = [
|
|
300
|
-
// Component outline
|
|
301
|
-
{
|
|
302
|
-
type: "pcb_silkscreen_rect" as const,
|
|
303
|
-
pcb_silkscreen_rect_id: "outline1",
|
|
304
|
-
pcb_component_id: "component1",
|
|
305
|
-
layer: "top" as const,
|
|
306
|
-
center: { x: 75, y: 50 },
|
|
307
|
-
width: 60,
|
|
308
|
-
height: 30,
|
|
309
|
-
stroke_width: 0.2,
|
|
310
|
-
},
|
|
311
|
-
// Pin 1 indicator
|
|
312
|
-
{
|
|
313
|
-
type: "pcb_silkscreen_circle" as const,
|
|
314
|
-
pcb_silkscreen_circle_id: "pin1marker",
|
|
315
|
-
pcb_component_id: "component1",
|
|
316
|
-
layer: "top" as const,
|
|
317
|
-
center: { x: 55, y: 40 },
|
|
318
|
-
radius: 3,
|
|
319
|
-
stroke_width: 0.2,
|
|
320
|
-
},
|
|
321
|
-
// Component label
|
|
322
|
-
{
|
|
323
|
-
type: "pcb_silkscreen_text" as const,
|
|
324
|
-
pcb_silkscreen_text_id: "label1",
|
|
325
|
-
pcb_component_id: "component1",
|
|
326
|
-
layer: "top" as const,
|
|
327
|
-
text: "IC1",
|
|
328
|
-
anchor_position: { x: 75, y: 50 },
|
|
329
|
-
anchor_alignment: "center" as const,
|
|
330
|
-
font: "tscircuit2024" as const,
|
|
331
|
-
font_size: 8,
|
|
332
|
-
},
|
|
333
|
-
// SMT pads
|
|
334
|
-
{
|
|
335
|
-
type: "pcb_smtpad" as const,
|
|
336
|
-
pcb_smtpad_id: "pad1",
|
|
337
|
-
shape: "rect" as const,
|
|
338
|
-
x: 55,
|
|
339
|
-
y: 50,
|
|
340
|
-
width: 10,
|
|
341
|
-
height: 5,
|
|
342
|
-
layer: "top" as const,
|
|
343
|
-
},
|
|
344
|
-
{
|
|
345
|
-
type: "pcb_smtpad" as const,
|
|
346
|
-
pcb_smtpad_id: "pad2",
|
|
347
|
-
shape: "rect" as const,
|
|
348
|
-
x: 95,
|
|
349
|
-
y: 50,
|
|
350
|
-
width: 10,
|
|
351
|
-
height: 5,
|
|
352
|
-
layer: "top" as const,
|
|
353
|
-
},
|
|
354
|
-
]
|
|
355
|
-
|
|
356
|
-
drawer.drawElements(elements)
|
|
357
|
-
|
|
358
|
-
await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
|
|
359
|
-
import.meta.path,
|
|
360
|
-
"silkscreen-on-component",
|
|
361
|
-
)
|
|
362
|
-
})
|
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
import { expect, test } from "bun:test"
|
|
2
|
-
import { createCanvas } from "@napi-rs/canvas"
|
|
3
|
-
import type { PcbSmtPad } from "circuit-json"
|
|
4
|
-
import { CircuitToCanvasDrawer } from "../../lib/drawer"
|
|
5
|
-
|
|
6
|
-
test("draw rectangular smt pad", async () => {
|
|
7
|
-
const canvas = createCanvas(100, 100)
|
|
8
|
-
const ctx = canvas.getContext("2d")
|
|
9
|
-
const drawer = new CircuitToCanvasDrawer(ctx)
|
|
10
|
-
|
|
11
|
-
ctx.fillStyle = "#1a1a1a"
|
|
12
|
-
ctx.fillRect(0, 0, 100, 100)
|
|
13
|
-
|
|
14
|
-
const pad: PcbSmtPad = {
|
|
15
|
-
type: "pcb_smtpad",
|
|
16
|
-
pcb_smtpad_id: "pad1",
|
|
17
|
-
shape: "rect",
|
|
18
|
-
x: 50,
|
|
19
|
-
y: 50,
|
|
20
|
-
width: 40,
|
|
21
|
-
height: 20,
|
|
22
|
-
layer: "top",
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
drawer.drawElements([pad])
|
|
26
|
-
|
|
27
|
-
await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
|
|
28
|
-
import.meta.path,
|
|
29
|
-
)
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
test("draw rectangular smt pad with border radius", async () => {
|
|
33
|
-
const canvas = createCanvas(100, 100)
|
|
34
|
-
const ctx = canvas.getContext("2d")
|
|
35
|
-
const drawer = new CircuitToCanvasDrawer(ctx)
|
|
36
|
-
|
|
37
|
-
ctx.fillStyle = "#1a1a1a"
|
|
38
|
-
ctx.fillRect(0, 0, 100, 100)
|
|
39
|
-
|
|
40
|
-
const pad: PcbSmtPad = {
|
|
41
|
-
type: "pcb_smtpad",
|
|
42
|
-
pcb_smtpad_id: "pad1",
|
|
43
|
-
shape: "rect",
|
|
44
|
-
x: 50,
|
|
45
|
-
y: 50,
|
|
46
|
-
width: 40,
|
|
47
|
-
height: 20,
|
|
48
|
-
layer: "top",
|
|
49
|
-
rect_border_radius: 5,
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
drawer.drawElements([pad])
|
|
53
|
-
|
|
54
|
-
await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
|
|
55
|
-
import.meta.path,
|
|
56
|
-
"rect-pad-with-border-radius",
|
|
57
|
-
)
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
test("draw rotated rectangular smt pad", async () => {
|
|
61
|
-
const canvas = createCanvas(100, 100)
|
|
62
|
-
const ctx = canvas.getContext("2d")
|
|
63
|
-
const drawer = new CircuitToCanvasDrawer(ctx)
|
|
64
|
-
|
|
65
|
-
ctx.fillStyle = "#1a1a1a"
|
|
66
|
-
ctx.fillRect(0, 0, 100, 100)
|
|
67
|
-
|
|
68
|
-
const pad: PcbSmtPad = {
|
|
69
|
-
type: "pcb_smtpad",
|
|
70
|
-
pcb_smtpad_id: "pad1",
|
|
71
|
-
shape: "rotated_rect",
|
|
72
|
-
x: 50,
|
|
73
|
-
y: 50,
|
|
74
|
-
width: 40,
|
|
75
|
-
height: 20,
|
|
76
|
-
layer: "top",
|
|
77
|
-
ccw_rotation: 45,
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
drawer.drawElements([pad])
|
|
81
|
-
|
|
82
|
-
await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
|
|
83
|
-
import.meta.path,
|
|
84
|
-
"rotated-rect-pad",
|
|
85
|
-
)
|
|
86
|
-
})
|
|
87
|
-
|
|
88
|
-
test("draw circular smt pad", async () => {
|
|
89
|
-
const canvas = createCanvas(100, 100)
|
|
90
|
-
const ctx = canvas.getContext("2d")
|
|
91
|
-
const drawer = new CircuitToCanvasDrawer(ctx)
|
|
92
|
-
|
|
93
|
-
ctx.fillStyle = "#1a1a1a"
|
|
94
|
-
ctx.fillRect(0, 0, 100, 100)
|
|
95
|
-
|
|
96
|
-
const pad: PcbSmtPad = {
|
|
97
|
-
type: "pcb_smtpad",
|
|
98
|
-
pcb_smtpad_id: "pad1",
|
|
99
|
-
shape: "circle",
|
|
100
|
-
x: 50,
|
|
101
|
-
y: 50,
|
|
102
|
-
radius: 20,
|
|
103
|
-
layer: "top",
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
drawer.drawElements([pad])
|
|
107
|
-
|
|
108
|
-
await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
|
|
109
|
-
import.meta.path,
|
|
110
|
-
"circular-pad",
|
|
111
|
-
)
|
|
112
|
-
})
|
|
113
|
-
|
|
114
|
-
test("draw pill smt pad", async () => {
|
|
115
|
-
const canvas = createCanvas(100, 100)
|
|
116
|
-
const ctx = canvas.getContext("2d")
|
|
117
|
-
const drawer = new CircuitToCanvasDrawer(ctx)
|
|
118
|
-
|
|
119
|
-
ctx.fillStyle = "#1a1a1a"
|
|
120
|
-
ctx.fillRect(0, 0, 100, 100)
|
|
121
|
-
|
|
122
|
-
const pad: PcbSmtPad = {
|
|
123
|
-
type: "pcb_smtpad",
|
|
124
|
-
pcb_smtpad_id: "pad1",
|
|
125
|
-
shape: "pill",
|
|
126
|
-
x: 50,
|
|
127
|
-
y: 50,
|
|
128
|
-
width: 50,
|
|
129
|
-
height: 25,
|
|
130
|
-
radius: 12.5,
|
|
131
|
-
layer: "top",
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
drawer.drawElements([pad])
|
|
135
|
-
|
|
136
|
-
await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
|
|
137
|
-
import.meta.path,
|
|
138
|
-
"pill-pad",
|
|
139
|
-
)
|
|
140
|
-
})
|
|
141
|
-
|
|
142
|
-
test("draw polygon smt pad", async () => {
|
|
143
|
-
const canvas = createCanvas(100, 100)
|
|
144
|
-
const ctx = canvas.getContext("2d")
|
|
145
|
-
const drawer = new CircuitToCanvasDrawer(ctx)
|
|
146
|
-
|
|
147
|
-
ctx.fillStyle = "#1a1a1a"
|
|
148
|
-
ctx.fillRect(0, 0, 100, 100)
|
|
149
|
-
|
|
150
|
-
const pad: PcbSmtPad = {
|
|
151
|
-
type: "pcb_smtpad",
|
|
152
|
-
pcb_smtpad_id: "pad1",
|
|
153
|
-
shape: "polygon",
|
|
154
|
-
layer: "top",
|
|
155
|
-
points: [
|
|
156
|
-
{ x: 30, y: 30 },
|
|
157
|
-
{ x: 70, y: 30 },
|
|
158
|
-
{ x: 80, y: 50 },
|
|
159
|
-
{ x: 70, y: 70 },
|
|
160
|
-
{ x: 30, y: 70 },
|
|
161
|
-
{ x: 20, y: 50 },
|
|
162
|
-
],
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
drawer.drawElements([pad])
|
|
166
|
-
|
|
167
|
-
await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
|
|
168
|
-
import.meta.path,
|
|
169
|
-
"polygon-pad",
|
|
170
|
-
)
|
|
171
|
-
})
|
|
172
|
-
|
|
173
|
-
test("draw bottom layer smt pad", async () => {
|
|
174
|
-
const canvas = createCanvas(100, 100)
|
|
175
|
-
const ctx = canvas.getContext("2d")
|
|
176
|
-
const drawer = new CircuitToCanvasDrawer(ctx)
|
|
177
|
-
|
|
178
|
-
ctx.fillStyle = "#1a1a1a"
|
|
179
|
-
ctx.fillRect(0, 0, 100, 100)
|
|
180
|
-
|
|
181
|
-
const pad: PcbSmtPad = {
|
|
182
|
-
type: "pcb_smtpad",
|
|
183
|
-
pcb_smtpad_id: "pad1",
|
|
184
|
-
shape: "rect",
|
|
185
|
-
x: 50,
|
|
186
|
-
y: 50,
|
|
187
|
-
width: 40,
|
|
188
|
-
height: 20,
|
|
189
|
-
layer: "bottom",
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
drawer.drawElements([pad])
|
|
193
|
-
|
|
194
|
-
await expect(canvas.toBuffer("image/png")).toMatchPngSnapshot(
|
|
195
|
-
import.meta.path,
|
|
196
|
-
"bottom-layer-pad",
|
|
197
|
-
)
|
|
198
|
-
})
|
/package/tests/elements/__snapshots__/{silkscreen-circle.snap.png → pcb-silkscreen-circle.snap.png}
RENAMED
|
File without changes
|
/package/tests/elements/__snapshots__/{silkscreen-line.snap.png → pcb-silkscreen-line.snap.png}
RENAMED
|
File without changes
|
|
File without changes
|
/package/tests/elements/__snapshots__/{silkscreen-path.snap.png → pcb-silkscreen-path.snap.png}
RENAMED
|
File without changes
|
/package/tests/elements/__snapshots__/{silkscreen-rect.snap.png → pcb-silkscreen-rect.snap.png}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/tests/elements/__snapshots__/{pcb-silkscreen.snap.png → pcb-silkscreen-text.snap.png}
RENAMED
|
File without changes
|
/package/tests/elements/__snapshots__/{bottom-layer-pad.snap.png → pcb-smtpad-bottom-layer.snap.png}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/tests/elements/__snapshots__/{rotated-rect-pad.snap.png → pcb-smtpad-rotated-rect.snap.png}
RENAMED
|
File without changes
|