circuit-json-to-lbrn 0.0.44 → 0.0.46

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.
@@ -1,14 +1,15 @@
1
1
  import { test, expect } from "bun:test"
2
2
  import circuitJson from "./example05.circuit.json" with { type: "json" }
3
- import { convertCircuitJsonToPcbSvg } from "circuit-to-svg"
4
3
  import { generateLightBurnSvg } from "lbrnts"
5
4
  import { convertCircuitJsonToLbrn } from "lib/index"
6
- import { stackSvgsVertically } from "stack-svgs"
5
+ import {
6
+ calculateCircuitBounds,
7
+ calculateOriginFromBounds,
8
+ } from "lib/calculateBounds"
9
+ import { cju } from "@tscircuit/circuit-json-util"
7
10
  import type { CircuitJson } from "circuit-json"
8
11
 
9
12
  test("example05 - copper fill conversion", async () => {
10
- const pcbSvg = await convertCircuitJsonToPcbSvg(circuitJson as CircuitJson)
11
-
12
13
  const project = await convertCircuitJsonToLbrn(circuitJson as CircuitJson, {
13
14
  includeLayers: ["top"],
14
15
  copperCutFillMargin: 0.5,
@@ -20,7 +21,58 @@ test("example05 - copper fill conversion", async () => {
20
21
  })
21
22
  console.log("tmp/example05.lbrn2")
22
23
 
23
- const lbrnSvg = await generateLightBurnSvg(project, {
24
+ // Calculate actual board bounds with origin transformation (same as index.ts)
25
+ const db = cju(circuitJson as CircuitJson)
26
+ const board = db.pcb_board.list()[0]
27
+ const bounds = calculateCircuitBounds(circuitJson as CircuitJson)
28
+ const origin = calculateOriginFromBounds(bounds, undefined)
29
+
30
+ let boardMinX = 0,
31
+ boardMinY = 0,
32
+ boardMaxX = 0,
33
+ boardMaxY = 0
34
+ if (board && board.width && board.height && board.center) {
35
+ const halfWidth = board.width / 2
36
+ const halfHeight = board.height / 2
37
+ boardMinX = board.center.x - halfWidth + origin.x
38
+ boardMinY = board.center.y - halfHeight + origin.y
39
+ boardMaxX = board.center.x + halfWidth + origin.x
40
+ boardMaxY = board.center.y + halfHeight + origin.y
41
+ }
42
+
43
+ // Get the copper cut fill shapes (cut index 4) and verify they're within board bounds
44
+ const copperCutFillCutIndex = 4 // "Top Copper Cut Fill" cut setting
45
+
46
+ // Collect all vertices from copper cut fill shapes
47
+ const collectShapeVertices = (
48
+ shapes: any[],
49
+ ): Array<{ x: number; y: number }> => {
50
+ const vertices: Array<{ x: number; y: number }> = []
51
+ for (const shape of shapes) {
52
+ if (shape.cutIndex === copperCutFillCutIndex && shape.verts) {
53
+ for (const vert of shape.verts) {
54
+ vertices.push({ x: vert.x, y: vert.y })
55
+ }
56
+ } else if (shape.children) {
57
+ vertices.push(...collectShapeVertices(shape.children))
58
+ }
59
+ }
60
+ return vertices
61
+ }
62
+
63
+ const copperFillVertices = collectShapeVertices(project.children as any)
64
+
65
+ // All copper cut fill vertices should be within board bounds
66
+ // Allow small tolerance for floating point
67
+ const tolerance = 0.001
68
+ for (const { x, y } of copperFillVertices) {
69
+ expect(x).toBeGreaterThanOrEqual(boardMinX - tolerance)
70
+ expect(x).toBeLessThanOrEqual(boardMaxX + tolerance)
71
+ expect(y).toBeGreaterThanOrEqual(boardMinY - tolerance)
72
+ expect(y).toBeLessThanOrEqual(boardMaxY + tolerance)
73
+ }
74
+
75
+ const lbrnSvg = generateLightBurnSvg(project, {
24
76
  margin: 0,
25
77
  width: 600,
26
78
  height: 400,