circuit-json-to-lbrn 0.0.43 → 0.0.45
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.js +85 -19
- package/lib/ConvertContext.ts +10 -0
- package/lib/createCopperCutFillForLayer.ts +12 -17
- package/lib/element-handlers/addPcbTrace/index.ts +35 -13
- package/lib/getManifold.ts +31 -0
- package/lib/index.ts +30 -0
- package/package.json +1 -1
- package/tests/examples/example05/__snapshots__/example05.snap.svg +1 -0
- package/tests/examples/example05/example05.circuit.json +9562 -0
- package/tests/examples/example05/example05.test.ts +71 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { test, expect } from "bun:test"
|
|
2
|
+
import circuitJson from "./example05.circuit.json" with { type: "json" }
|
|
3
|
+
import { convertCircuitJsonToPcbSvg } from "circuit-to-svg"
|
|
4
|
+
import { generateLightBurnSvg, ShapePath, ShapeGroup } from "lbrnts"
|
|
5
|
+
import { convertCircuitJsonToLbrn } from "lib/index"
|
|
6
|
+
import { stackSvgsVertically } from "stack-svgs"
|
|
7
|
+
import type { CircuitJson } from "circuit-json"
|
|
8
|
+
|
|
9
|
+
test("example05 - copper fill conversion", async () => {
|
|
10
|
+
const pcbSvg = await convertCircuitJsonToPcbSvg(circuitJson as CircuitJson)
|
|
11
|
+
|
|
12
|
+
const project = await convertCircuitJsonToLbrn(circuitJson as CircuitJson, {
|
|
13
|
+
includeLayers: ["top"],
|
|
14
|
+
copperCutFillMargin: 0.5,
|
|
15
|
+
includeCopperCutFill: true,
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
Bun.write("tmp/example05.lbrn2", project.getString(), {
|
|
19
|
+
createPath: true,
|
|
20
|
+
})
|
|
21
|
+
console.log("tmp/example05.lbrn2")
|
|
22
|
+
|
|
23
|
+
// Board dimensions: centered at (0,0), width 18, height 23.38
|
|
24
|
+
// With margin adjustment for origin, we need to check the actual bounds
|
|
25
|
+
// The origin adjustment shifts coordinates to be positive
|
|
26
|
+
const boardWidth = 18
|
|
27
|
+
const boardHeight = 23.380000000000003
|
|
28
|
+
|
|
29
|
+
// Get the copper cut fill shapes (cut index 4) and verify they're within board bounds
|
|
30
|
+
// Find the copper cut fill cut setting index
|
|
31
|
+
const copperCutFillCutIndex = 4 // "Top Copper Cut Fill" cut setting
|
|
32
|
+
|
|
33
|
+
// Collect all vertices from copper cut fill shapes
|
|
34
|
+
const collectShapeVertices = (
|
|
35
|
+
shapes: Array<ShapePath | ShapeGroup>,
|
|
36
|
+
): Array<[number, number]> => {
|
|
37
|
+
const vertices: Array<[number, number]> = []
|
|
38
|
+
for (const shape of shapes) {
|
|
39
|
+
if (shape instanceof ShapePath && shape.cutIndex === copperCutFillCutIndex) {
|
|
40
|
+
for (let i = 0; i < shape.verts.length; i += 2) {
|
|
41
|
+
vertices.push([shape.verts[i]!, shape.verts[i + 1]!])
|
|
42
|
+
}
|
|
43
|
+
} else if (shape instanceof ShapeGroup) {
|
|
44
|
+
vertices.push(...collectShapeVertices(shape.children))
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return vertices
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const copperFillVertices = collectShapeVertices(project.children as any)
|
|
51
|
+
|
|
52
|
+
// All copper cut fill vertices should be within board bounds
|
|
53
|
+
// The origin shifts coordinates so they start at (0, 0)
|
|
54
|
+
// Allow small tolerance for floating point
|
|
55
|
+
const tolerance = 0.001
|
|
56
|
+
for (const [x, y] of copperFillVertices) {
|
|
57
|
+
expect(x).toBeGreaterThanOrEqual(-tolerance)
|
|
58
|
+
expect(x).toBeLessThanOrEqual(boardWidth + tolerance)
|
|
59
|
+
expect(y).toBeGreaterThanOrEqual(-tolerance)
|
|
60
|
+
expect(y).toBeLessThanOrEqual(boardHeight + tolerance)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const lbrnSvg = await generateLightBurnSvg(project, {
|
|
64
|
+
margin: 0,
|
|
65
|
+
width: 600,
|
|
66
|
+
height: 400,
|
|
67
|
+
defaultStrokeWidth: 0.03,
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
expect(lbrnSvg).toMatchSvgSnapshot(import.meta.filename)
|
|
71
|
+
})
|