@tscircuit/rectdiff 0.0.14 → 0.0.16

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.
@@ -2,6 +2,7 @@ import { expect, test } from "bun:test"
2
2
  import boardWithCutout from "../test-assets/board-with-cutout.json"
3
3
  import { RectDiffPipeline } from "../lib/RectDiffPipeline"
4
4
  import { getSvgFromGraphicsObject } from "graphics-debug"
5
+ import { makeCapacityMeshNodeWithLayerInfo } from "./fixtures/makeCapacityMeshNodeWithLayerInfo"
5
6
 
6
7
  test("board outline snapshot", async () => {
7
8
  const solver = new RectDiffPipeline({
@@ -11,9 +12,15 @@ test("board outline snapshot", async () => {
11
12
  // Run to completion
12
13
  solver.solve()
13
14
 
14
- const viz =
15
- solver.rectDiffGridSolverPipeline!.rectDiffSeedingSolver!.visualize()
16
- const svg = getSvgFromGraphicsObject(viz)
15
+ const meshNodesGraphics = makeCapacityMeshNodeWithLayerInfo(
16
+ solver?.getOutput().meshNodes || [],
17
+ )
18
+ .values()
19
+ .toArray()
20
+ .flat()
21
+ const svg = getSvgFromGraphicsObject({
22
+ rects: meshNodesGraphics,
23
+ })
17
24
 
18
25
  await expect(svg).toMatchSvgSnapshot(import.meta.path)
19
26
  })
@@ -0,0 +1,33 @@
1
+ import type { Rect } from "graphics-debug"
2
+ import type { CapacityMeshNode } from "lib/types/capacity-mesh-types"
3
+ import { getColorForZLayer } from "lib/utils/getColorForZLayer"
4
+
5
+ export const makeCapacityMeshNodeWithLayerInfo = (
6
+ nodes: CapacityMeshNode[],
7
+ ): Map<string, Rect[]> => {
8
+ const map = new Map<string, Rect[]>()
9
+
10
+ for (const node of nodes) {
11
+ if (!node.availableZ.length) continue
12
+ const key = node.availableZ.join(",")
13
+ const colors = getColorForZLayer(node.availableZ)
14
+ const rect: Rect = {
15
+ center: node.center,
16
+ width: node.width,
17
+ height: node.height,
18
+ layer: `z${key}`,
19
+ stroke: "black",
20
+ fill: node._containsObstacle ? "red" : colors.fill,
21
+ label: "node",
22
+ }
23
+
24
+ const existing = map.get(key)
25
+ if (existing) {
26
+ existing.push(rect)
27
+ } else {
28
+ map.set(key, [rect])
29
+ }
30
+ }
31
+
32
+ return map
33
+ }