circuit-json-to-lbrn 0.0.45 → 0.0.47

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.
@@ -0,0 +1 @@
1
+ * @AnasSarkiz
@@ -6,22 +6,6 @@ import { getManifold } from "./getManifold"
6
6
 
7
7
  type Contour = Array<[number, number]>
8
8
 
9
- /**
10
- * Calculates the signed area of a contour.
11
- * Positive area = counter-clockwise winding (outer boundary)
12
- * Negative area = clockwise winding (hole)
13
- */
14
- const getSignedArea = (contour: Contour): number => {
15
- let area = 0
16
- const n = contour.length
17
- for (let i = 0; i < n; i++) {
18
- const j = (i + 1) % n
19
- area += contour[i]![0] * contour[j]![1]
20
- area -= contour[j]![0] * contour[i]![1]
21
- }
22
- return area / 2
23
- }
24
-
25
9
  /**
26
10
  * Converts a flatten-js Polygon to an array of contours for manifold CrossSection
27
11
  * Each contour is an array of [x, y] coordinates
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "circuit-json-to-lbrn",
3
3
  "main": "dist/index.js",
4
- "version": "0.0.45",
4
+ "version": "0.0.47",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "start": "bun run site/index.html",
@@ -28,7 +28,7 @@
28
28
  "typescript": "^5"
29
29
  },
30
30
  "dependencies": {
31
- "lbrnts": "^0.0.13",
31
+ "lbrnts": "^0.0.14",
32
32
  "manifold-3d": "^3.3.2"
33
33
  }
34
34
  }
@@ -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
- import { generateLightBurnSvg, ShapePath, ShapeGroup } from "lbrnts"
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,27 +21,39 @@ test("example05 - copper fill conversion", async () => {
20
21
  })
21
22
  console.log("tmp/example05.lbrn2")
22
23
 
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
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
+ }
28
42
 
29
43
  // 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
44
  const copperCutFillCutIndex = 4 // "Top Copper Cut Fill" cut setting
32
45
 
33
46
  // Collect all vertices from copper cut fill shapes
34
47
  const collectShapeVertices = (
35
- shapes: Array<ShapePath | ShapeGroup>,
36
- ): Array<[number, number]> => {
37
- const vertices: Array<[number, number]> = []
48
+ shapes: any[],
49
+ ): Array<{ x: number; y: number }> => {
50
+ const vertices: Array<{ x: number; y: number }> = []
38
51
  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]!])
52
+ if (shape.cutIndex === copperCutFillCutIndex && shape.verts) {
53
+ for (const vert of shape.verts) {
54
+ vertices.push({ x: vert.x, y: vert.y })
42
55
  }
43
- } else if (shape instanceof ShapeGroup) {
56
+ } else if (shape.children) {
44
57
  vertices.push(...collectShapeVertices(shape.children))
45
58
  }
46
59
  }
@@ -50,17 +63,16 @@ test("example05 - copper fill conversion", async () => {
50
63
  const copperFillVertices = collectShapeVertices(project.children as any)
51
64
 
52
65
  // All copper cut fill vertices should be within board bounds
53
- // The origin shifts coordinates so they start at (0, 0)
54
66
  // Allow small tolerance for floating point
55
67
  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)
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)
61
73
  }
62
74
 
63
- const lbrnSvg = await generateLightBurnSvg(project, {
75
+ const lbrnSvg = generateLightBurnSvg(project, {
64
76
  margin: 0,
65
77
  width: 600,
66
78
  height: 400,