Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bun.lock
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"@types/react-dom": "^19.0.3",
"@vercel/node": "^5.1.7",
"@vitejs/plugin-react": "^4.3.4",
"bun-match-svg": "^0.0.9",
"bun-match-svg": "^0.0.12",
"circuit-json-to-connectivity-map": "^0.0.19",
"circuit-to-svg": "^0.0.110",
"clsx": "^2.1.1",
Expand Down Expand Up @@ -487,7 +487,7 @@

"buffer": ["[email protected]", "", { "dependencies": { "base64-js": "^1.3.1", "ieee754": "^1.1.13" } }, "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ=="],

"bun-match-svg": ["[email protected].9", "", { "dependencies": { "looks-same": "^9.0.1" }, "peerDependencies": { "typescript": "^5.0.0" }, "bin": { "bun-match-svg": "cli.ts" } }, "sha512-WISE8cUd3ztIEbYRymuxs+l4qwRviHIhyRQHmDz26vnhKON9g+Ur+2L3pfJrffpGiYWGF/jtWoWmYRQiaimTxg=="],
"bun-match-svg": ["[email protected].12", "", { "dependencies": { "looks-same": "^9.0.1" }, "peerDependencies": { "typescript": "^5.0.0" }, "bin": { "bun-match-svg": "cli.ts" } }, "sha512-qjQtTwRvuqGDe8xza1OEm3OMA4bUEuFDl4i4y1vH9GwdEegqB9x1/H5+AjoRwQUcMmt5kP9bfPdplkBWxmlfWg=="],

"bun-types": ["[email protected]", "", { "dependencies": { "@types/node": "*" } }, "sha512-ciXLrHV4PXax9vHvUrkvun9VPVGOVwbbbBF/Ev1cXz12lyEZMoJpIJABOfPcN9gDJRaiKF9MVbSygLg4NXu3/A=="],

Expand Down
2 changes: 1 addition & 1 deletion lib/solvers/HighDensitySolver/IntraNodeSolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export class IntraNodeRouteSolver extends BaseSolver {
)
: this.solvedRoutes,
futureConnections: this.unsolvedConnections,
layerCount: 2,
layerCount: this.nodeWithPortPoints.availableZ?.length ?? 2,
hyperParameters: this.hyperParameters,
connMap: this.connMap,
})
Expand Down
39 changes: 18 additions & 21 deletions lib/solvers/HighDensitySolver/SingleHighDensityRouteSolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ export class SingleHighDensityRouteSolver extends BaseSolver {
computeG(node: Node) {
return (
(node.parent?.g ?? 0) +
(node.z === 0 ? 0 : this.viaPenaltyDistance) +
(node.parent && node.z !== node.parent.z ? this.viaPenaltyDistance : 0) +
distance(node, node.parent!)
)
}
Expand Down Expand Up @@ -342,26 +342,23 @@ export class SingleHighDensityRouteSolver extends BaseSolver {
}
}

const viaNeighbor = {
...node,
parent: node,
z: node.z === 0 ? this.layerCount - 1 : 0,
}

if (
!this.exploredNodes.has(this.getNodeKey(viaNeighbor)) &&
!this.isNodeTooCloseToObstacle(
viaNeighbor,
this.viaDiameter / 2 + this.obstacleMargin / 2,
true,
) &&
!this.isNodeTooCloseToEdge(viaNeighbor, true)
) {
viaNeighbor.g = this.computeG(viaNeighbor)
viaNeighbor.h = this.computeH(viaNeighbor)
viaNeighbor.f = this.computeF(viaNeighbor.g, viaNeighbor.h)

neighbors.push(viaNeighbor)
for (let z = 0; z < this.layerCount; z++) {
if (z === node.z) continue
const viaNeighbor = { ...node, parent: node, z }
if (
!this.exploredNodes.has(this.getNodeKey(viaNeighbor)) &&
!this.isNodeTooCloseToObstacle(
viaNeighbor,
this.viaDiameter / 2 + this.obstacleMargin / 2,
true,
) &&
!this.isNodeTooCloseToEdge(viaNeighbor, true)
) {
viaNeighbor.g = this.computeG(viaNeighbor)
viaNeighbor.h = this.computeH(viaNeighbor)
viaNeighbor.f = this.computeF(viaNeighbor.g, viaNeighbor.h)
neighbors.push(viaNeighbor)
}
}

return neighbors
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"@types/react-dom": "^19.0.3",
"@vercel/node": "^5.1.7",
"@vitejs/plugin-react": "^4.3.4",
"bun-match-svg": "^0.0.9",
"bun-match-svg": "^0.0.12",
"circuit-json-to-connectivity-map": "^0.0.19",
"circuit-to-svg": "^0.0.110",
"clsx": "^2.1.1",
Expand Down
84 changes: 84 additions & 0 deletions tests/__snapshots__/e2e-4layer.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions tests/e2e-4layer.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { expect, test } from "bun:test"
import { CapacityMeshSolver } from "../lib"
import type { SimpleRouteJson } from "../lib/types"
import srj from "./fixtures/simple-4layer.json"
import { convertSrjToGraphicsObject } from "./fixtures/convertSrjToGraphicsObject"

test("should solve 4 layer board", async () => {
const solver = new CapacityMeshSolver(srj as SimpleRouteJson)
await solver.solve()
const result = solver.getOutputSimpleRouteJson()
expect(convertSrjToGraphicsObject(result)).toMatchGraphicsSvg(
import.meta.path,
)
})
4 changes: 2 additions & 2 deletions tests/fixtures/convertSrjToGraphicsObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const convertSrjToGraphicsObject = (srj: SimpleRouteJson) => {
const points: Point[] = []

const colorMap: Record<string, string> = getColorMap(srj)
const layerCount = 2
const layerCount = srj.layerCount ?? 2

// Add points for each connection's pointsToConnect
if (srj.connections) {
Expand Down Expand Up @@ -45,7 +45,7 @@ export const convertSrjToGraphicsObject = (srj: SimpleRouteJson) => {
radius: 0.3, // 0.6 via diameter
fill: "blue",
stroke: "none",
layer: "z0,1",
layer: `z${mapLayerNameToZ(routePoint.from_layer!, layerCount)},${mapLayerNameToZ(routePoint.to_layer!, layerCount)}`,
})
} else if (
routePoint.route_type === "wire" &&
Expand Down
31 changes: 31 additions & 0 deletions tests/fixtures/simple-4layer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"layerCount": 4,
"minTraceWidth": 0.15,
"obstacles": [
{
"type": "rect",
"layers": ["top"],
"center": { "x": 5, "y": 5 },
"width": 1,
"height": 1,
"connectedTo": []
}
],
"connections": [
{
"name": "conn1",
"pointsToConnect": [
{ "x": 2, "y": 2, "layer": "top" },
{ "x": 8, "y": 2, "layer": "inner1" }
]
},
{
"name": "conn2",
"pointsToConnect": [
{ "x": 2, "y": 8, "layer": "top" },
{ "x": 8, "y": 8, "layer": "bottom" }
]
}
],
"bounds": { "minX": 0, "maxX": 10, "minY": 0, "maxY": 10 }
}