@tscircuit/rectdiff 0.0.1 → 0.0.3

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,9 +1,9 @@
1
1
  import { expect, test } from "bun:test"
2
- import simpleRouteJson from "../../test-assets/example-simple-route.json"
2
+ import simpleRouteJson from "../../test-assets/example01.json"
3
3
  import { RectDiffSolver } from "../../lib/solvers/RectDiffSolver"
4
4
  import { getSvgFromGraphicsObject } from "graphics-debug"
5
5
 
6
- test("example01", () => {
6
+ test.skip("example01", () => {
7
7
  const solver = new RectDiffSolver({ simpleRouteJson })
8
8
 
9
9
  solver.solve()
@@ -1 +1 @@
1
- import "bun-match-svg"
1
+ import "bun-match-svg"
@@ -0,0 +1,37 @@
1
+ import { expect, test } from "bun:test"
2
+ import type { SimpleRouteJson } from "../lib/types/srj-types"
3
+ import { RectDiffSolver } from "../lib/solvers/RectDiffSolver"
4
+
5
+ // Legacy SRJs sometimes reference "inner" layers beyond layerCount; ensure we clamp.
6
+ test("RectDiffSolver clamps extra layer names to available z indices", () => {
7
+ const srj: SimpleRouteJson = {
8
+ bounds: { minX: 0, maxX: 5, minY: 0, maxY: 5 },
9
+ connections: [],
10
+ minTraceWidth: 0.2,
11
+ layerCount: 2,
12
+ obstacles: [
13
+ {
14
+ type: "rect",
15
+ center: { x: 1, y: 1 },
16
+ width: 1,
17
+ height: 1,
18
+ layers: ["inner1"],
19
+ connectedTo: [],
20
+ },
21
+ {
22
+ type: "rect",
23
+ center: { x: 3, y: 3 },
24
+ width: 1,
25
+ height: 1,
26
+ layers: ["inner2"],
27
+ connectedTo: [],
28
+ },
29
+ ],
30
+ }
31
+
32
+ const solver = new RectDiffSolver({ simpleRouteJson: srj, mode: "grid" })
33
+ solver.setup()
34
+
35
+ expect(srj.obstacles[0]?.zLayers).toEqual([1])
36
+ expect(srj.obstacles[1]?.zLayers).toEqual([1])
37
+ })
@@ -0,0 +1,37 @@
1
+ import { expect, test } from "bun:test"
2
+ import type { SimpleRouteJson } from "../lib/types/srj-types"
3
+ import { RectDiffSolver } from "../lib/solvers/RectDiffSolver"
4
+
5
+ // Baseline: plain string layers should be auto-converted to numeric zLayers.
6
+ test("RectDiffSolver maps obstacle layers to numeric zLayers", () => {
7
+ const srj: SimpleRouteJson = {
8
+ bounds: { minX: 0, maxX: 10, minY: 0, maxY: 10 },
9
+ connections: [],
10
+ minTraceWidth: 0.2,
11
+ layerCount: 3,
12
+ obstacles: [
13
+ {
14
+ type: "rect",
15
+ center: { x: 1, y: 1 },
16
+ width: 1,
17
+ height: 1,
18
+ layers: ["top"],
19
+ connectedTo: [],
20
+ },
21
+ {
22
+ type: "rect",
23
+ center: { x: 2, y: 2 },
24
+ width: 1,
25
+ height: 1,
26
+ layers: ["inner1", "bottom"],
27
+ connectedTo: [],
28
+ },
29
+ ],
30
+ }
31
+
32
+ const solver = new RectDiffSolver({ simpleRouteJson: srj, mode: "grid" })
33
+ solver.setup()
34
+
35
+ expect(srj.obstacles[0]?.zLayers).toEqual([0])
36
+ expect(srj.obstacles[1]?.zLayers).toEqual([1, 2])
37
+ })
@@ -79,7 +79,7 @@ test("RectDiffSolver handles multi-layer spans", () => {
79
79
 
80
80
  // Check if any nodes span multiple layers
81
81
  const multiLayerNodes = output.meshNodes.filter(
82
- (n) => n.availableZ && n.availableZ.length >= 2
82
+ (n) => n.availableZ && n.availableZ.length >= 2,
83
83
  )
84
84
 
85
85
  // With no obstacles and preferMultiLayer=true, we should get multi-layer nodes
@@ -145,10 +145,11 @@ test("disruptive placement resizes single-layer nodes", () => {
145
145
 
146
146
  // Expect at least one node spanning multiple layers at/through the center
147
147
  const mesh = solver.getOutput().meshNodes
148
- const throughCenter = mesh.find(n =>
149
- Math.abs(n.center.x - 5) < 0.6 &&
150
- Math.abs(n.center.y - 5) < 0.6 &&
151
- (n.availableZ?.length ?? 0) >= 2
148
+ const throughCenter = mesh.find(
149
+ (n) =>
150
+ Math.abs(n.center.x - 5) < 0.6 &&
151
+ Math.abs(n.center.y - 5) < 0.6 &&
152
+ (n.availableZ?.length ?? 0) >= 2,
152
153
  )
153
154
  expect(throughCenter).toBeTruthy()
154
155
  })
package/tests/svg.test.ts CHANGED
@@ -1,12 +1,11 @@
1
- import { expect, test } from "bun:test"
2
-
3
- const testSvg = `<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg">
1
+ import { expect, test } from "bun:test"
2
+
3
+ const testSvg = `<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg">
4
4
  <circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red" />
5
- </svg>`
6
-
7
- test("svg snapshot example", async () => {
8
- // First run will create the snapshot
9
- // Subsequent runs will compare against the saved snapshot
10
- await expect(testSvg).toMatchSvgSnapshot(import.meta.path)
11
- })
12
-
5
+ </svg>`
6
+
7
+ test("svg snapshot example", async () => {
8
+ // First run will create the snapshot
9
+ // Subsequent runs will compare against the saved snapshot
10
+ await expect(testSvg).toMatchSvgSnapshot(import.meta.path)
11
+ })
@@ -1,9 +0,0 @@
1
- {
2
- "permissions": {
3
- "allow": [
4
- "Bash(bunx tsc:*)"
5
- ],
6
- "deny": [],
7
- "ask": []
8
- }
9
- }
package/bun.lock DELETED
@@ -1,29 +0,0 @@
1
- {
2
- "lockfileVersion": 1,
3
- "workspaces": {
4
- "": {
5
- "name": "rectdiff",
6
- "devDependencies": {
7
- "@types/bun": "latest",
8
- },
9
- "peerDependencies": {
10
- "typescript": "^5",
11
- },
12
- },
13
- },
14
- "packages": {
15
- "@types/bun": ["@types/bun@1.3.2", "", { "dependencies": { "bun-types": "1.3.2" } }, "sha512-t15P7k5UIgHKkxwnMNkJbWlh/617rkDGEdSsDbu+qNHTaz9SKf7aC8fiIlUdD5RPpH6GEkP0cK7WlvmrEBRtWg=="],
16
-
17
- "@types/node": ["@types/node@24.10.1", "", { "dependencies": { "undici-types": "~7.16.0" } }, "sha512-GNWcUTRBgIRJD5zj+Tq0fKOJ5XZajIiBroOF0yvj2bSU1WvNdYS/dn9UxwsujGW4JX06dnHyjV2y9rRaybH0iQ=="],
18
-
19
- "@types/react": ["@types/react@19.2.5", "", { "dependencies": { "csstype": "^3.0.2" } }, "sha512-keKxkZMqnDicuvFoJbzrhbtdLSPhj/rZThDlKWCDbgXmUg0rEUFtRssDXKYmtXluZlIqiC5VqkCgRwzuyLHKHw=="],
20
-
21
- "bun-types": ["bun-types@1.3.2", "", { "dependencies": { "@types/node": "*" }, "peerDependencies": { "@types/react": "^19" } }, "sha512-i/Gln4tbzKNuxP70OWhJRZz1MRfvqExowP7U6JKoI8cntFrtxg7RJK3jvz7wQW54UuvNC8tbKHHri5fy74FVqg=="],
22
-
23
- "csstype": ["csstype@3.2.1", "", {}, "sha512-98XGutrXoh75MlgLihlNxAGbUuFQc7l1cqcnEZlLNKc0UrVdPndgmaDmYTDDh929VS/eqTZV0rozmhu2qqT1/g=="],
24
-
25
- "typescript": ["typescript@5.9.3", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw=="],
26
-
27
- "undici-types": ["undici-types@7.16.0", "", {}, "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw=="],
28
- }
29
- }