@tscircuit/copper-pour-solver 0.0.32 → 0.0.34

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.
@@ -0,0 +1,124 @@
1
+ import { expect, test } from "bun:test"
2
+ import type { AnyCircuitElement, PcbCopperPourBRep } from "circuit-json"
3
+ import { convertCircuitJsonToPcbSvg } from "circuit-to-svg"
4
+ import {
5
+ CopperPourPipelineSolver,
6
+ convertCircuitJsonToInputProblem,
7
+ } from "lib/index"
8
+ import type { InputProblem } from "lib/types"
9
+
10
+ const ch340cPadPositions = [
11
+ { pin: 1, x: -4.445, y: -2.872486 },
12
+ { pin: 2, x: -3.175, y: -2.872486 },
13
+ { pin: 3, x: -1.905, y: -2.872486 },
14
+ { pin: 4, x: -0.635, y: -2.872486 },
15
+ { pin: 5, x: 0.635, y: -2.872486 },
16
+ { pin: 6, x: 1.905, y: -2.872486 },
17
+ { pin: 7, x: 3.175, y: -2.872486 },
18
+ { pin: 8, x: 4.445, y: -2.872486 },
19
+ { pin: 16, x: -4.445, y: 2.872486 },
20
+ { pin: 15, x: -3.175, y: 2.872486 },
21
+ { pin: 14, x: -1.905, y: 2.872486 },
22
+ { pin: 13, x: -0.635, y: 2.872486 },
23
+ { pin: 12, x: 0.635, y: 2.872486 },
24
+ { pin: 11, x: 1.905, y: 2.872486 },
25
+ { pin: 10, x: 3.175, y: 2.872486 },
26
+ { pin: 9, x: 4.445, y: 2.872486 },
27
+ ]
28
+
29
+ const circuitJson: AnyCircuitElement[] = [
30
+ {
31
+ type: "pcb_board",
32
+ pcb_board_id: "pcb_board_0",
33
+ center: { x: 0, y: 0 },
34
+ width: 14,
35
+ height: 10,
36
+ thickness: 1.4,
37
+ num_layers: 2,
38
+ material: "fr4",
39
+ },
40
+ ...ch340cPadPositions.map(({ pin, x, y }) => ({
41
+ type: "pcb_smtpad" as const,
42
+ pcb_smtpad_id: `pcb_smtpad_ch340c_${pin}`,
43
+ pcb_component_id: "pcb_component_ch340c",
44
+ layer: "top" as const,
45
+ shape: "pill" as const,
46
+ x,
47
+ y,
48
+ width: 0.5599938,
49
+ height: 1.7450054,
50
+ radius: 0.2799969,
51
+ port_hints: [`pin${pin}`],
52
+ is_covered_with_solder_mask: false,
53
+ })),
54
+ {
55
+ type: "pcb_smtpad",
56
+ pcb_smtpad_id: "pcb_smtpad_rotated_pill",
57
+ pcb_component_id: "pcb_component_rotated_pill",
58
+ layer: "top",
59
+ shape: "rotated_pill",
60
+ x: 0,
61
+ y: 0,
62
+ width: 0.5599938,
63
+ height: 1.7450054,
64
+ radius: 0.2799969,
65
+ ccw_rotation: 90,
66
+ port_hints: ["rotated_pill"],
67
+ is_covered_with_solder_mask: false,
68
+ },
69
+ ] as AnyCircuitElement[]
70
+
71
+ const getInputProblem = () =>
72
+ convertCircuitJsonToInputProblem(circuitJson, {
73
+ layer: "top",
74
+ subcircuit_connectivity_map_key: "net:GND",
75
+ pad_margin: 0.15,
76
+ trace_margin: 0.15,
77
+ })
78
+
79
+ const renderSolvedPour = (inputProblem: InputProblem) => {
80
+ const solver = new CopperPourPipelineSolver(inputProblem)
81
+ const output = solver.getOutput()
82
+ const pcbCopperPours = output.brep_shapes.map(
83
+ (brep_shape, index) =>
84
+ ({
85
+ type: "pcb_copper_pour",
86
+ shape: "brep",
87
+ pcb_copper_pour_id: `pcb_copper_pour_${index}`,
88
+ layer: "top",
89
+ source_net_id: "source_net_gnd",
90
+ brep_shape,
91
+ covered_with_solder_mask: true,
92
+ }) as PcbCopperPourBRep,
93
+ )
94
+
95
+ return convertCircuitJsonToPcbSvg([...circuitJson, ...pcbCopperPours] as any)
96
+ }
97
+
98
+ test("pill and rotated pill pads clear copper pour", () => {
99
+ const inputProblem = getInputProblem()
100
+
101
+ const pillPads = inputProblem.pads.filter((pad) => pad.shape === "pill")
102
+
103
+ expect(pillPads).toHaveLength(17)
104
+ expect(
105
+ pillPads.some(
106
+ (pad) =>
107
+ pad.padId === "pcb_smtpad_rotated_pill" && pad.ccwRotation === 90,
108
+ ),
109
+ ).toBe(true)
110
+
111
+ const solver = new CopperPourPipelineSolver(inputProblem)
112
+ const output = solver.getOutput()
113
+
114
+ expect(output.brep_shapes).toHaveLength(1)
115
+ expect(output.brep_shapes[0]!.inner_rings).toHaveLength(17)
116
+ })
117
+
118
+ test("pill and rotated pill copper pour svg snapshot", async () => {
119
+ const inputProblem = getInputProblem()
120
+
121
+ const svg = renderSolvedPour(inputProblem)
122
+
123
+ await expect(svg).toMatchSvgSnapshot(import.meta.path, "pill-pad-copper-pour")
124
+ })