circuit-json-to-lbrn 0.0.44 → 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.
@@ -1,7 +1,7 @@
1
1
  import { test, expect } from "bun:test"
2
2
  import circuitJson from "./example05.circuit.json" with { type: "json" }
3
3
  import { convertCircuitJsonToPcbSvg } from "circuit-to-svg"
4
- import { generateLightBurnSvg } from "lbrnts"
4
+ import { generateLightBurnSvg, ShapePath, ShapeGroup } from "lbrnts"
5
5
  import { convertCircuitJsonToLbrn } from "lib/index"
6
6
  import { stackSvgsVertically } from "stack-svgs"
7
7
  import type { CircuitJson } from "circuit-json"
@@ -20,6 +20,46 @@ test("example05 - copper fill conversion", async () => {
20
20
  })
21
21
  console.log("tmp/example05.lbrn2")
22
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
+
23
63
  const lbrnSvg = await generateLightBurnSvg(project, {
24
64
  margin: 0,
25
65
  width: 600,