@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
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
|
+
import srj from "test-assets/bugreport11-b2de3c.json"
|
|
3
|
+
import {
|
|
4
|
+
getBounds,
|
|
5
|
+
getSvgFromGraphicsObject,
|
|
6
|
+
stackGraphicsVertically,
|
|
7
|
+
type GraphicsObject,
|
|
8
|
+
type Rect,
|
|
9
|
+
} from "graphics-debug"
|
|
10
|
+
import { RectDiffPipeline } from "lib/RectDiffPipeline"
|
|
11
|
+
import { makeCapacityMeshNodeWithLayerInfo } from "tests/fixtures/makeCapacityMeshNodeWithLayerInfo"
|
|
12
|
+
|
|
13
|
+
test("RectDiffPipeline mesh layer snapshots", async () => {
|
|
14
|
+
const solver = new RectDiffPipeline({
|
|
15
|
+
simpleRouteJson: srj.simple_route_json,
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
solver.solve()
|
|
19
|
+
|
|
20
|
+
const { meshNodes } = solver.getOutput()
|
|
21
|
+
const rectsByCombo = makeCapacityMeshNodeWithLayerInfo(meshNodes)
|
|
22
|
+
const allGraphicsObjects: GraphicsObject[] = []
|
|
23
|
+
|
|
24
|
+
// Generate a snapshot for each z-layer
|
|
25
|
+
for (const z of [0, 1, 2, 3]) {
|
|
26
|
+
const layerRects: Rect[] = []
|
|
27
|
+
|
|
28
|
+
for (const [key, rects] of rectsByCombo) {
|
|
29
|
+
const layers = key
|
|
30
|
+
.split(",")
|
|
31
|
+
.map((value) => Number.parseInt(value, 10))
|
|
32
|
+
.filter((value) => !Number.isNaN(value))
|
|
33
|
+
|
|
34
|
+
if (layers.includes(z)) {
|
|
35
|
+
layerRects.push(...rects)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
let labelY = 0
|
|
40
|
+
|
|
41
|
+
if (layerRects.length > 0) {
|
|
42
|
+
let maxY = -Infinity
|
|
43
|
+
|
|
44
|
+
for (const rect of layerRects) {
|
|
45
|
+
const top = rect.center.y + rect.height * (2 / 3)
|
|
46
|
+
|
|
47
|
+
if (top > maxY) maxY = top
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
labelY = maxY
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const graphics: GraphicsObject = {
|
|
54
|
+
title: `RectDiffPipeline - z${z}`,
|
|
55
|
+
texts: [
|
|
56
|
+
{
|
|
57
|
+
anchorSide: "top_right",
|
|
58
|
+
text: `Layer z=${z}`,
|
|
59
|
+
x: 0,
|
|
60
|
+
y: labelY,
|
|
61
|
+
fontSize: 0.5,
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
coordinateSystem: "cartesian",
|
|
65
|
+
rects: layerRects,
|
|
66
|
+
points: [],
|
|
67
|
+
lines: [],
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
allGraphicsObjects.push(graphics)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const stackedGraphics = stackGraphicsVertically(allGraphicsObjects)
|
|
74
|
+
const bounds = getBounds(stackedGraphics)
|
|
75
|
+
const boundsWidth = Math.max(1, bounds.maxX - bounds.minX)
|
|
76
|
+
const boundsHeight = Math.max(1, bounds.maxY - bounds.minY)
|
|
77
|
+
const svgWidth = 640
|
|
78
|
+
const svgHeight = Math.max(
|
|
79
|
+
svgWidth,
|
|
80
|
+
Math.ceil((boundsHeight / boundsWidth) * svgWidth),
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
const svg = getSvgFromGraphicsObject(stackedGraphics, {
|
|
84
|
+
svgWidth,
|
|
85
|
+
svgHeight,
|
|
86
|
+
})
|
|
87
|
+
await expect(svg).toMatchSvgSnapshot(import.meta.path)
|
|
88
|
+
})
|