@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.
- package/dist/index.d.ts +19 -9
- package/dist/index.js +68 -30
- package/lib/RectDiffPipeline.ts +27 -2
- package/lib/solvers/GapFillSolver/ExpandEdgesToEmptySpaceSolver.ts +32 -6
- package/lib/solvers/GapFillSolver/GapFillSolverPipeline.ts +10 -3
- package/lib/solvers/RectDiffGridSolverPipeline/RectDiffGridSolverPipeline.ts +8 -8
- package/lib/solvers/RectDiffGridSolverPipeline/buildObstacleIndexes.ts +7 -8
- package/lib/solvers/RectDiffSeedingSolver/RectDiffSeedingSolver.ts +2 -18
- package/lib/utils/getColorForZLayer.ts +17 -0
- package/package.json +1 -1
- package/tests/__snapshots__/board-outline.snap.svg +1 -16
- package/tests/board-outline.test.ts +10 -3
- package/tests/fixtures/makeCapacityMeshNodeWithLayerInfo.ts +33 -0
- package/tests/solver/__snapshots__/rectDiffGridSolverPipeline.snap.svg +44 -0
- package/tests/solver/rectDiffGridSolverPipeline.test.ts +88 -0
|
@@ -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
|
|
15
|
-
solver
|
|
16
|
-
|
|
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
|
+
}
|