@tscircuit/rectdiff 0.0.20 → 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/package.json +1 -1
- 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,93 @@
|
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
|
+
import srj_json from "./bugreport19.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
|
+
const srj = srj_json.simple_route_json ?? srj_json.simpleRouteJson ?? srj_json
|
|
16
|
+
|
|
17
|
+
test("bugreport19", async () => {
|
|
18
|
+
const solver = new RectDiffPipeline({
|
|
19
|
+
simpleRouteJson: srj,
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
const outline = makeSimpleRouteOutlineGraphics(srj)
|
|
23
|
+
|
|
24
|
+
solver.solve()
|
|
25
|
+
|
|
26
|
+
const { meshNodes } = solver.getOutput()
|
|
27
|
+
const rectsByCombo = makeCapacityMeshNodeWithLayerInfo(meshNodes)
|
|
28
|
+
const allGraphicsObjects: GraphicsObject[] = []
|
|
29
|
+
|
|
30
|
+
for (const z of Array.from({ length: srj.layerCount }, (_, index) => index)) {
|
|
31
|
+
const layerRects: Rect[] = []
|
|
32
|
+
|
|
33
|
+
for (const [key, rects] of rectsByCombo) {
|
|
34
|
+
const layers = key
|
|
35
|
+
.split(",")
|
|
36
|
+
.map((value) => Number.parseInt(value, 10))
|
|
37
|
+
.filter((value) => !Number.isNaN(value))
|
|
38
|
+
|
|
39
|
+
if (layers.includes(z)) {
|
|
40
|
+
layerRects.push(...rects)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
let labelY = 0
|
|
45
|
+
|
|
46
|
+
if (layerRects.length > 0) {
|
|
47
|
+
let maxY = -Infinity
|
|
48
|
+
|
|
49
|
+
for (const rect of layerRects) {
|
|
50
|
+
const top = rect.center.y + rect.height * (2 / 3)
|
|
51
|
+
|
|
52
|
+
if (top > maxY) maxY = top
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
labelY = maxY
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const graphics: GraphicsObject = {
|
|
59
|
+
title: `RectDiffPipeline - z${z}`,
|
|
60
|
+
texts: [
|
|
61
|
+
{
|
|
62
|
+
anchorSide: "top_right",
|
|
63
|
+
text: `Layer z=${z}`,
|
|
64
|
+
x: 0,
|
|
65
|
+
y: labelY,
|
|
66
|
+
fontSize: 0.5,
|
|
67
|
+
},
|
|
68
|
+
],
|
|
69
|
+
coordinateSystem: "cartesian",
|
|
70
|
+
rects: layerRects,
|
|
71
|
+
points: [],
|
|
72
|
+
lines: [],
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
allGraphicsObjects.push(mergeGraphics(graphics, outline))
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const stackedGraphics = stackGraphicsVertically(allGraphicsObjects)
|
|
79
|
+
const bounds = getBounds(stackedGraphics)
|
|
80
|
+
const boundsWidth = Math.max(1, bounds.maxX - bounds.minX)
|
|
81
|
+
const boundsHeight = Math.max(1, bounds.maxY - bounds.minY)
|
|
82
|
+
const svgWidth = 640
|
|
83
|
+
const svgHeight = Math.max(
|
|
84
|
+
svgWidth,
|
|
85
|
+
Math.ceil((boundsHeight / boundsWidth) * svgWidth),
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
const svg = getSvgFromGraphicsObject(stackedGraphics, {
|
|
89
|
+
svgWidth,
|
|
90
|
+
svgHeight,
|
|
91
|
+
})
|
|
92
|
+
await expect(svg).toMatchSvgSnapshot(import.meta.path)
|
|
93
|
+
})
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
<svg width="640" height="1600" viewBox="0 0 640 1600" xmlns="http://www.w3.org/2000/svg"><rect width="100%" height="100%" fill="white"/><g><polyline data-points="-10,-10 10,-10 10,10 -10,10 -10,-10" data-type="line" data-label="bounds" points="40,722.2299999999999 600,722.2299999999999 600,162.2299999999999 40,162.2299999999999 40,722.2299999999999" fill="none" stroke="#111827" stroke-width="2.8000000000000003"/></g><g><polyline data-points="-10,-37.775 10,-37.775 10,-17.775 -10,-17.775 -10,-37.775" data-type="line" data-label="bounds" points="40,1499.9299999999998 600,1499.9299999999998 600,939.9299999999998 40,939.9299999999998 40,1499.9299999999998" fill="none" stroke="#111827" stroke-width="2.8000000000000003"/></g><g><rect data-type="rect" data-label="node" data-x="0" data-y="-5.16" x="40" y="451.18999999999994" width="560" height="271.03999999999996" fill="#dbeafe" stroke="black" stroke-width="0.03571428571428571"/></g><g><rect data-type="rect" data-label="node" data-x="-5.39" data-y="4.84" x="40" y="162.2299999999999" width="258.16" height="288.96000000000004" fill="#dbeafe" stroke="black" stroke-width="0.03571428571428571"/></g><g><rect data-type="rect" data-label="node" data-x="4.61" data-y="5.16" x="298.16" y="162.2299999999999" width="301.84" height="271.03999999999996" fill="#dbeafe" stroke="black" stroke-width="0.03571428571428571"/></g><g><rect data-type="rect" data-label="node" data-x="3.1800000000000006" data-y="-1.1102230246251565e-16" x="379.92" y="433.2699999999999" width="58.24000000000001" height="17.920000000000016" fill="#dbeafe" stroke="black" stroke-width="0.03571428571428571"/></g><g><rect data-type="rect" data-label="node" data-x="1.46" data-y="-1.1102230246251565e-16" x="341.84" y="433.2699999999999" width="38.08000000000004" height="17.920000000000016" fill="#dbeafe" stroke="black" stroke-width="0.03571428571428571"/></g><g><rect data-type="rect" data-label="node" data-x="6.93" data-y="-1.1102230246251565e-16" x="481.84" y="433.2699999999999" width="64.40000000000003" height="17.920000000000016" fill="#dbeafe" stroke="black" stroke-width="0.03571428571428571"/></g><g><rect data-type="rect" data-label="node" data-x="9.040000000000001" data-y="-1.1102230246251565e-16" x="546.24" y="433.2699999999999" width="53.75999999999999" height="17.920000000000016" fill="#dbeafe" stroke="black" stroke-width="0.03571428571428571"/></g><g><rect data-type="rect" data-label="node" data-x="0" data-y="-1.1102230246251565e-16" x="313.28" y="433.2699999999999" width="13.440000000000055" height="17.920000000000016" fill="#dbeafe" stroke="black" stroke-width="0.03571428571428571"/></g><g><rect data-type="rect" data-label="node" data-x="5" data-y="-1.1102230246251565e-16" x="453.28" y="433.2699999999999" width="13.440000000000055" height="17.920000000000016" fill="#dbeafe" stroke="black" stroke-width="0.03571428571428571"/></g><g><rect data-type="rect" data-label="node" data-x="-0.51" data-y="0" x="298.16" y="433.2699999999999" width="15.119999999999948" height="17.91999999999996" fill="red" stroke="black" stroke-width="0.03571428571428571"/></g><g><rect data-type="rect" data-label="node" data-x="0.51" data-y="0" x="326.72" y="433.2699999999999" width="15.119999999999948" height="17.91999999999996" fill="red" stroke="black" stroke-width="0.03571428571428571"/></g><g><rect data-type="rect" data-label="node" data-x="4.49" data-y="0" x="438.16" y="433.2699999999999" width="15.119999999999948" height="17.91999999999996" fill="red" stroke="black" stroke-width="0.03571428571428571"/></g><g><rect data-type="rect" data-label="node" data-x="5.51" data-y="0" x="466.72" y="433.2699999999999" width="15.119999999999948" height="17.91999999999996" fill="red" stroke="black" stroke-width="0.03571428571428571"/></g><g><rect data-type="rect" data-label="node" data-x="0" data-y="-32.935" x="40" y="1228.8899999999999" width="560" height="271.0400000000004" fill="#dbeafe" stroke="black" stroke-width="0.03571428571428571"/></g><g><rect data-type="rect" data-label="node" data-x="-5.39" data-y="-22.935" x="40" y="939.9299999999998" width="258.16" height="288.96000000000004" fill="#dbeafe" stroke="black" stroke-width="0.03571428571428571"/></g><g><rect data-type="rect" data-label="node" data-x="4.61" data-y="-22.615" x="298.16" y="939.9299999999998" width="301.84" height="271.03999999999996" fill="#dbeafe" stroke="black" stroke-width="0.03571428571428571"/></g><g><rect data-type="rect" data-label="node" data-x="3.1800000000000006" data-y="-27.775" x="379.92" y="1210.9699999999998" width="58.24000000000001" height="17.920000000000073" fill="#dbeafe" stroke="black" stroke-width="0.03571428571428571"/></g><g><rect data-type="rect" data-label="node" data-x="1.46" data-y="-27.775" x="341.84" y="1210.9699999999998" width="38.08000000000004" height="17.920000000000073" fill="#dbeafe" stroke="black" stroke-width="0.03571428571428571"/></g><g><rect data-type="rect" data-label="node" data-x="6.93" data-y="-27.775" x="481.84" y="1210.9699999999998" width="64.40000000000003" height="17.920000000000073" fill="#dbeafe" stroke="black" stroke-width="0.03571428571428571"/></g><g><rect data-type="rect" data-label="node" data-x="9.040000000000001" data-y="-27.775" x="546.24" y="1210.9699999999998" width="53.75999999999999" height="17.920000000000073" fill="#dbeafe" stroke="black" stroke-width="0.03571428571428571"/></g><g><rect data-type="rect" data-label="node" data-x="3.3306690738754696e-16" data-y="-27.775" x="298.16" y="1210.9699999999998" width="43.67999999999995" height="17.920000000000073" fill="#fef3c7" stroke="black" stroke-width="0.03571428571428571"/></g><g><rect data-type="rect" data-label="node" data-x="5" data-y="-27.775" x="438.16" y="1210.9699999999998" width="43.67999999999995" height="17.920000000000073" fill="#fef3c7" stroke="black" stroke-width="0.03571428571428571"/></g><text data-type="text" data-label="Layer z=0" data-x="0" data-y="11.719999999999999" x="320" y="114.06999999999994" fill="black" font-size="14" 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="-16.055" x="320" y="891.7699999999999" fill="black" font-size="14" 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="1600" 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', '1600');
|
|
21
|
+
|
|
22
|
+
// Calculate real coordinates using inverse transformation
|
|
23
|
+
const matrix = {"a":28,"c":0,"e":320,"b":0,"d":-28,"f":442.2299999999999};
|
|
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,109 @@
|
|
|
1
|
+
{
|
|
2
|
+
"bounds": {
|
|
3
|
+
"minX": -10,
|
|
4
|
+
"maxX": 10,
|
|
5
|
+
"minY": -10,
|
|
6
|
+
"maxY": 10
|
|
7
|
+
},
|
|
8
|
+
"obstacles": [
|
|
9
|
+
{
|
|
10
|
+
"type": "rect",
|
|
11
|
+
"layers": ["top"],
|
|
12
|
+
"center": {
|
|
13
|
+
"x": -0.51,
|
|
14
|
+
"y": 0
|
|
15
|
+
},
|
|
16
|
+
"width": 0.54,
|
|
17
|
+
"height": 0.64,
|
|
18
|
+
"connectedTo": [
|
|
19
|
+
"pcb_smtpad_0",
|
|
20
|
+
"connectivity_net11",
|
|
21
|
+
"source_port_0",
|
|
22
|
+
"pcb_smtpad_0",
|
|
23
|
+
"pcb_port_0"
|
|
24
|
+
],
|
|
25
|
+
"zLayers": [0]
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"type": "rect",
|
|
29
|
+
"layers": ["top"],
|
|
30
|
+
"center": {
|
|
31
|
+
"x": 0.51,
|
|
32
|
+
"y": 0
|
|
33
|
+
},
|
|
34
|
+
"width": 0.54,
|
|
35
|
+
"height": 0.64,
|
|
36
|
+
"connectedTo": [
|
|
37
|
+
"pcb_smtpad_1",
|
|
38
|
+
"connectivity_net12",
|
|
39
|
+
"source_port_1",
|
|
40
|
+
"pcb_smtpad_1",
|
|
41
|
+
"pcb_port_1"
|
|
42
|
+
],
|
|
43
|
+
"zLayers": [0]
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"type": "rect",
|
|
47
|
+
"layers": ["top"],
|
|
48
|
+
"center": {
|
|
49
|
+
"x": 4.49,
|
|
50
|
+
"y": 0
|
|
51
|
+
},
|
|
52
|
+
"width": 0.54,
|
|
53
|
+
"height": 0.64,
|
|
54
|
+
"connectedTo": [
|
|
55
|
+
"pcb_smtpad_2",
|
|
56
|
+
"connectivity_net0",
|
|
57
|
+
"source_trace_0",
|
|
58
|
+
"source_port_3",
|
|
59
|
+
"source_port_2",
|
|
60
|
+
"pcb_port_2",
|
|
61
|
+
"pcb_smtpad_2",
|
|
62
|
+
"pcb_port_3"
|
|
63
|
+
],
|
|
64
|
+
"zLayers": [0]
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"type": "rect",
|
|
68
|
+
"layers": ["top"],
|
|
69
|
+
"center": {
|
|
70
|
+
"x": 5.51,
|
|
71
|
+
"y": 0
|
|
72
|
+
},
|
|
73
|
+
"width": 0.54,
|
|
74
|
+
"height": 0.64,
|
|
75
|
+
"connectedTo": [
|
|
76
|
+
"pcb_smtpad_3",
|
|
77
|
+
"connectivity_net14",
|
|
78
|
+
"source_port_4",
|
|
79
|
+
"pcb_smtpad_3",
|
|
80
|
+
"pcb_port_4"
|
|
81
|
+
],
|
|
82
|
+
"zLayers": [0]
|
|
83
|
+
}
|
|
84
|
+
],
|
|
85
|
+
"connections": [
|
|
86
|
+
{
|
|
87
|
+
"name": "source_trace_0",
|
|
88
|
+
"source_trace_id": "source_trace_0",
|
|
89
|
+
"pointsToConnect": [
|
|
90
|
+
{
|
|
91
|
+
"x": 4.49,
|
|
92
|
+
"y": 0,
|
|
93
|
+
"layer": "top",
|
|
94
|
+
"pointId": "pcb_port_3",
|
|
95
|
+
"pcb_port_id": "pcb_port_3"
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
"x": -0.51,
|
|
99
|
+
"y": 0,
|
|
100
|
+
"layer": "top",
|
|
101
|
+
"pointId": "pcb_port_2",
|
|
102
|
+
"pcb_port_id": "pcb_port_2"
|
|
103
|
+
}
|
|
104
|
+
]
|
|
105
|
+
}
|
|
106
|
+
],
|
|
107
|
+
"layerCount": 2,
|
|
108
|
+
"minTraceWidth": 0.15
|
|
109
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
|
+
import srj_json from "./bugreport20-obstacle-clipping.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
|
+
const srj = srj_json.simple_route_json ?? srj_json.simpleRouteJson ?? srj_json
|
|
16
|
+
|
|
17
|
+
test("bugreport20-obstacle-clipping", async () => {
|
|
18
|
+
const solver = new RectDiffPipeline({
|
|
19
|
+
simpleRouteJson: srj,
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
const outline = makeSimpleRouteOutlineGraphics(srj)
|
|
23
|
+
|
|
24
|
+
solver.solve()
|
|
25
|
+
|
|
26
|
+
const { meshNodes } = solver.getOutput()
|
|
27
|
+
const rectsByCombo = makeCapacityMeshNodeWithLayerInfo(meshNodes)
|
|
28
|
+
const allGraphicsObjects: GraphicsObject[] = []
|
|
29
|
+
|
|
30
|
+
for (const z of Array.from({ length: srj.layerCount }, (_, index) => index)) {
|
|
31
|
+
const layerRects: Rect[] = []
|
|
32
|
+
|
|
33
|
+
for (const [key, rects] of rectsByCombo) {
|
|
34
|
+
const layers = key
|
|
35
|
+
.split(",")
|
|
36
|
+
.map((value) => Number.parseInt(value, 10))
|
|
37
|
+
.filter((value) => !Number.isNaN(value))
|
|
38
|
+
|
|
39
|
+
if (layers.includes(z)) {
|
|
40
|
+
layerRects.push(...rects)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
let labelY = 0
|
|
45
|
+
|
|
46
|
+
if (layerRects.length > 0) {
|
|
47
|
+
let maxY = -Infinity
|
|
48
|
+
|
|
49
|
+
for (const rect of layerRects) {
|
|
50
|
+
const top = rect.center.y + rect.height * (2 / 3)
|
|
51
|
+
|
|
52
|
+
if (top > maxY) maxY = top
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
labelY = maxY
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const graphics: GraphicsObject = {
|
|
59
|
+
title: `RectDiffPipeline - z${z}`,
|
|
60
|
+
texts: [
|
|
61
|
+
{
|
|
62
|
+
anchorSide: "top_right",
|
|
63
|
+
text: `Layer z=${z}`,
|
|
64
|
+
x: 0,
|
|
65
|
+
y: labelY,
|
|
66
|
+
fontSize: 0.5,
|
|
67
|
+
},
|
|
68
|
+
],
|
|
69
|
+
coordinateSystem: "cartesian",
|
|
70
|
+
rects: layerRects,
|
|
71
|
+
points: [],
|
|
72
|
+
lines: [],
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
allGraphicsObjects.push(mergeGraphics(graphics, outline))
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const stackedGraphics = stackGraphicsVertically(allGraphicsObjects)
|
|
79
|
+
const bounds = getBounds(stackedGraphics)
|
|
80
|
+
const boundsWidth = Math.max(1, bounds.maxX - bounds.minX)
|
|
81
|
+
const boundsHeight = Math.max(1, bounds.maxY - bounds.minY)
|
|
82
|
+
const svgWidth = 640
|
|
83
|
+
const svgHeight = Math.max(
|
|
84
|
+
svgWidth,
|
|
85
|
+
Math.ceil((boundsHeight / boundsWidth) * svgWidth),
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
const svg = getSvgFromGraphicsObject(stackedGraphics, {
|
|
89
|
+
svgWidth,
|
|
90
|
+
svgHeight,
|
|
91
|
+
})
|
|
92
|
+
await expect(svg).toMatchSvgSnapshot(import.meta.path)
|
|
93
|
+
})
|
package/tests/solver/bugreport21-board-outline/__snapshots__/bugreport21-board-outline.snap.svg
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
<svg width="640" height="1271" viewBox="0 0 640 1271" xmlns="http://www.w3.org/2000/svg"><rect width="100%" height="100%" fill="white"/><g><polyline data-points="-8,-6 -2,-6 -2,2 2,2 2,-6 8,-6 8,6 -8,6 -8,-6" data-type="line" data-label="outline" points="40,573.7541666666666 250,573.7541666666666 250,293.7541666666666 390,293.7541666666666 390,573.7541666666666 600,573.7541666666666 600,153.7541666666666 40,153.7541666666666 40,573.7541666666666" fill="none" stroke="#111827" stroke-width="3.5"/></g><g><polyline data-points="-8,-23.64166666666667 -2,-23.64166666666667 -2,-15.64166666666667 2,-15.64166666666667 2,-23.64166666666667 8,-23.64166666666667 8,-11.64166666666667 -8,-11.64166666666667 -8,-23.64166666666667" data-type="line" data-label="outline" points="40,1191.2125 250,1191.2125 250,911.2125 390,911.2125 390,1191.2125 600,1191.2125 600,771.2125000000001 40,771.2125000000001 40,1191.2125" fill="none" stroke="#111827" stroke-width="3.5"/></g><g><rect data-type="rect" data-label="node" data-x="-5" data-y="1.1600000000000008" x="40" y="153.75416666666655" width="210" height="338.8" fill="#dbeafe" stroke="black" stroke-width="0.02857142857142857"/></g><g><rect data-type="rect" data-label="node" data-x="5" data-y="1.1600000000000008" x="390" y="153.75416666666655" width="210" height="338.8" fill="#dbeafe" stroke="black" stroke-width="0.02857142857142857"/></g><g><rect data-type="rect" data-label="node" data-x="0" data-y="4" x="250" y="153.7541666666666" width="140" height="140" fill="#dbeafe" stroke="black" stroke-width="0.02857142857142857"/></g><g><rect data-type="rect" data-label="node" data-x="-5.48" data-y="-5.16" x="40" y="514.9541666666667" width="176.39999999999998" height="58.799999999999955" fill="#dbeafe" stroke="black" stroke-width="0.02857142857142857"/></g><g><rect data-type="rect" data-label="node" data-x="5.48" data-y="-5.16" x="423.6" y="514.9541666666667" width="176.39999999999998" height="58.799999999999955" fill="#dbeafe" stroke="black" stroke-width="0.02857142857142857"/></g><g><rect data-type="rect" data-label="node" data-x="-2.4800000000000004" data-y="-4.84" x="216.39999999999998" y="492.55416666666656" width="33.60000000000002" height="81.20000000000005" fill="#dbeafe" stroke="black" stroke-width="0.02857142857142857"/></g><g><rect data-type="rect" data-label="node" data-x="2.4800000000000004" data-y="-4.84" x="390" y="492.55416666666656" width="33.60000000000002" height="81.20000000000005" fill="#dbeafe" stroke="black" stroke-width="0.02857142857142857"/></g><g><rect data-type="rect" data-label="node" data-x="6.890000000000001" data-y="-4" x="522.3000000000001" y="492.55416666666656" width="77.69999999999993" height="22.40000000000009" fill="#dbeafe" stroke="black" stroke-width="0.02857142857142857"/></g><g><rect data-type="rect" data-label="node" data-x="-6.89" data-y="-4" x="40" y="492.55416666666656" width="77.70000000000002" height="22.40000000000009" fill="#dbeafe" stroke="black" stroke-width="0.02857142857142857"/></g><g><rect data-type="rect" data-label="node" data-x="-5" data-y="-4" x="136.6" y="492.55416666666656" width="16.80000000000001" height="22.40000000000009" fill="#dbeafe" stroke="black" stroke-width="0.02857142857142857"/></g><g><rect data-type="rect" data-label="node" data-x="-3.5900000000000003" data-y="-4" x="172.3" y="492.55416666666656" width="44.099999999999966" height="22.40000000000009" fill="#dbeafe" stroke="black" stroke-width="0.02857142857142857"/></g><g><rect data-type="rect" data-label="node" data-x="3.5900000000000007" data-y="-4" x="423.6" y="492.55416666666656" width="44.10000000000002" height="22.40000000000009" fill="#dbeafe" stroke="black" stroke-width="0.02857142857142857"/></g><g><rect data-type="rect" data-label="node" data-x="5" data-y="-4" x="486.6" y="492.55416666666656" width="16.799999999999955" height="22.40000000000009" fill="#dbeafe" stroke="black" stroke-width="0.02857142857142857"/></g><g><rect data-type="rect" data-label="node" data-x="-5.51" data-y="-4" x="117.70000000000002" y="492.55416666666656" width="18.899999999999977" height="22.40000000000009" fill="red" stroke="black" stroke-width="0.02857142857142857"/></g><g><rect data-type="rect" data-label="node" data-x="-4.49" data-y="-4" x="153.4" y="492.55416666666656" width="18.899999999999977" height="22.40000000000009" fill="red" stroke="black" stroke-width="0.02857142857142857"/></g><g><rect data-type="rect" data-label="node" data-x="4.49" data-y="-4" x="467.70000000000005" y="492.55416666666656" width="18.899999999999977" height="22.40000000000009" fill="red" stroke="black" stroke-width="0.02857142857142857"/></g><g><rect data-type="rect" data-label="node" data-x="5.51" data-y="-4" x="503.4" y="492.55416666666656" width="18.899999999999977" height="22.40000000000009" fill="red" stroke="black" stroke-width="0.02857142857142857"/></g><g><rect data-type="rect" data-label="node" data-x="-5" data-y="-16.48166666666667" x="40" y="771.2125000000001" width="210" height="338.79999999999995" fill="#dbeafe" stroke="black" stroke-width="0.02857142857142857"/></g><g><rect data-type="rect" data-label="node" data-x="5" data-y="-16.48166666666667" x="390" y="771.2125000000001" width="210" height="338.79999999999995" fill="#dbeafe" stroke="black" stroke-width="0.02857142857142857"/></g><g><rect data-type="rect" data-label="node" data-x="0" data-y="-13.64166666666667" x="250" y="771.2125000000001" width="140" height="139.9999999999999" fill="#dbeafe" stroke="black" stroke-width="0.02857142857142857"/></g><g><rect data-type="rect" data-label="node" data-x="-5.48" data-y="-22.80166666666667" x="40" y="1132.4125" width="176.39999999999998" height="58.80000000000018" fill="#dbeafe" stroke="black" stroke-width="0.02857142857142857"/></g><g><rect data-type="rect" data-label="node" data-x="5.48" data-y="-22.80166666666667" x="423.6" y="1132.4125" width="176.39999999999998" height="58.80000000000018" fill="#dbeafe" stroke="black" stroke-width="0.02857142857142857"/></g><g><rect data-type="rect" data-label="node" data-x="-2.4800000000000004" data-y="-22.48166666666667" x="216.39999999999998" y="1110.0125" width="33.60000000000002" height="81.20000000000005" fill="#dbeafe" stroke="black" stroke-width="0.02857142857142857"/></g><g><rect data-type="rect" data-label="node" data-x="2.4800000000000004" data-y="-22.48166666666667" x="390" y="1110.0125" width="33.60000000000002" height="81.20000000000005" fill="#dbeafe" stroke="black" stroke-width="0.02857142857142857"/></g><g><rect data-type="rect" data-label="node" data-x="-5.48" data-y="-21.64166666666667" x="40" y="1110.0125" width="176.39999999999998" height="22.399999999999864" fill="#fef3c7" stroke="black" stroke-width="0.02857142857142857"/></g><g><rect data-type="rect" data-label="node" data-x="5.48" data-y="-21.64166666666667" x="423.6" y="1110.0125" width="176.39999999999998" height="22.399999999999864" fill="#fef3c7" stroke="black" stroke-width="0.02857142857142857"/></g><text data-type="text" data-label="Layer z=0" data-x="0" data-y="7.613333333333335" x="320" y="97.28749999999985" fill="black" font-size="17.5" 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="-10.028333333333334" x="320" y="714.7458333333333" fill="black" font-size="17.5" 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="1271" 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', '1271');
|
|
21
|
+
|
|
22
|
+
// Calculate real coordinates using inverse transformation
|
|
23
|
+
const matrix = {"a":35,"c":0,"e":320,"b":0,"d":-35,"f":363.7541666666666};
|
|
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,148 @@
|
|
|
1
|
+
{
|
|
2
|
+
"bounds": {
|
|
3
|
+
"minX": -9,
|
|
4
|
+
"maxX": 9,
|
|
5
|
+
"minY": -7,
|
|
6
|
+
"maxY": 7
|
|
7
|
+
},
|
|
8
|
+
"obstacles": [
|
|
9
|
+
{
|
|
10
|
+
"type": "rect",
|
|
11
|
+
"layers": ["top"],
|
|
12
|
+
"center": {
|
|
13
|
+
"x": -5.51,
|
|
14
|
+
"y": -4
|
|
15
|
+
},
|
|
16
|
+
"width": 0.54,
|
|
17
|
+
"height": 0.64,
|
|
18
|
+
"connectedTo": [
|
|
19
|
+
"pcb_smtpad_0",
|
|
20
|
+
"connectivity_net11",
|
|
21
|
+
"source_port_0",
|
|
22
|
+
"pcb_smtpad_0",
|
|
23
|
+
"pcb_port_0"
|
|
24
|
+
],
|
|
25
|
+
"zLayers": [0]
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"type": "rect",
|
|
29
|
+
"layers": ["top"],
|
|
30
|
+
"center": {
|
|
31
|
+
"x": -4.49,
|
|
32
|
+
"y": -4
|
|
33
|
+
},
|
|
34
|
+
"width": 0.54,
|
|
35
|
+
"height": 0.64,
|
|
36
|
+
"connectedTo": [
|
|
37
|
+
"pcb_smtpad_1",
|
|
38
|
+
"connectivity_net0",
|
|
39
|
+
"source_trace_0",
|
|
40
|
+
"source_port_1",
|
|
41
|
+
"source_port_3",
|
|
42
|
+
"pcb_smtpad_1",
|
|
43
|
+
"pcb_port_1",
|
|
44
|
+
"pcb_smtpad_3",
|
|
45
|
+
"pcb_port_3"
|
|
46
|
+
],
|
|
47
|
+
"zLayers": [0]
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"type": "rect",
|
|
51
|
+
"layers": ["top"],
|
|
52
|
+
"center": {
|
|
53
|
+
"x": 4.49,
|
|
54
|
+
"y": -4
|
|
55
|
+
},
|
|
56
|
+
"width": 0.54,
|
|
57
|
+
"height": 0.64,
|
|
58
|
+
"connectedTo": [
|
|
59
|
+
"pcb_smtpad_2",
|
|
60
|
+
"connectivity_net12",
|
|
61
|
+
"source_port_2",
|
|
62
|
+
"pcb_smtpad_2",
|
|
63
|
+
"pcb_port_2"
|
|
64
|
+
],
|
|
65
|
+
"zLayers": [0]
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
"type": "rect",
|
|
69
|
+
"layers": ["top"],
|
|
70
|
+
"center": {
|
|
71
|
+
"x": 5.51,
|
|
72
|
+
"y": -4
|
|
73
|
+
},
|
|
74
|
+
"width": 0.54,
|
|
75
|
+
"height": 0.64,
|
|
76
|
+
"connectedTo": [
|
|
77
|
+
"pcb_smtpad_3",
|
|
78
|
+
"connectivity_net0",
|
|
79
|
+
"source_trace_0",
|
|
80
|
+
"source_port_1",
|
|
81
|
+
"source_port_3",
|
|
82
|
+
"pcb_smtpad_1",
|
|
83
|
+
"pcb_port_1",
|
|
84
|
+
"pcb_smtpad_3",
|
|
85
|
+
"pcb_port_3"
|
|
86
|
+
],
|
|
87
|
+
"zLayers": [0]
|
|
88
|
+
}
|
|
89
|
+
],
|
|
90
|
+
"connections": [
|
|
91
|
+
{
|
|
92
|
+
"name": "source_trace_0",
|
|
93
|
+
"source_trace_id": "source_trace_0",
|
|
94
|
+
"pointsToConnect": [
|
|
95
|
+
{
|
|
96
|
+
"x": -4.49,
|
|
97
|
+
"y": -4,
|
|
98
|
+
"layer": "top",
|
|
99
|
+
"pointId": "pcb_port_1",
|
|
100
|
+
"pcb_port_id": "pcb_port_1"
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
"x": 5.51,
|
|
104
|
+
"y": -4,
|
|
105
|
+
"layer": "top",
|
|
106
|
+
"pointId": "pcb_port_3",
|
|
107
|
+
"pcb_port_id": "pcb_port_3"
|
|
108
|
+
}
|
|
109
|
+
]
|
|
110
|
+
}
|
|
111
|
+
],
|
|
112
|
+
"layerCount": 2,
|
|
113
|
+
"minTraceWidth": 0.15,
|
|
114
|
+
"outline": [
|
|
115
|
+
{
|
|
116
|
+
"x": -8,
|
|
117
|
+
"y": -6
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
"x": -2,
|
|
121
|
+
"y": -6
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
"x": -2,
|
|
125
|
+
"y": 2
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
"x": 2,
|
|
129
|
+
"y": 2
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
"x": 2,
|
|
133
|
+
"y": -6
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
"x": 8,
|
|
137
|
+
"y": -6
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
"x": 8,
|
|
141
|
+
"y": 6
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
"x": -8,
|
|
145
|
+
"y": 6
|
|
146
|
+
}
|
|
147
|
+
]
|
|
148
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
|
+
import srj_json from "./bugreport21-board-outline.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
|
+
const srj = srj_json.simple_route_json ?? srj_json.simpleRouteJson ?? srj_json
|
|
16
|
+
|
|
17
|
+
test("bugreport21-board-outline", async () => {
|
|
18
|
+
const solver = new RectDiffPipeline({
|
|
19
|
+
simpleRouteJson: srj,
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
const outline = makeSimpleRouteOutlineGraphics(srj)
|
|
23
|
+
|
|
24
|
+
solver.solve()
|
|
25
|
+
|
|
26
|
+
const { meshNodes } = solver.getOutput()
|
|
27
|
+
const rectsByCombo = makeCapacityMeshNodeWithLayerInfo(meshNodes)
|
|
28
|
+
const allGraphicsObjects: GraphicsObject[] = []
|
|
29
|
+
|
|
30
|
+
for (const z of Array.from({ length: srj.layerCount }, (_, index) => index)) {
|
|
31
|
+
const layerRects: Rect[] = []
|
|
32
|
+
|
|
33
|
+
for (const [key, rects] of rectsByCombo) {
|
|
34
|
+
const layers = key
|
|
35
|
+
.split(",")
|
|
36
|
+
.map((value) => Number.parseInt(value, 10))
|
|
37
|
+
.filter((value) => !Number.isNaN(value))
|
|
38
|
+
|
|
39
|
+
if (layers.includes(z)) {
|
|
40
|
+
layerRects.push(...rects)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
let labelY = 0
|
|
45
|
+
|
|
46
|
+
if (layerRects.length > 0) {
|
|
47
|
+
let maxY = -Infinity
|
|
48
|
+
|
|
49
|
+
for (const rect of layerRects) {
|
|
50
|
+
const top = rect.center.y + rect.height * (2 / 3)
|
|
51
|
+
|
|
52
|
+
if (top > maxY) maxY = top
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
labelY = maxY
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const graphics: GraphicsObject = {
|
|
59
|
+
title: `RectDiffPipeline - z${z}`,
|
|
60
|
+
texts: [
|
|
61
|
+
{
|
|
62
|
+
anchorSide: "top_right",
|
|
63
|
+
text: `Layer z=${z}`,
|
|
64
|
+
x: 0,
|
|
65
|
+
y: labelY,
|
|
66
|
+
fontSize: 0.5,
|
|
67
|
+
},
|
|
68
|
+
],
|
|
69
|
+
coordinateSystem: "cartesian",
|
|
70
|
+
rects: layerRects,
|
|
71
|
+
points: [],
|
|
72
|
+
lines: [],
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
allGraphicsObjects.push(mergeGraphics(graphics, outline))
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const stackedGraphics = stackGraphicsVertically(allGraphicsObjects)
|
|
79
|
+
const bounds = getBounds(stackedGraphics)
|
|
80
|
+
const boundsWidth = Math.max(1, bounds.maxX - bounds.minX)
|
|
81
|
+
const boundsHeight = Math.max(1, bounds.maxY - bounds.minY)
|
|
82
|
+
const svgWidth = 640
|
|
83
|
+
const svgHeight = Math.max(
|
|
84
|
+
svgWidth,
|
|
85
|
+
Math.ceil((boundsHeight / boundsWidth) * svgWidth),
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
const svg = getSvgFromGraphicsObject(stackedGraphics, {
|
|
89
|
+
svgWidth,
|
|
90
|
+
svgHeight,
|
|
91
|
+
})
|
|
92
|
+
await expect(svg).toMatchSvgSnapshot(import.meta.path)
|
|
93
|
+
})
|