-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from tscircuit/fix-route-obstacles
Add Debug SVGs for snapshot algorithm development, fix duplicated routes returned from autorouter
- Loading branch information
Showing
7 changed files
with
138 additions
and
2 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
...infinite-grid-ijump-astar/tests/__snapshots__/intersection-with-margin.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 46 additions & 0 deletions
46
algos/infinite-grid-ijump-astar/tests/fixtures/get-debug-svg.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { getSimpleRouteJson } from "autorouting-dataset" | ||
import { test, expect } from "bun:test" | ||
import { circuitJsonToPcbSvg } from "circuit-to-svg" | ||
import { Circuit } from "@tscircuit/core" | ||
import { transformPCBElements } from "@tscircuit/soup-util" | ||
import { translate } from "transformation-matrix" | ||
import type { AnySoupElement } from "@tscircuit/soup" | ||
import type { GeneralizedAstarAutorouter } from "algos/infinite-grid-ijump-astar/v2/lib/GeneralizedAstar" | ||
|
||
export const getDebugSvg = ( | ||
inputCircuitJson: AnySoupElement[], | ||
autorouter: GeneralizedAstarAutorouter, | ||
) => { | ||
const debugSolutions = Object.entries(autorouter.debugSolutions!).map( | ||
([debugSolutionName, solutionCircuitJson]) => ({ | ||
debugSolutionName, | ||
solutionCircuitJson, | ||
}), | ||
) | ||
|
||
const aggCircuitJson: AnySoupElement[] = [] | ||
|
||
for (let i = 0; i < debugSolutions.length; i++) { | ||
const { debugSolutionName, solutionCircuitJson } = debugSolutions[i] | ||
const translatedCircuitJson = transformPCBElements( | ||
JSON.parse( | ||
JSON.stringify( | ||
solutionCircuitJson.concat(inputCircuitJson).concat({ | ||
type: "pcb_fabrication_note_text", | ||
text: debugSolutionName, | ||
pcb_component_id: "unknown", | ||
layer: "top", | ||
font: "tscircuit2024", | ||
font_size: 0.2, | ||
anchor_position: { x: -5, y: 0 }, | ||
anchor_alignment: "center", | ||
}), | ||
), | ||
), | ||
translate(0, -2 * i), | ||
) | ||
aggCircuitJson.push(...translatedCircuitJson) | ||
} | ||
|
||
return circuitJsonToPcbSvg(aggCircuitJson) | ||
} |
36 changes: 36 additions & 0 deletions
36
algos/infinite-grid-ijump-astar/tests/get-debug-svg.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { getSimpleRouteJson } from "autorouting-dataset" | ||
import { test, expect } from "bun:test" | ||
import { circuitJsonToPcbSvg } from "circuit-to-svg" | ||
import { IJumpAutorouter } from "../v2" | ||
import { Circuit } from "@tscircuit/core" | ||
import { transformPCBElements } from "@tscircuit/soup-util" | ||
import { translate } from "transformation-matrix" | ||
import type { AnySoupElement } from "@tscircuit/soup" | ||
import { getDebugSvg } from "./fixtures/get-debug-svg" | ||
|
||
test("ijump-astar: intersection with margin", () => { | ||
const circuit = new Circuit() | ||
|
||
circuit.add( | ||
<board width="10mm" height="2mm" routingDisabled> | ||
<resistor name="R1" resistance="1k" footprint="0402" pcbX={-3} /> | ||
<resistor name="R2" resistance="1k" footprint="0402" pcbX={3} /> | ||
<trace from=".R1 > .pin1" to=".R2 > .pin1" /> | ||
</board>, | ||
) | ||
|
||
const inputCircuitJson = circuit.getCircuitJson() | ||
|
||
const input = getSimpleRouteJson(inputCircuitJson) | ||
|
||
const autorouter = new IJumpAutorouter({ | ||
input, | ||
debug: true, | ||
}) | ||
|
||
const traces = autorouter.solveAndMapToTraces() | ||
|
||
expect(getDebugSvg(inputCircuitJson, autorouter)).toMatchSvgSnapshot( | ||
import.meta.path, | ||
) | ||
}) |
36 changes: 36 additions & 0 deletions
36
algos/infinite-grid-ijump-astar/tests/intersection-with-margin.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { getSimpleRouteJson } from "autorouting-dataset" | ||
import { test, expect } from "bun:test" | ||
import { circuitJsonToPcbSvg } from "circuit-to-svg" | ||
import { IJumpAutorouter } from "../v2" | ||
import { Circuit } from "@tscircuit/core" | ||
import { transformPCBElements } from "@tscircuit/soup-util" | ||
import { translate } from "transformation-matrix" | ||
import type { AnySoupElement } from "@tscircuit/soup" | ||
import { getDebugSvg } from "./fixtures/get-debug-svg" | ||
|
||
test("ijump-astar: intersection with margin", () => { | ||
const circuit = new Circuit() | ||
|
||
circuit.add( | ||
<board width="10mm" height="2mm" routingDisabled> | ||
<resistor name="R1" resistance="1k" footprint="0402" pcbX={-3} /> | ||
<resistor name="R2" resistance="1k" footprint="0402" pcbX={3} /> | ||
<trace from=".R1 > .pin1" to=".R2 > .pin1" /> | ||
</board>, | ||
) | ||
|
||
const inputCircuitJson = circuit.getCircuitJson() | ||
|
||
const input = getSimpleRouteJson(inputCircuitJson) | ||
|
||
const autorouter = new IJumpAutorouter({ | ||
input, | ||
debug: true, | ||
}) | ||
|
||
const traces = autorouter.solveAndMapToTraces() | ||
|
||
expect(getDebugSvg(inputCircuitJson, autorouter)).toMatchSvgSnapshot( | ||
import.meta.path, | ||
) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters