@tscircuit/copper-pour-solver 0.0.19 → 0.0.21
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 +2 -1
- package/dist/index.js +51 -18
- package/lib/circuit-json/convert-circuit-json-to-input-problem.ts +55 -17
- package/lib/solvers/copper-pour/process-obstacles.ts +0 -1
- package/package.json +1 -1
- package/tests/__snapshots__/multiple-pours.snap.svg +1 -0
- package/tests/assets/multiple-pours.json +657 -0
- package/tests/multiple-pours.test.ts +42 -0
- package/tests/repro02-pinrow4-copper-pour/__snapshots__/repro02-pinrow4-copper-pour.snap.svg +1 -0
- package/tests/repro02-pinrow4-copper-pour/repro02-pinrow4-copper-pour.json +2344 -0
- package/tests/repro02-pinrow4-copper-pour/repro02-pinrow4-copper-pour.test.ts +18 -0
- package/tests/utils/run-solver-and-render-to-svg.ts +60 -48
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
|
+
import type { AnyCircuitElement } from "circuit-json"
|
|
3
|
+
import circuitJson from "./repro02-pinrow4-copper-pour.json"
|
|
4
|
+
import { runSolverAndRenderToSvg } from "../utils/run-solver-and-render-to-svg"
|
|
5
|
+
|
|
6
|
+
test("repro02-pinrow4-copper-pour", async () => {
|
|
7
|
+
const svg = runSolverAndRenderToSvg(circuitJson as AnyCircuitElement[], {
|
|
8
|
+
layer: "top",
|
|
9
|
+
net_name: "GND",
|
|
10
|
+
pad_margin: 0.2,
|
|
11
|
+
trace_margin: 0.2,
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
await expect(svg).toMatchSvgSnapshot(
|
|
15
|
+
import.meta.path,
|
|
16
|
+
"repro02-pinrow4-copper-pour",
|
|
17
|
+
)
|
|
18
|
+
})
|
|
@@ -10,67 +10,79 @@ import type {
|
|
|
10
10
|
} from "circuit-json"
|
|
11
11
|
import { getFullConnectivityMapFromCircuitJson } from "circuit-json-to-connectivity-map"
|
|
12
12
|
import { convertCircuitJsonToPcbSvg } from "circuit-to-svg"
|
|
13
|
+
import type { Point } from "@tscircuit/math-utils"
|
|
14
|
+
|
|
15
|
+
interface PourOptions {
|
|
16
|
+
layer: LayerRef
|
|
17
|
+
net_name: string
|
|
18
|
+
pad_margin: number
|
|
19
|
+
trace_margin: number
|
|
20
|
+
board_edge_margin?: number
|
|
21
|
+
cutout_margin?: number
|
|
22
|
+
outline?: Point[]
|
|
23
|
+
}
|
|
13
24
|
|
|
14
25
|
export const runSolverAndRenderToSvg = (
|
|
15
26
|
circuitJson: AnyCircuitElement[],
|
|
16
|
-
pour_options:
|
|
17
|
-
layer: LayerRef
|
|
18
|
-
net_name: string
|
|
19
|
-
pad_margin: number
|
|
20
|
-
trace_margin: number
|
|
21
|
-
board_edge_margin?: number
|
|
22
|
-
cutout_margin?: number
|
|
23
|
-
},
|
|
27
|
+
pour_options: PourOptions | PourOptions[],
|
|
24
28
|
) => {
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
)
|
|
29
|
-
|
|
30
|
-
if (!source_net) {
|
|
31
|
-
throw new Error(`Net with name "${pour_options.net_name}" not found`)
|
|
32
|
-
}
|
|
29
|
+
const pourOptionsArray = Array.isArray(pour_options)
|
|
30
|
+
? pour_options
|
|
31
|
+
: [pour_options]
|
|
33
32
|
|
|
34
33
|
const connectivityMap = getFullConnectivityMapFromCircuitJson(circuitJson)
|
|
35
|
-
|
|
36
|
-
source_net.source_net_id,
|
|
37
|
-
)
|
|
34
|
+
const allCopperPours: PcbCopperPourBRep[] = []
|
|
38
35
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
36
|
+
for (const options of pourOptionsArray) {
|
|
37
|
+
const source_net = circuitJson.find(
|
|
38
|
+
(elm): elm is SourceNet =>
|
|
39
|
+
elm.type === "source_net" && elm.name === options.net_name,
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
if (!source_net) {
|
|
43
|
+
throw new Error(`Net with name "${options.net_name}" not found`)
|
|
44
|
+
}
|
|
42
45
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
`Net "${pour_options.net_name}" has no connectivity mapping`,
|
|
46
|
+
let pour_connectivity_key = connectivityMap.getNetConnectedToId(
|
|
47
|
+
source_net.source_net_id,
|
|
46
48
|
)
|
|
47
|
-
}
|
|
48
49
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
if (!pour_connectivity_key && source_net.subcircuit_connectivity_map_key) {
|
|
51
|
+
pour_connectivity_key = source_net.subcircuit_connectivity_map_key
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (!pour_connectivity_key) {
|
|
55
|
+
throw new Error(`Net "${options.net_name}" has no connectivity mapping`)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const inputProblem = convertCircuitJsonToInputProblem(circuitJson, {
|
|
59
|
+
...options,
|
|
60
|
+
pour_connectivity_key,
|
|
61
|
+
})
|
|
53
62
|
|
|
54
|
-
|
|
55
|
-
|
|
63
|
+
const solver = new CopperPourPipelineSolver(inputProblem)
|
|
64
|
+
const output = solver.getOutput()
|
|
56
65
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
66
|
+
const pcb_copper_pours: PcbCopperPourBRep[] = output.brep_shapes.map(
|
|
67
|
+
(brep_shape, i) =>
|
|
68
|
+
({
|
|
69
|
+
type: "pcb_copper_pour",
|
|
70
|
+
shape: "brep",
|
|
71
|
+
pcb_copper_pour_id: `pcb_copper_pour_${allCopperPours.length + i}`,
|
|
72
|
+
layer: options.layer,
|
|
73
|
+
source_net_id: source_net.source_net_id,
|
|
74
|
+
brep_shape: {
|
|
75
|
+
outer_ring: brep_shape.outer_ring,
|
|
76
|
+
inner_rings: brep_shape.inner_rings,
|
|
77
|
+
},
|
|
78
|
+
covered_with_solder_mask: true,
|
|
79
|
+
}) as PcbCopperPourBRep,
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
allCopperPours.push(...pcb_copper_pours)
|
|
83
|
+
}
|
|
72
84
|
|
|
73
|
-
const finalCircuitJson = [...circuitJson, ...
|
|
85
|
+
const finalCircuitJson = [...circuitJson, ...allCopperPours]
|
|
74
86
|
|
|
75
87
|
const svg = convertCircuitJsonToPcbSvg(finalCircuitJson as any)
|
|
76
88
|
return svg
|