@tscircuit/copper-pour-solver 0.0.1
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/.github/workflows/.replit +9 -0
- package/.github/workflows/bun-formatcheck.yml +26 -0
- package/.github/workflows/bun-pver-release.yml +71 -0
- package/.github/workflows/bun-test.yml +31 -0
- package/.github/workflows/bun-typecheck.yml +26 -0
- package/README.md +37 -0
- package/biome.json +93 -0
- package/bun.lock +164 -0
- package/bunfig.toml +5 -0
- package/cosmos.config.json +5 -0
- package/dist/index.d.ts +57 -0
- package/dist/index.js +368 -0
- package/lib/circuit-json/convert-circuit-json-to-input-problem.ts +208 -0
- package/lib/circuit-json/convertCircuitJsonToInputProblem.ts +0 -0
- package/lib/index.ts +3 -0
- package/lib/solvers/CopperPourPipelineSolver.ts +51 -0
- package/lib/solvers/copper-pour/circle-to-polygon.ts +15 -0
- package/lib/solvers/copper-pour/generate-brep.ts +60 -0
- package/lib/solvers/copper-pour/get-board-polygon.ts +19 -0
- package/lib/solvers/copper-pour/process-obstacles.ts +116 -0
- package/lib/types.ts +46 -0
- package/package.json +28 -0
- package/site/Welcome.page.tsx +0 -0
- package/tests/__snapshots__/circuit-1.snap.svg +1 -0
- package/tests/__snapshots__/circuit-2.snap.svg +1 -0
- package/tests/__snapshots__/circuit-3.snap.svg +1 -0
- package/tests/__snapshots__/circuit-4.snap.svg +1 -0
- package/tests/__snapshots__/circuit-5.snap.svg +1 -0
- package/tests/__snapshots__/circuit-6.snap.svg +1 -0
- package/tests/assets/circuit-1.json +592 -0
- package/tests/assets/circuit-2.json +1424 -0
- package/tests/assets/circuit-3.json +1424 -0
- package/tests/assets/circuit-4.json +631 -0
- package/tests/assets/circuit-5.json +631 -0
- package/tests/assets/circuit-6.json +806 -0
- package/tests/circuit-1.test.ts +14 -0
- package/tests/circuit-2.test.ts +15 -0
- package/tests/circuit-3.test.ts +15 -0
- package/tests/circuit-4.test.ts +15 -0
- package/tests/circuit-5.test.ts +15 -0
- package/tests/circuit-6.test.ts +15 -0
- package/tests/fixtures/preload.ts +1 -0
- package/tests/utils/run-solver-and-render-to-svg.ts +64 -0
- package/tsconfig.json +34 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
|
+
import circuitJson from "./assets/circuit-1.json"
|
|
3
|
+
import { runSolverAndRenderToSvg } from "./utils/run-solver-and-render-to-svg"
|
|
4
|
+
|
|
5
|
+
test("circuit-1", async () => {
|
|
6
|
+
const svg = runSolverAndRenderToSvg(circuitJson as any, {
|
|
7
|
+
layer: "top",
|
|
8
|
+
net_name: "GND",
|
|
9
|
+
pad_margin: 0.4,
|
|
10
|
+
trace_margin: 0.2,
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
await expect(svg).toMatchSvgSnapshot(import.meta.path, "circuit-1")
|
|
14
|
+
})
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
|
+
import circuitJson from "./assets/circuit-2.json"
|
|
3
|
+
import { runSolverAndRenderToSvg } from "./utils/run-solver-and-render-to-svg"
|
|
4
|
+
import type { AnyCircuitElement } from "circuit-json"
|
|
5
|
+
|
|
6
|
+
test("circuit 2", async () => {
|
|
7
|
+
const svg = runSolverAndRenderToSvg(circuitJson as AnyCircuitElement[], {
|
|
8
|
+
layer: "top",
|
|
9
|
+
net_name: "VCC",
|
|
10
|
+
pad_margin: 0.2,
|
|
11
|
+
trace_margin: 0.4,
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
await expect(svg).toMatchSvgSnapshot(import.meta.path, "circuit-2")
|
|
15
|
+
})
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
|
+
import circuitJson from "./assets/circuit-3.json"
|
|
3
|
+
import { runSolverAndRenderToSvg } from "./utils/run-solver-and-render-to-svg"
|
|
4
|
+
import type { AnyCircuitElement } from "circuit-json"
|
|
5
|
+
|
|
6
|
+
test("circuit 3", async () => {
|
|
7
|
+
const svg = runSolverAndRenderToSvg(circuitJson as AnyCircuitElement[], {
|
|
8
|
+
layer: "top",
|
|
9
|
+
net_name: "VCC",
|
|
10
|
+
pad_margin: 0.2,
|
|
11
|
+
trace_margin: 0.1,
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
await expect(svg).toMatchSvgSnapshot(import.meta.path, "circuit-3")
|
|
15
|
+
})
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
|
+
import circuitJson from "./assets/circuit-4.json"
|
|
3
|
+
import { runSolverAndRenderToSvg } from "./utils/run-solver-and-render-to-svg"
|
|
4
|
+
import type { AnyCircuitElement } from "circuit-json"
|
|
5
|
+
|
|
6
|
+
test("circuit 4", 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(import.meta.path, "circuit-4")
|
|
15
|
+
})
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
|
+
import circuitJson from "./assets/circuit-5.json"
|
|
3
|
+
import { runSolverAndRenderToSvg } from "./utils/run-solver-and-render-to-svg"
|
|
4
|
+
import type { AnyCircuitElement } from "circuit-json"
|
|
5
|
+
|
|
6
|
+
test("circuit 5", async () => {
|
|
7
|
+
const svg = runSolverAndRenderToSvg(circuitJson as AnyCircuitElement[], {
|
|
8
|
+
layer: "bottom",
|
|
9
|
+
net_name: "VCC",
|
|
10
|
+
pad_margin: 0.4,
|
|
11
|
+
trace_margin: 0.2,
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
await expect(svg).toMatchSvgSnapshot(import.meta.path, "circuit-5")
|
|
15
|
+
})
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
|
+
import circuitJson from "./assets/circuit-6.json"
|
|
3
|
+
import { runSolverAndRenderToSvg } from "./utils/run-solver-and-render-to-svg"
|
|
4
|
+
import type { AnyCircuitElement } from "circuit-json"
|
|
5
|
+
|
|
6
|
+
test("circuit 6", 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(import.meta.path, "circuit-6")
|
|
15
|
+
})
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "bun-match-svg"
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CopperPourPipelineSolver,
|
|
3
|
+
convertCircuitJsonToInputProblem,
|
|
4
|
+
} from "lib/index"
|
|
5
|
+
import type {
|
|
6
|
+
AnyCircuitElement,
|
|
7
|
+
LayerRef,
|
|
8
|
+
PcbCopperPourBRep,
|
|
9
|
+
SourceNet,
|
|
10
|
+
} from "circuit-json"
|
|
11
|
+
import { convertCircuitJsonToPcbSvg } from "circuit-to-svg"
|
|
12
|
+
|
|
13
|
+
export const runSolverAndRenderToSvg = (
|
|
14
|
+
circuitJson: AnyCircuitElement[],
|
|
15
|
+
pour_options: {
|
|
16
|
+
layer: LayerRef
|
|
17
|
+
net_name: string
|
|
18
|
+
pad_margin: number
|
|
19
|
+
trace_margin: number
|
|
20
|
+
},
|
|
21
|
+
) => {
|
|
22
|
+
const source_net = circuitJson.find(
|
|
23
|
+
(elm): elm is SourceNet =>
|
|
24
|
+
elm.type === "source_net" && elm.name === pour_options.net_name,
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
if (!source_net) {
|
|
28
|
+
throw new Error(`Net with name "${pour_options.net_name}" not found`)
|
|
29
|
+
}
|
|
30
|
+
if (!source_net.subcircuit_connectivity_map_key) {
|
|
31
|
+
throw new Error(`Net "${pour_options.net_name}" has no connectivity key`)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const pour_connectivity_key = source_net.subcircuit_connectivity_map_key
|
|
35
|
+
|
|
36
|
+
const inputProblem = convertCircuitJsonToInputProblem(circuitJson, {
|
|
37
|
+
...pour_options,
|
|
38
|
+
pour_connectivity_key,
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
const solver = new CopperPourPipelineSolver(inputProblem)
|
|
42
|
+
const output = solver.getOutput()
|
|
43
|
+
|
|
44
|
+
const pcb_copper_pours: PcbCopperPourBRep[] = output.brep_shapes.map(
|
|
45
|
+
(brep_shape, i) =>
|
|
46
|
+
({
|
|
47
|
+
type: "pcb_copper_pour",
|
|
48
|
+
shape: "brep",
|
|
49
|
+
pcb_copper_pour_id: `pcb_copper_pour_${i}`,
|
|
50
|
+
layer: pour_options.layer,
|
|
51
|
+
source_net_id: source_net.source_net_id,
|
|
52
|
+
brep_shape: {
|
|
53
|
+
outer_ring: brep_shape.outer_ring,
|
|
54
|
+
inner_rings: brep_shape.inner_rings,
|
|
55
|
+
},
|
|
56
|
+
covered_with_solder_mask: true,
|
|
57
|
+
}) as PcbCopperPourBRep,
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
const finalCircuitJson = [...circuitJson, ...pcb_copper_pours]
|
|
61
|
+
|
|
62
|
+
const svg = convertCircuitJsonToPcbSvg(finalCircuitJson as any)
|
|
63
|
+
return svg
|
|
64
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
// Environment setup & latest features
|
|
4
|
+
"lib": ["ESNext"],
|
|
5
|
+
"target": "ESNext",
|
|
6
|
+
"module": "Preserve",
|
|
7
|
+
"moduleDetection": "force",
|
|
8
|
+
"jsx": "react-jsx",
|
|
9
|
+
"allowJs": true,
|
|
10
|
+
|
|
11
|
+
// Bundler mode
|
|
12
|
+
"moduleResolution": "bundler",
|
|
13
|
+
"allowImportingTsExtensions": true,
|
|
14
|
+
"verbatimModuleSyntax": true,
|
|
15
|
+
"noEmit": true,
|
|
16
|
+
"resolveJsonModule": true,
|
|
17
|
+
|
|
18
|
+
// Best practices
|
|
19
|
+
"strict": true,
|
|
20
|
+
"skipLibCheck": true,
|
|
21
|
+
"noFallthroughCasesInSwitch": true,
|
|
22
|
+
"noUncheckedIndexedAccess": true,
|
|
23
|
+
"noImplicitOverride": true,
|
|
24
|
+
|
|
25
|
+
// Some stricter flags (disabled by default)
|
|
26
|
+
"noUnusedLocals": false,
|
|
27
|
+
"noUnusedParameters": false,
|
|
28
|
+
"noPropertyAccessFromIndexSignature": false,
|
|
29
|
+
"baseUrl": ".",
|
|
30
|
+
"paths": {
|
|
31
|
+
"lib": ["./lib"]
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|