@tscircuit/rectdiff 0.0.19 → 0.0.21
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/.github/workflows/bun-test.yml +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +28 -35
- package/lib/solvers/RectDiffExpansionSolver/RectDiffExpansionSolver.ts +6 -3
- package/lib/solvers/RectDiffGridSolverPipeline/buildObstacleIndexes.ts +2 -1
- package/lib/solvers/RectDiffSeedingSolver/RectDiffSeedingSolver.ts +2 -7
- package/lib/types/capacity-mesh-types.ts +1 -0
- package/lib/utils/expandRectFromSeed.ts +3 -0
- package/lib/utils/rectToTree.ts +5 -1
- package/lib/utils/resizeSoftOverlaps.ts +8 -16
- package/package.json +1 -1
- package/tests/solver/__snapshots__/rectDiffGridSolverPipeline.snap.svg +3 -3
- package/tests/solver/both-points-equivalent/__snapshots__/both-points-equivalent.snap.svg +44 -0
- package/tests/solver/both-points-equivalent/both-points-equivalent.srj.json +64 -0
- package/tests/solver/both-points-equivalent/both-points-equivalent.test.ts +92 -0
- package/tests/solver/bugreport01-be84eb/__snapshots__/bugreport01-be84eb.snap.svg +44 -0
- package/tests/solver/bugreport01-be84eb/bugreport01-be84eb.json +929 -0
- package/tests/solver/bugreport01-be84eb/bugreport01-be84eb.test.ts +93 -0
- package/tests/solver/bugreport02-bc4361/__snapshots__/bugreport02-bc4361.snap.svg +44 -0
- package/tests/solver/bugreport02-bc4361/bugreport02-bc4361.json +1276 -0
- package/tests/solver/bugreport02-bc4361/bugreport02-bc4361.test.ts +93 -0
- package/tests/solver/bugreport03-fe4a17/__snapshots__/bugreport03-fe4a17.snap.svg +44 -0
- package/tests/solver/bugreport03-fe4a17/bugreport03-fe4a17.json +986 -0
- package/tests/solver/bugreport03-fe4a17/bugreport03-fe4a17.test.ts +93 -0
- package/tests/solver/bugreport07-d3f3be/__snapshots__/bugreport07-d3f3be.snap.svg +44 -0
- package/tests/solver/bugreport07-d3f3be/bugreport07-d3f3be.json +1211 -0
- package/tests/solver/bugreport07-d3f3be/bugreport07-d3f3be.test.ts +93 -0
- package/tests/solver/bugreport08-e3ec95/__snapshots__/bugreport08-e3ec95.snap.svg +44 -0
- package/tests/solver/bugreport08-e3ec95/bugreport08-e3ec95.json +1511 -0
- package/tests/solver/bugreport08-e3ec95/bugreport08-e3ec95.test.ts +93 -0
- package/tests/solver/bugreport09-618e09/__snapshots__/bugreport09-618e09.snap.svg +44 -0
- package/tests/solver/bugreport09-618e09/bugreport09-618e09.json +2827 -0
- package/tests/solver/bugreport09-618e09/bugreport09-618e09.test.ts +93 -0
- package/tests/solver/bugreport10-71239a/__snapshots__/bugreport10-71239a.snap.svg +44 -0
- package/tests/solver/bugreport10-71239a/bugreport10-71239a.json +890 -0
- package/tests/solver/bugreport10-71239a/bugreport10-71239a.test.ts +93 -0
- package/tests/solver/bugreport11-b2de3c/__snapshots__/bugreport11-b2de3c.snap.svg +44 -0
- package/tests/solver/bugreport11-b2de3c/bugreport11-b2de3c.json +4315 -0
- package/tests/solver/bugreport11-b2de3c/bugreport11-b2de3c.test.ts +93 -0
- package/tests/solver/bugreport12-35ce1c/__snapshots__/bugreport12-35ce1c.snap.svg +44 -0
- package/tests/solver/bugreport12-35ce1c/bugreport12-35ce1c.json +475 -0
- package/tests/solver/bugreport12-35ce1c/bugreport12-35ce1c.test.ts +93 -0
- package/tests/solver/bugreport13-b9a758/__snapshots__/bugreport13-b9a758.snap.svg +44 -0
- package/tests/solver/bugreport13-b9a758/bugreport13-b9a758.json +15815 -0
- package/tests/solver/bugreport13-b9a758/bugreport13-b9a758.test.ts +93 -0
- package/tests/solver/bugreport16-d95f38/__snapshots__/bugreport16-d95f38.snap.svg +44 -0
- package/tests/solver/bugreport16-d95f38/bugreport16-d95f38.json +623 -0
- package/tests/solver/bugreport16-d95f38/bugreport16-d95f38.test.ts +93 -0
- package/tests/solver/bugreport18-1b2d06/__snapshots__/bugreport18-1b2d06.snap.svg +44 -0
- package/tests/solver/bugreport18-1b2d06/bugreport18-1b2d06.json +543 -0
- package/tests/solver/bugreport18-1b2d06/bugreport18-1b2d06.test.ts +93 -0
- package/tests/solver/bugreport19/__snapshots__/bugreport19.snap.svg +44 -0
- package/tests/solver/bugreport19/bugreport19.json +678 -0
- package/tests/solver/bugreport19/bugreport19.test.ts +93 -0
- package/tests/solver/bugreport20-obstacle-clipping/__snapshots__/bugreport20-obstacle-clipping.snap.svg +44 -0
- package/tests/solver/bugreport20-obstacle-clipping/bugreport20-obstacle-clipping.json +109 -0
- package/tests/solver/bugreport20-obstacle-clipping/bugreport20-obstacle-clipping.test.ts +93 -0
- package/tests/solver/bugreport21-board-outline/__snapshots__/bugreport21-board-outline.snap.svg +44 -0
- package/tests/solver/bugreport21-board-outline/bugreport21-board-outline.json +148 -0
- package/tests/solver/bugreport21-board-outline/bugreport21-board-outline.test.ts +93 -0
- package/tests/solver/bugreport22-2a75ce/__snapshots__/bugreport22-2a75ce.snap.svg +44 -0
- package/tests/solver/bugreport22-2a75ce/bugreport22-2a75ce.json +1550 -0
- package/tests/solver/bugreport22-2a75ce/bugreport22-2a75ce.test.ts +93 -0
- package/tests/solver/bugreport23-LGA15x4/__snapshots__/bugreport23-LGA15x4.snap.svg +44 -0
- package/tests/solver/bugreport23-LGA15x4/bugreport23-LGA15x4.srj.json +2401 -0
- package/tests/solver/bugreport23-LGA15x4/bugreport23-LGA15x4.test.ts +92 -0
- package/tests/solver/bugreport24-05597c/__snapshots__/bugreport24-05597c.snap.svg +44 -0
- package/tests/solver/bugreport24-05597c/bugreport24-05597c.json +8427 -0
- package/tests/solver/bugreport24-05597c/bugreport24-05597c.test.ts +93 -0
- package/tests/solver/bugreport25-4b1d55/__snapshots__/bugreport25-4b1d55.snap.svg +44 -0
- package/tests/solver/bugreport25-4b1d55/bugreport25-4b1d55.json +119 -0
- package/tests/solver/bugreport25-4b1d55/bugreport25-4b1d55.test.ts +93 -0
- package/tests/solver/bugreport26-66b0b2/__snapshots__/bugreport26-66b0b2.snap.svg +44 -0
- package/tests/solver/bugreport26-66b0b2/bugreport26-66b0b2.json +1651 -0
- package/tests/solver/bugreport26-66b0b2/bugreport26-66b0b2.test.ts +93 -0
- package/tests/solver/bugreport27-dd3734/__snapshots__/bugreport27-dd3734.snap.svg +44 -0
- package/tests/solver/bugreport27-dd3734/bugreport27-dd3734.json +4116 -0
- package/tests/solver/bugreport27-dd3734/bugreport27-dd3734.test.ts +93 -0
- package/tests/solver/bugreport28-18a9ef/__snapshots__/bugreport28-18a9ef.snap.svg +44 -0
- package/tests/solver/bugreport28-18a9ef/bugreport28-18a9ef.json +4116 -0
- package/tests/solver/bugreport28-18a9ef/bugreport28-18a9ef.test.ts +93 -0
- package/tests/solver/bugreport29-7deae8/__snapshots__/bugreport29-7deae8.snap.svg +44 -0
- package/tests/solver/bugreport29-7deae8/bugreport29-7deae8.json +4118 -0
- package/tests/solver/bugreport29-7deae8/bugreport29-7deae8.test.ts +93 -0
- package/tests/solver/bugreport30-2174c8/__snapshots__/bugreport30-2174c8.snap.svg +44 -0
- package/tests/solver/bugreport30-2174c8/bugreport30-2174c8.json +4007 -0
- package/tests/solver/bugreport30-2174c8/bugreport30-2174c8.test.ts +93 -0
- package/tests/solver/bugreport33-213d45/__snapshots__/bugreport33-213d45.snap.svg +44 -0
- package/tests/solver/bugreport33-213d45/bugreport33-213d45.json +5089 -0
- package/tests/solver/bugreport33-213d45/bugreport33-213d45.test.ts +93 -0
- package/tests/solver/bugreport34-e9dea2/__snapshots__/bugreport34-e9dea2.snap.svg +44 -0
- package/tests/solver/bugreport34-e9dea2/bugreport34-e9dea2.json +3924 -0
- package/tests/solver/bugreport34-e9dea2/bugreport34-e9dea2.test.ts +93 -0
- package/tests/solver/bugreport35-191db9/__snapshots__/bugreport35-191db9.snap.svg +44 -0
- package/tests/solver/bugreport35-191db9/bugreport35-191db9.json +4237 -0
- package/tests/solver/bugreport35-191db9/bugreport35-191db9.test.ts +93 -0
- package/tests/solver/bugreport36-bf8303/__snapshots__/bugreport36-bf8303.snap.svg +44 -0
- package/tests/solver/bugreport36-bf8303/bugreport36-bf8303.json +29660 -0
- package/tests/solver/bugreport36-bf8303/bugreport36-bf8303.test.ts +93 -0
- package/tests/solver/interaction/__snapshots__/interaction.snap.svg +44 -0
- package/tests/solver/interaction/interaction.srj.json +58 -0
- package/tests/solver/interaction/interaction.test.ts +92 -0
- package/tests/solver/multi-point/__snapshots__/multi-point.snap.svg +44 -0
- package/tests/solver/multi-point/multi-point.srj.json +57 -0
- package/tests/solver/multi-point/multi-point.test.ts +92 -0
- package/tests/solver/no-better-path/__snapshots__/no-better-path.snap.svg +44 -0
- package/tests/solver/no-better-path/no-better-path.srj.json +48 -0
- package/tests/solver/no-better-path/no-better-path.test.ts +92 -0
- package/tests/solver/offboardconnects01/__snapshots__/offboardconnects01.snap.svg +44 -0
- package/tests/solver/offboardconnects01/offboardconnects01.srj.json +53 -0
- package/tests/solver/offboardconnects01/offboardconnects01.test.ts +92 -0
- package/tests/solver/pcb_trace_id-should-return-root-connection-name/__snapshots__/pcb_trace_id-should-return-root-connection-name.snap.svg +44 -0
- package/tests/solver/pcb_trace_id-should-return-root-connection-name/pcb_trace_id-should-return-root-connection-name.srj.json +129 -0
- package/tests/solver/pcb_trace_id-should-return-root-connection-name/pcb_trace_id-should-return-root-connection-name.test.ts +92 -0
- package/tests/solver/transitivity/__snapshots__/transitivity.snap.svg +44 -0
- package/tests/solver/transitivity/transitivity.srj.json +64 -0
- package/tests/solver/transitivity/transitivity.test.ts +92 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"layerCount": 2,
|
|
3
|
+
"minTraceWidth": 0.2,
|
|
4
|
+
"obstacles": [
|
|
5
|
+
{
|
|
6
|
+
"type": "rect",
|
|
7
|
+
"layers": ["top"],
|
|
8
|
+
"center": { "x": 0, "y": 0 },
|
|
9
|
+
"width": 1,
|
|
10
|
+
"height": 1,
|
|
11
|
+
"connectedTo": ["X"]
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"type": "rect",
|
|
15
|
+
"layers": ["top"],
|
|
16
|
+
"center": { "x": 5, "y": 5 },
|
|
17
|
+
"width": 1,
|
|
18
|
+
"height": 1,
|
|
19
|
+
"connectedTo": ["A"]
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"type": "rect",
|
|
23
|
+
"layers": ["top"],
|
|
24
|
+
"center": { "x": 20, "y": 20 },
|
|
25
|
+
"width": 1,
|
|
26
|
+
"height": 1,
|
|
27
|
+
"connectedTo": ["B"]
|
|
28
|
+
}
|
|
29
|
+
],
|
|
30
|
+
"connections": [
|
|
31
|
+
{
|
|
32
|
+
"name": "on-board",
|
|
33
|
+
"pointsToConnect": [
|
|
34
|
+
{ "x": 0, "y": 0, "layer": "top", "pointId": "X" },
|
|
35
|
+
{ "x": 5, "y": 5, "layer": "top", "pointId": "A" }
|
|
36
|
+
]
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"name": "off-board",
|
|
40
|
+
"isOffBoard": true,
|
|
41
|
+
"pointsToConnect": [
|
|
42
|
+
{ "x": 5, "y": 5, "layer": "top", "pointId": "A" },
|
|
43
|
+
{ "x": 20, "y": 20, "layer": "top", "pointId": "B" }
|
|
44
|
+
]
|
|
45
|
+
}
|
|
46
|
+
],
|
|
47
|
+
"bounds": { "minX": -5, "maxX": 25, "minY": -5, "maxY": 25 }
|
|
48
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
|
+
import srj from "./no-better-path.srj.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("no-better-path", async () => {
|
|
16
|
+
const solver = new RectDiffPipeline({
|
|
17
|
+
simpleRouteJson: srj,
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
const outline = makeSimpleRouteOutlineGraphics(srj)
|
|
21
|
+
|
|
22
|
+
solver.solve()
|
|
23
|
+
|
|
24
|
+
const { meshNodes } = solver.getOutput()
|
|
25
|
+
const rectsByCombo = makeCapacityMeshNodeWithLayerInfo(meshNodes)
|
|
26
|
+
const allGraphicsObjects: GraphicsObject[] = []
|
|
27
|
+
|
|
28
|
+
// Generate a snapshot for each z-layer
|
|
29
|
+
for (const z of Array.from({ length: srj.layerCount }, (_, index) => index)) {
|
|
30
|
+
const layerRects: Rect[] = []
|
|
31
|
+
|
|
32
|
+
for (const [key, rects] of rectsByCombo) {
|
|
33
|
+
const layers = key
|
|
34
|
+
.split(",")
|
|
35
|
+
.map((value) => Number.parseInt(value, 10))
|
|
36
|
+
.filter((value) => !Number.isNaN(value))
|
|
37
|
+
|
|
38
|
+
if (layers.includes(z)) {
|
|
39
|
+
layerRects.push(...rects)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
let labelY = 0
|
|
44
|
+
|
|
45
|
+
if (layerRects.length > 0) {
|
|
46
|
+
let maxY = -Infinity
|
|
47
|
+
|
|
48
|
+
for (const rect of layerRects) {
|
|
49
|
+
const top = rect.center.y + rect.height * (2 / 3)
|
|
50
|
+
|
|
51
|
+
if (top > maxY) maxY = top
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
labelY = maxY
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const graphics: GraphicsObject = {
|
|
58
|
+
title: `RectDiffPipeline - z${z}`,
|
|
59
|
+
texts: [
|
|
60
|
+
{
|
|
61
|
+
anchorSide: "top_right",
|
|
62
|
+
text: `Layer z=${z}`,
|
|
63
|
+
x: 0,
|
|
64
|
+
y: labelY,
|
|
65
|
+
fontSize: 0.5,
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
coordinateSystem: "cartesian",
|
|
69
|
+
rects: layerRects,
|
|
70
|
+
points: [],
|
|
71
|
+
lines: [],
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
allGraphicsObjects.push(mergeGraphics(graphics, outline))
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const stackedGraphics = stackGraphicsVertically(allGraphicsObjects)
|
|
78
|
+
const bounds = getBounds(stackedGraphics)
|
|
79
|
+
const boundsWidth = Math.max(1, bounds.maxX - bounds.minX)
|
|
80
|
+
const boundsHeight = Math.max(1, bounds.maxY - bounds.minY)
|
|
81
|
+
const svgWidth = 640
|
|
82
|
+
const svgHeight = Math.max(
|
|
83
|
+
svgWidth,
|
|
84
|
+
Math.ceil((boundsHeight / boundsWidth) * svgWidth),
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
const svg = getSvgFromGraphicsObject(stackedGraphics, {
|
|
88
|
+
svgWidth,
|
|
89
|
+
svgHeight,
|
|
90
|
+
})
|
|
91
|
+
await expect(svg).toMatchSvgSnapshot(import.meta.path)
|
|
92
|
+
})
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
<svg width="640" height="1548" viewBox="0 0 640 1548" xmlns="http://www.w3.org/2000/svg"><rect width="100%" height="100%" fill="white"/><g><polyline data-points="-15,-15 15,-15 15,15 -15,15 -15,-15" data-type="line" data-label="bounds" points="40,698.75 600,698.75 600,138.75 40,138.75 40,698.75" fill="none" stroke="#111827" stroke-width="1.866666666666667"/></g><g><polyline data-points="-15,-55.3125 15,-55.3125 15,-25.3125 -15,-25.3125 -15,-55.3125" data-type="line" data-label="bounds" points="40,1451.25 600,1451.25 600,891.25 40,891.25 40,1451.25" fill="none" stroke="#111827" stroke-width="1.866666666666667"/></g><g><rect data-type="rect" data-label="node" data-x="0" data-y="9.75" x="40" y="138.75" width="560" height="196" fill="#dbeafe" stroke="black" stroke-width="0.05357142857142857"/></g><g><rect data-type="rect" data-label="node" data-x="1.5" data-y="-5.25" x="236" y="334.75" width="224" height="364" fill="#dbeafe" stroke="black" stroke-width="0.05357142857142857"/></g><g><rect data-type="rect" data-label="node" data-x="-12.25" data-y="-3.7750000000000004" x="40" y="334.75" width="102.66666666666666" height="308.9333333333334" fill="#dbeafe" stroke="black" stroke-width="0.05357142857142857"/></g><g><rect data-type="rect" data-label="node" data-x="-7" data-y="-11.25" x="142.66666666666666" y="558.75" width="93.33333333333334" height="140" fill="#dbeafe" stroke="black" stroke-width="0.05357142857142857"/></g><g><rect data-type="rect" data-label="node" data-x="11.25" data-y="-11.25" x="460" y="558.75" width="140" height="140" fill="#dbeafe" stroke="black" stroke-width="0.05357142857142857"/></g><g><rect data-type="rect" data-label="node" data-x="11.25" data-y="1" x="460" y="334.75" width="140" height="130.66666666666669" fill="#dbeafe" stroke="black" stroke-width="0.05357142857142857"/></g><g><rect data-type="rect" data-label="node" data-x="-12.25" data-y="-13.525" x="40" y="643.6833333333334" width="102.66666666666666" height="55.066666666666606" fill="#dbeafe" stroke="black" stroke-width="0.05357142857142857"/></g><g><rect data-type="rect" data-label="node" data-x="-7" data-y="-1.5" x="142.66666666666666" y="428.0833333333333" width="93.33333333333334" height="37.33333333333337" fill="#dbeafe" stroke="black" stroke-width="0.05357142857142857"/></g><g><rect data-type="rect" data-label="node" data-x="13.75" data-y="-5" x="553.3333333333334" y="465.4166666666667" width="46.66666666666663" height="93.33333333333331" fill="#dbeafe" stroke="black" stroke-width="0.05357142857142857"/></g><g><rect data-type="rect" data-label="node" data-x="-7" data-y="2" x="142.66666666666666" y="334.75" width="93.33333333333334" height="93.33333333333331" fill="red" stroke="black" stroke-width="0.05357142857142857"/></g><g><rect data-type="rect" data-label="node" data-x="10" data-y="-5" x="460" y="465.4166666666667" width="93.33333333333337" height="93.33333333333331" fill="red" stroke="black" stroke-width="0.05357142857142857"/></g><g><rect data-type="rect" data-label="node" data-x="-7" data-y="-5" x="142.66666666666666" y="465.4166666666667" width="93.33333333333334" height="93.33333333333331" fill="red" stroke="black" stroke-width="0.05357142857142857"/></g><g><rect data-type="rect" data-label="node" data-x="0" data-y="-30.5625" x="40" y="891.25" width="560" height="196" fill="#dbeafe" stroke="black" stroke-width="0.05357142857142857"/></g><g><rect data-type="rect" data-label="node" data-x="1.5" data-y="-45.5625" x="236" y="1087.25" width="224" height="364" fill="#dbeafe" stroke="black" stroke-width="0.05357142857142857"/></g><g><rect data-type="rect" data-label="node" data-x="-12.25" data-y="-44.0875" x="40" y="1087.25" width="102.66666666666666" height="308.9333333333334" fill="#dbeafe" stroke="black" stroke-width="0.05357142857142857"/></g><g><rect data-type="rect" data-label="node" data-x="-7" data-y="-51.5625" x="142.66666666666666" y="1311.25" width="93.33333333333334" height="140" fill="#dbeafe" stroke="black" stroke-width="0.05357142857142857"/></g><g><rect data-type="rect" data-label="node" data-x="11.25" data-y="-51.5625" x="460" y="1311.25" width="140" height="140" fill="#dbeafe" stroke="black" stroke-width="0.05357142857142857"/></g><g><rect data-type="rect" data-label="node" data-x="11.25" data-y="-39.3125" x="460" y="1087.25" width="140" height="130.66666666666674" fill="#dbeafe" stroke="black" stroke-width="0.05357142857142857"/></g><g><rect data-type="rect" data-label="node" data-x="-12.25" data-y="-53.8375" x="40" y="1396.1833333333334" width="102.66666666666666" height="55.066666666666606" fill="#dbeafe" stroke="black" stroke-width="0.05357142857142857"/></g><g><rect data-type="rect" data-label="node" data-x="-7" data-y="-41.8125" x="142.66666666666666" y="1180.5833333333335" width="93.33333333333334" height="37.33333333333326" fill="#dbeafe" stroke="black" stroke-width="0.05357142857142857"/></g><g><rect data-type="rect" data-label="node" data-x="13.75" data-y="-45.3125" x="553.3333333333334" y="1217.9166666666667" width="46.66666666666663" height="93.33333333333326" fill="#dbeafe" stroke="black" stroke-width="0.05357142857142857"/></g><g><rect data-type="rect" data-label="node" data-x="-7" data-y="-38.3125" x="142.66666666666666" y="1087.25" width="93.33333333333334" height="93.33333333333348" fill="red" stroke="black" stroke-width="0.05357142857142857"/></g><g><rect data-type="rect" data-label="node" data-x="10" data-y="-45.3125" x="460" y="1217.9166666666667" width="93.33333333333337" height="93.33333333333326" fill="red" stroke="black" stroke-width="0.05357142857142857"/></g><g><rect data-type="rect" data-label="node" data-x="-7" data-y="-45.3125" x="142.66666666666666" y="1217.9166666666667" width="93.33333333333334" height="93.33333333333326" fill="red" stroke="black" stroke-width="0.05357142857142857"/></g><text data-type="text" data-label="Layer z=0" data-x="0" data-y="16.75" x="320" y="106.08333333333331" fill="black" font-size="9.333333333333334" font-family="sans-serif" text-anchor="end" dominant-baseline="text-before-edge">Layer z=0</text><text data-type="text" data-label="Layer z=1" data-x="0" data-y="-23.5625" x="320" y="858.5833333333334" fill="black" font-size="9.333333333333334" font-family="sans-serif" text-anchor="end" dominant-baseline="text-before-edge">Layer z=1</text><g id="crosshair" style="display: none"><line id="crosshair-h" y1="0" y2="1548" stroke="#666" stroke-width="0.5"/><line id="crosshair-v" x1="0" x2="640" stroke="#666" stroke-width="0.5"/><text id="coordinates" font-family="monospace" font-size="12" fill="#666"></text></g><script><![CDATA[
|
|
2
|
+
document.currentScript.parentElement.addEventListener('mousemove', (e) => {
|
|
3
|
+
const svg = e.currentTarget;
|
|
4
|
+
const rect = svg.getBoundingClientRect();
|
|
5
|
+
const x = e.clientX - rect.left;
|
|
6
|
+
const y = e.clientY - rect.top;
|
|
7
|
+
const crosshair = svg.getElementById('crosshair');
|
|
8
|
+
const h = svg.getElementById('crosshair-h');
|
|
9
|
+
const v = svg.getElementById('crosshair-v');
|
|
10
|
+
const coords = svg.getElementById('coordinates');
|
|
11
|
+
|
|
12
|
+
crosshair.style.display = 'block';
|
|
13
|
+
h.setAttribute('x1', '0');
|
|
14
|
+
h.setAttribute('x2', '640');
|
|
15
|
+
h.setAttribute('y1', y);
|
|
16
|
+
h.setAttribute('y2', y);
|
|
17
|
+
v.setAttribute('x1', x);
|
|
18
|
+
v.setAttribute('x2', x);
|
|
19
|
+
v.setAttribute('y1', '0');
|
|
20
|
+
v.setAttribute('y2', '1548');
|
|
21
|
+
|
|
22
|
+
// Calculate real coordinates using inverse transformation
|
|
23
|
+
const matrix = {"a":18.666666666666668,"c":0,"e":320,"b":0,"d":-18.666666666666668,"f":418.75};
|
|
24
|
+
// Manually invert and apply the affine transform
|
|
25
|
+
// Since we only use translate and scale, we can directly compute:
|
|
26
|
+
// x' = (x - tx) / sx
|
|
27
|
+
// y' = (y - ty) / sy
|
|
28
|
+
const sx = matrix.a;
|
|
29
|
+
const sy = matrix.d;
|
|
30
|
+
const tx = matrix.e;
|
|
31
|
+
const ty = matrix.f;
|
|
32
|
+
const realPoint = {
|
|
33
|
+
x: (x - tx) / sx,
|
|
34
|
+
y: (y - ty) / sy // Flip y back since we used negative scale
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
coords.textContent = `(${realPoint.x.toFixed(2)}, ${realPoint.y.toFixed(2)})`;
|
|
38
|
+
coords.setAttribute('x', (x + 5).toString());
|
|
39
|
+
coords.setAttribute('y', (y - 5).toString());
|
|
40
|
+
});
|
|
41
|
+
document.currentScript.parentElement.addEventListener('mouseleave', () => {
|
|
42
|
+
document.currentScript.parentElement.getElementById('crosshair').style.display = 'none';
|
|
43
|
+
});
|
|
44
|
+
]]></script></svg>
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"layerCount": 2,
|
|
3
|
+
"minTraceWidth": 0.2,
|
|
4
|
+
"obstacles": [
|
|
5
|
+
{
|
|
6
|
+
"type": "rect",
|
|
7
|
+
"layers": ["top", "bottom"],
|
|
8
|
+
"center": { "x": -7, "y": 2 },
|
|
9
|
+
"width": 5,
|
|
10
|
+
"height": 5,
|
|
11
|
+
"connectedTo": ["pointA"]
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"type": "rect",
|
|
15
|
+
"layers": ["top", "bottom"],
|
|
16
|
+
"center": { "x": 10, "y": -5 },
|
|
17
|
+
"width": 5,
|
|
18
|
+
"height": 5,
|
|
19
|
+
"connectedTo": ["pointB"]
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"type": "rect",
|
|
23
|
+
"layers": ["top", "bottom"],
|
|
24
|
+
"center": { "x": -7, "y": -5 },
|
|
25
|
+
"width": 5,
|
|
26
|
+
"height": 5,
|
|
27
|
+
"connectedTo": ["pointC"]
|
|
28
|
+
}
|
|
29
|
+
],
|
|
30
|
+
"connections": [
|
|
31
|
+
{
|
|
32
|
+
"name": "connectionA",
|
|
33
|
+
"pointsToConnect": [
|
|
34
|
+
{ "x": -7, "y": 2, "layer": "top", "pointId": "pointA" },
|
|
35
|
+
{ "x": 10, "y": -5, "layer": "top", "pointId": "pointB" }
|
|
36
|
+
]
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"name": "connectionB",
|
|
40
|
+
"isOffBoard": true,
|
|
41
|
+
"pointsToConnect": [
|
|
42
|
+
{ "x": -7, "y": -5, "layer": "top", "pointId": "pointC" },
|
|
43
|
+
{ "x": 10, "y": -5, "layer": "top", "pointId": "pointB" }
|
|
44
|
+
]
|
|
45
|
+
}
|
|
46
|
+
],
|
|
47
|
+
"bounds": {
|
|
48
|
+
"minX": -15,
|
|
49
|
+
"maxX": 15,
|
|
50
|
+
"minY": -15,
|
|
51
|
+
"maxY": 15
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
|
+
import srj from "./offboardconnects01.srj.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("offboardconnects01", async () => {
|
|
16
|
+
const solver = new RectDiffPipeline({
|
|
17
|
+
simpleRouteJson: srj,
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
const outline = makeSimpleRouteOutlineGraphics(srj)
|
|
21
|
+
|
|
22
|
+
solver.solve()
|
|
23
|
+
|
|
24
|
+
const { meshNodes } = solver.getOutput()
|
|
25
|
+
const rectsByCombo = makeCapacityMeshNodeWithLayerInfo(meshNodes)
|
|
26
|
+
const allGraphicsObjects: GraphicsObject[] = []
|
|
27
|
+
|
|
28
|
+
// Generate a snapshot for each z-layer
|
|
29
|
+
for (const z of Array.from({ length: srj.layerCount }, (_, index) => index)) {
|
|
30
|
+
const layerRects: Rect[] = []
|
|
31
|
+
|
|
32
|
+
for (const [key, rects] of rectsByCombo) {
|
|
33
|
+
const layers = key
|
|
34
|
+
.split(",")
|
|
35
|
+
.map((value) => Number.parseInt(value, 10))
|
|
36
|
+
.filter((value) => !Number.isNaN(value))
|
|
37
|
+
|
|
38
|
+
if (layers.includes(z)) {
|
|
39
|
+
layerRects.push(...rects)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
let labelY = 0
|
|
44
|
+
|
|
45
|
+
if (layerRects.length > 0) {
|
|
46
|
+
let maxY = -Infinity
|
|
47
|
+
|
|
48
|
+
for (const rect of layerRects) {
|
|
49
|
+
const top = rect.center.y + rect.height * (2 / 3)
|
|
50
|
+
|
|
51
|
+
if (top > maxY) maxY = top
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
labelY = maxY
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const graphics: GraphicsObject = {
|
|
58
|
+
title: `RectDiffPipeline - z${z}`,
|
|
59
|
+
texts: [
|
|
60
|
+
{
|
|
61
|
+
anchorSide: "top_right",
|
|
62
|
+
text: `Layer z=${z}`,
|
|
63
|
+
x: 0,
|
|
64
|
+
y: labelY,
|
|
65
|
+
fontSize: 0.5,
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
coordinateSystem: "cartesian",
|
|
69
|
+
rects: layerRects,
|
|
70
|
+
points: [],
|
|
71
|
+
lines: [],
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
allGraphicsObjects.push(mergeGraphics(graphics, outline))
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const stackedGraphics = stackGraphicsVertically(allGraphicsObjects)
|
|
78
|
+
const bounds = getBounds(stackedGraphics)
|
|
79
|
+
const boundsWidth = Math.max(1, bounds.maxX - bounds.minX)
|
|
80
|
+
const boundsHeight = Math.max(1, bounds.maxY - bounds.minY)
|
|
81
|
+
const svgWidth = 640
|
|
82
|
+
const svgHeight = Math.max(
|
|
83
|
+
svgWidth,
|
|
84
|
+
Math.ceil((boundsHeight / boundsWidth) * svgWidth),
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
const svg = getSvgFromGraphicsObject(stackedGraphics, {
|
|
88
|
+
svgWidth,
|
|
89
|
+
svgHeight,
|
|
90
|
+
})
|
|
91
|
+
await expect(svg).toMatchSvgSnapshot(import.meta.path)
|
|
92
|
+
})
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
<svg width="640" height="1714" viewBox="0 0 640 1714" xmlns="http://www.w3.org/2000/svg"><rect width="100%" height="100%" fill="white"/><g><polyline data-points="-5,-5 5,-5 5,5 -5,5 -5,-5" data-type="line" data-label="bounds" points="40,773.6999999999999 600,773.6999999999999 600,213.69999999999993 40,213.69999999999993 40,773.6999999999999" fill="none" stroke="#111827" stroke-width="5.6000000000000005"/></g><g><polyline data-points="-5,-19.875 5,-19.875 5,-9.875 -5,-9.875 -5,-19.875" data-type="line" data-label="bounds" points="40,1606.6999999999998 600,1606.6999999999998 600,1046.6999999999998 40,1046.6999999999998 40,1606.6999999999998" fill="none" stroke="#111827" stroke-width="5.6000000000000005"/></g><g><rect data-type="rect" data-label="node" data-x="0" data-y="0.7999999999999998" x="241.6" y="213.69999999999993" width="156.79999999999998" height="470.4" fill="#dbeafe" stroke="black" stroke-width="0.017857142857142856"/></g><g><rect data-type="rect" data-label="node" data-x="-3.2" data-y="-2.8" x="40" y="527.3" width="201.6" height="246.39999999999998" fill="#dbeafe" stroke="black" stroke-width="0.017857142857142856"/></g><g><rect data-type="rect" data-label="node" data-x="-3.2" data-y="2.8" x="40" y="213.69999999999993" width="201.6" height="246.40000000000003" fill="#dbeafe" stroke="black" stroke-width="0.017857142857142856"/></g><g><rect data-type="rect" data-label="node" data-x="3.2" data-y="-2.8" x="398.40000000000003" y="527.3" width="201.59999999999997" height="246.39999999999998" fill="#dbeafe" stroke="black" stroke-width="0.017857142857142856"/></g><g><rect data-type="rect" data-label="node" data-x="3.525" data-y="1" x="434.79999999999995" y="415.29999999999995" width="165.20000000000005" height="44.799999999999955" fill="#dbeafe" stroke="black" stroke-width="0.017857142857142856"/></g><g><rect data-type="rect" data-label="node" data-x="-3.8" data-y="0" x="40" y="460.0999999999999" width="134.40000000000003" height="67.20000000000005" fill="#dbeafe" stroke="black" stroke-width="0.017857142857142856"/></g><g><rect data-type="rect" data-label="node" data-x="0" data-y="-4.2" x="241.60000000000002" y="684.0999999999999" width="156.79999999999995" height="89.60000000000002" fill="#dbeafe" stroke="black" stroke-width="0.017857142857142856"/></g><g><rect data-type="rect" data-label="node" data-x="3.8" data-y="3.2" x="465.59999999999997" y="213.69999999999993" width="134.40000000000003" height="201.60000000000002" fill="#dbeafe" stroke="black" stroke-width="0.017857142857142856"/></g><g><rect data-type="rect" data-label="node" data-x="2" data-y="3.8" x="398.40000000000003" y="213.69999999999993" width="67.19999999999993" height="134.40000000000003" fill="#dbeafe" stroke="black" stroke-width="0.017857142857142856"/></g><g><rect data-type="rect" data-label="node" data-x="3.8" data-y="0" x="465.59999999999997" y="460.0999999999999" width="134.40000000000003" height="67.20000000000005" fill="#dbeafe" stroke="black" stroke-width="0.017857142857142856"/></g><g><rect data-type="rect" data-label="node" data-x="1.725" data-y="1" x="398.4" y="415.29999999999995" width="36.400000000000034" height="44.799999999999955" fill="#dbeafe" stroke="black" stroke-width="0.017857142857142856"/></g><g><rect data-type="rect" data-label="node" data-x="-2" data-y="0" x="174.4" y="460.0999999999999" width="67.20000000000002" height="67.20000000000005" fill="red" stroke="black" stroke-width="0.017857142857142856"/></g><g><rect data-type="rect" data-label="node" data-x="1.9999999999999998" data-y="0" x="398.4" y="460.0999999999999" width="67.19999999999999" height="67.20000000000005" fill="red" stroke="black" stroke-width="0.017857142857142856"/></g><g><rect data-type="rect" data-label="node" data-x="1.9999999999999998" data-y="1.9999999999999998" x="398.4" y="348.09999999999997" width="67.19999999999999" height="67.19999999999999" fill="red" stroke="black" stroke-width="0.017857142857142856"/></g><g><rect data-type="rect" data-label="node" data-x="0" data-y="-14.075" x="241.6" y="1046.6999999999998" width="156.79999999999998" height="470.4000000000001" fill="#dbeafe" stroke="black" stroke-width="0.017857142857142856"/></g><g><rect data-type="rect" data-label="node" data-x="-3.2" data-y="-17.675" x="40" y="1360.3000000000002" width="201.6" height="246.39999999999964" fill="#dbeafe" stroke="black" stroke-width="0.017857142857142856"/></g><g><rect data-type="rect" data-label="node" data-x="-3.2" data-y="-12.075" x="40" y="1046.6999999999998" width="201.6" height="246.4000000000001" fill="#dbeafe" stroke="black" stroke-width="0.017857142857142856"/></g><g><rect data-type="rect" data-label="node" data-x="3.2" data-y="-17.675" x="398.40000000000003" y="1360.3000000000002" width="201.59999999999997" height="246.39999999999964" fill="#dbeafe" stroke="black" stroke-width="0.017857142857142856"/></g><g><rect data-type="rect" data-label="node" data-x="3.525" data-y="-13.875" x="434.79999999999995" y="1248.3" width="165.20000000000005" height="44.799999999999955" fill="#dbeafe" stroke="black" stroke-width="0.017857142857142856"/></g><g><rect data-type="rect" data-label="node" data-x="-3.8" data-y="-14.875" x="40" y="1293.1" width="134.40000000000003" height="67.20000000000005" fill="#dbeafe" stroke="black" stroke-width="0.017857142857142856"/></g><g><rect data-type="rect" data-label="node" data-x="0" data-y="-19.075" x="241.60000000000002" y="1517.1" width="156.79999999999995" height="89.59999999999991" fill="#dbeafe" stroke="black" stroke-width="0.017857142857142856"/></g><g><rect data-type="rect" data-label="node" data-x="3.8" data-y="-11.675" x="465.59999999999997" y="1046.6999999999998" width="134.40000000000003" height="201.60000000000036" fill="#dbeafe" stroke="black" stroke-width="0.017857142857142856"/></g><g><rect data-type="rect" data-label="node" data-x="2" data-y="-11.075" x="398.40000000000003" y="1046.6999999999998" width="67.19999999999993" height="134.4000000000001" fill="#dbeafe" stroke="black" stroke-width="0.017857142857142856"/></g><g><rect data-type="rect" data-label="node" data-x="3.8" data-y="-14.875" x="465.59999999999997" y="1293.1" width="134.40000000000003" height="67.20000000000005" fill="#dbeafe" stroke="black" stroke-width="0.017857142857142856"/></g><g><rect data-type="rect" data-label="node" data-x="1.725" data-y="-13.875" x="398.4" y="1248.3" width="36.400000000000034" height="44.799999999999955" fill="#dbeafe" stroke="black" stroke-width="0.017857142857142856"/></g><g><rect data-type="rect" data-label="node" data-x="-2" data-y="-14.875" x="174.4" y="1293.1" width="67.20000000000002" height="67.20000000000005" fill="#fef3c7" stroke="black" stroke-width="0.017857142857142856"/></g><g><rect data-type="rect" data-label="node" data-x="2" data-y="-12.875" x="398.4" y="1181.1" width="67.20000000000005" height="67.20000000000005" fill="#fef3c7" stroke="black" stroke-width="0.017857142857142856"/></g><g><rect data-type="rect" data-label="node" data-x="2" data-y="-14.875" x="398.4" y="1293.1" width="67.20000000000005" height="67.20000000000005" fill="#fef3c7" stroke="black" stroke-width="0.017857142857142856"/></g><text data-type="text" data-label="Layer z=0" data-x="0" data-y="6.3999999999999995" x="320" y="135.29999999999995" fill="black" font-size="28" font-family="sans-serif" text-anchor="end" dominant-baseline="text-before-edge">Layer z=0</text><text data-type="text" data-label="Layer z=1" data-x="0" data-y="-8.475000000000001" x="320" y="968.3" fill="black" font-size="28" font-family="sans-serif" text-anchor="end" dominant-baseline="text-before-edge">Layer z=1</text><g id="crosshair" style="display: none"><line id="crosshair-h" y1="0" y2="1714" stroke="#666" stroke-width="0.5"/><line id="crosshair-v" x1="0" x2="640" stroke="#666" stroke-width="0.5"/><text id="coordinates" font-family="monospace" font-size="12" fill="#666"></text></g><script><![CDATA[
|
|
2
|
+
document.currentScript.parentElement.addEventListener('mousemove', (e) => {
|
|
3
|
+
const svg = e.currentTarget;
|
|
4
|
+
const rect = svg.getBoundingClientRect();
|
|
5
|
+
const x = e.clientX - rect.left;
|
|
6
|
+
const y = e.clientY - rect.top;
|
|
7
|
+
const crosshair = svg.getElementById('crosshair');
|
|
8
|
+
const h = svg.getElementById('crosshair-h');
|
|
9
|
+
const v = svg.getElementById('crosshair-v');
|
|
10
|
+
const coords = svg.getElementById('coordinates');
|
|
11
|
+
|
|
12
|
+
crosshair.style.display = 'block';
|
|
13
|
+
h.setAttribute('x1', '0');
|
|
14
|
+
h.setAttribute('x2', '640');
|
|
15
|
+
h.setAttribute('y1', y);
|
|
16
|
+
h.setAttribute('y2', y);
|
|
17
|
+
v.setAttribute('x1', x);
|
|
18
|
+
v.setAttribute('x2', x);
|
|
19
|
+
v.setAttribute('y1', '0');
|
|
20
|
+
v.setAttribute('y2', '1714');
|
|
21
|
+
|
|
22
|
+
// Calculate real coordinates using inverse transformation
|
|
23
|
+
const matrix = {"a":56,"c":0,"e":320,"b":0,"d":-56,"f":493.69999999999993};
|
|
24
|
+
// Manually invert and apply the affine transform
|
|
25
|
+
// Since we only use translate and scale, we can directly compute:
|
|
26
|
+
// x' = (x - tx) / sx
|
|
27
|
+
// y' = (y - ty) / sy
|
|
28
|
+
const sx = matrix.a;
|
|
29
|
+
const sy = matrix.d;
|
|
30
|
+
const tx = matrix.e;
|
|
31
|
+
const ty = matrix.f;
|
|
32
|
+
const realPoint = {
|
|
33
|
+
x: (x - tx) / sx,
|
|
34
|
+
y: (y - ty) / sy // Flip y back since we used negative scale
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
coords.textContent = `(${realPoint.x.toFixed(2)}, ${realPoint.y.toFixed(2)})`;
|
|
38
|
+
coords.setAttribute('x', (x + 5).toString());
|
|
39
|
+
coords.setAttribute('y', (y - 5).toString());
|
|
40
|
+
});
|
|
41
|
+
document.currentScript.parentElement.addEventListener('mouseleave', () => {
|
|
42
|
+
document.currentScript.parentElement.getElementById('crosshair').style.display = 'none';
|
|
43
|
+
});
|
|
44
|
+
]]></script></svg>
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
{
|
|
2
|
+
"bounds": {
|
|
3
|
+
"minX": -5,
|
|
4
|
+
"maxX": 5,
|
|
5
|
+
"minY": -5,
|
|
6
|
+
"maxY": 5
|
|
7
|
+
},
|
|
8
|
+
"obstacles": [
|
|
9
|
+
{
|
|
10
|
+
"type": "oval",
|
|
11
|
+
"layers": ["top"],
|
|
12
|
+
"center": {
|
|
13
|
+
"x": -2,
|
|
14
|
+
"y": 0
|
|
15
|
+
},
|
|
16
|
+
"width": 1.2,
|
|
17
|
+
"height": 1.2,
|
|
18
|
+
"connectedTo": [
|
|
19
|
+
"pcb_smtpad_0",
|
|
20
|
+
"connectivity_net3",
|
|
21
|
+
"source_trace_1",
|
|
22
|
+
"source_trace_0",
|
|
23
|
+
"source_port_0",
|
|
24
|
+
"source_port_1",
|
|
25
|
+
"source_port_2",
|
|
26
|
+
"pcb_smtpad_0",
|
|
27
|
+
"pcb_port_0",
|
|
28
|
+
"pcb_smtpad_1",
|
|
29
|
+
"pcb_port_1",
|
|
30
|
+
"pcb_smtpad_2",
|
|
31
|
+
"pcb_port_2"
|
|
32
|
+
]
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"type": "oval",
|
|
36
|
+
"layers": ["top"],
|
|
37
|
+
"center": {
|
|
38
|
+
"x": 2,
|
|
39
|
+
"y": 0
|
|
40
|
+
},
|
|
41
|
+
"width": 1.2,
|
|
42
|
+
"height": 1.2,
|
|
43
|
+
"connectedTo": [
|
|
44
|
+
"pcb_smtpad_1",
|
|
45
|
+
"connectivity_net3",
|
|
46
|
+
"source_trace_1",
|
|
47
|
+
"source_trace_0",
|
|
48
|
+
"source_port_0",
|
|
49
|
+
"source_port_1",
|
|
50
|
+
"source_port_2",
|
|
51
|
+
"pcb_smtpad_0",
|
|
52
|
+
"pcb_port_0",
|
|
53
|
+
"pcb_smtpad_1",
|
|
54
|
+
"pcb_port_1",
|
|
55
|
+
"pcb_smtpad_2",
|
|
56
|
+
"pcb_port_2"
|
|
57
|
+
]
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"type": "oval",
|
|
61
|
+
"layers": ["top"],
|
|
62
|
+
"center": {
|
|
63
|
+
"x": 2,
|
|
64
|
+
"y": 2
|
|
65
|
+
},
|
|
66
|
+
"width": 1.2,
|
|
67
|
+
"height": 1.2,
|
|
68
|
+
"connectedTo": [
|
|
69
|
+
"pcb_smtpad_2",
|
|
70
|
+
"connectivity_net3",
|
|
71
|
+
"source_trace_1",
|
|
72
|
+
"source_trace_0",
|
|
73
|
+
"source_port_0",
|
|
74
|
+
"source_port_1",
|
|
75
|
+
"source_port_2",
|
|
76
|
+
"pcb_smtpad_0",
|
|
77
|
+
"pcb_port_0",
|
|
78
|
+
"pcb_smtpad_1",
|
|
79
|
+
"pcb_port_1",
|
|
80
|
+
"pcb_smtpad_2",
|
|
81
|
+
"pcb_port_2"
|
|
82
|
+
]
|
|
83
|
+
}
|
|
84
|
+
],
|
|
85
|
+
"connections": [
|
|
86
|
+
{
|
|
87
|
+
"name": "source_trace_0",
|
|
88
|
+
"source_trace_id": "source_trace_0",
|
|
89
|
+
"pointsToConnect": [
|
|
90
|
+
{
|
|
91
|
+
"x": -2,
|
|
92
|
+
"y": 0,
|
|
93
|
+
"layer": "top",
|
|
94
|
+
"pointId": "pcb_port_0",
|
|
95
|
+
"pcb_port_id": "pcb_port_0"
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
"x": 2,
|
|
99
|
+
"y": 0,
|
|
100
|
+
"layer": "top",
|
|
101
|
+
"pointId": "pcb_port_1",
|
|
102
|
+
"pcb_port_id": "pcb_port_1"
|
|
103
|
+
}
|
|
104
|
+
]
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
"name": "source_trace_1",
|
|
108
|
+
"source_trace_id": "source_trace_1",
|
|
109
|
+
"pointsToConnect": [
|
|
110
|
+
{
|
|
111
|
+
"x": 2,
|
|
112
|
+
"y": 0,
|
|
113
|
+
"layer": "top",
|
|
114
|
+
"pointId": "pcb_port_1",
|
|
115
|
+
"pcb_port_id": "pcb_port_1"
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
"x": 2,
|
|
119
|
+
"y": 2,
|
|
120
|
+
"layer": "top",
|
|
121
|
+
"pointId": "pcb_port_2",
|
|
122
|
+
"pcb_port_id": "pcb_port_2"
|
|
123
|
+
}
|
|
124
|
+
]
|
|
125
|
+
}
|
|
126
|
+
],
|
|
127
|
+
"layerCount": 2,
|
|
128
|
+
"minTraceWidth": 0.15
|
|
129
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
|
+
import srj from "./pcb_trace_id-should-return-root-connection-name.srj.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("pcb_trace_id-should-return-root-connection-name", async () => {
|
|
16
|
+
const solver = new RectDiffPipeline({
|
|
17
|
+
simpleRouteJson: srj,
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
const outline = makeSimpleRouteOutlineGraphics(srj)
|
|
21
|
+
|
|
22
|
+
solver.solve()
|
|
23
|
+
|
|
24
|
+
const { meshNodes } = solver.getOutput()
|
|
25
|
+
const rectsByCombo = makeCapacityMeshNodeWithLayerInfo(meshNodes)
|
|
26
|
+
const allGraphicsObjects: GraphicsObject[] = []
|
|
27
|
+
|
|
28
|
+
// Generate a snapshot for each z-layer
|
|
29
|
+
for (const z of Array.from({ length: srj.layerCount }, (_, index) => index)) {
|
|
30
|
+
const layerRects: Rect[] = []
|
|
31
|
+
|
|
32
|
+
for (const [key, rects] of rectsByCombo) {
|
|
33
|
+
const layers = key
|
|
34
|
+
.split(",")
|
|
35
|
+
.map((value) => Number.parseInt(value, 10))
|
|
36
|
+
.filter((value) => !Number.isNaN(value))
|
|
37
|
+
|
|
38
|
+
if (layers.includes(z)) {
|
|
39
|
+
layerRects.push(...rects)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
let labelY = 0
|
|
44
|
+
|
|
45
|
+
if (layerRects.length > 0) {
|
|
46
|
+
let maxY = -Infinity
|
|
47
|
+
|
|
48
|
+
for (const rect of layerRects) {
|
|
49
|
+
const top = rect.center.y + rect.height * (2 / 3)
|
|
50
|
+
|
|
51
|
+
if (top > maxY) maxY = top
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
labelY = maxY
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const graphics: GraphicsObject = {
|
|
58
|
+
title: `RectDiffPipeline - z${z}`,
|
|
59
|
+
texts: [
|
|
60
|
+
{
|
|
61
|
+
anchorSide: "top_right",
|
|
62
|
+
text: `Layer z=${z}`,
|
|
63
|
+
x: 0,
|
|
64
|
+
y: labelY,
|
|
65
|
+
fontSize: 0.5,
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
coordinateSystem: "cartesian",
|
|
69
|
+
rects: layerRects,
|
|
70
|
+
points: [],
|
|
71
|
+
lines: [],
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
allGraphicsObjects.push(mergeGraphics(graphics, outline))
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const stackedGraphics = stackGraphicsVertically(allGraphicsObjects)
|
|
78
|
+
const bounds = getBounds(stackedGraphics)
|
|
79
|
+
const boundsWidth = Math.max(1, bounds.maxX - bounds.minX)
|
|
80
|
+
const boundsHeight = Math.max(1, bounds.maxY - bounds.minY)
|
|
81
|
+
const svgWidth = 640
|
|
82
|
+
const svgHeight = Math.max(
|
|
83
|
+
svgWidth,
|
|
84
|
+
Math.ceil((boundsHeight / boundsWidth) * svgWidth),
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
const svg = getSvgFromGraphicsObject(stackedGraphics, {
|
|
88
|
+
svgWidth,
|
|
89
|
+
svgHeight,
|
|
90
|
+
})
|
|
91
|
+
await expect(svg).toMatchSvgSnapshot(import.meta.path)
|
|
92
|
+
})
|