@tscircuit/rectdiff 0.0.31 → 0.0.32

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