diff --git a/algos/infinite-grid-ijump-astar/v1/lib/getObstaclesFromTrace.ts b/algos/infinite-grid-ijump-astar/v1/lib/getObstaclesFromTrace.ts index c212394..5075ddf 100644 --- a/algos/infinite-grid-ijump-astar/v1/lib/getObstaclesFromTrace.ts +++ b/algos/infinite-grid-ijump-astar/v1/lib/getObstaclesFromTrace.ts @@ -22,6 +22,7 @@ export const getObstaclesFromTrace = ( const obstacle: Obstacle = { type: "rect", + layers: [start.layer], center: { x: (start.x + end.x) / 2, y: (start.y + end.y) / 2, diff --git a/bun.lockb b/bun.lockb index 735de2d..2afd281 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/module/lib/solver-utils/getObstaclesFromCircuitJson.ts b/module/lib/solver-utils/getObstaclesFromCircuitJson.ts index 41564ba..11ea43c 100644 --- a/module/lib/solver-utils/getObstaclesFromCircuitJson.ts +++ b/module/lib/solver-utils/getObstaclesFromCircuitJson.ts @@ -2,6 +2,8 @@ import type { AnySoupElement } from "@tscircuit/soup" import type { Obstacle } from "../types" import { getObstaclesFromRoute } from "./getObstaclesFromRoute" +const EVERY_LAYER = ["top", "inner1", "inner2", "bottom"] + export const getObstaclesFromCircuitJson = (soup: AnySoupElement[]) => { const obstacles: Obstacle[] = [] for (const element of soup) { @@ -10,6 +12,7 @@ export const getObstaclesFromCircuitJson = (soup: AnySoupElement[]) => { obstacles.push({ // @ts-ignore type: "oval", + layers: [element.layer], center: { x: element.x, y: element.y, @@ -21,6 +24,7 @@ export const getObstaclesFromCircuitJson = (soup: AnySoupElement[]) => { } else if (element.shape === "rect") { obstacles.push({ type: "rect", + layers: [element.layer], center: { x: element.x, y: element.y, @@ -35,6 +39,7 @@ export const getObstaclesFromCircuitJson = (soup: AnySoupElement[]) => { obstacles.push({ // @ts-ignore type: "oval", + layers: element.layers, center: { x: element.center.x, y: element.center.y, @@ -46,9 +51,10 @@ export const getObstaclesFromCircuitJson = (soup: AnySoupElement[]) => { } else if (element.shape === "rect") { obstacles.push({ type: "rect", + layers: element.layers, center: { - x: element.x, - y: element.y, + x: element.center.x, + y: element.center.y, }, width: element.width, height: element.height, @@ -71,6 +77,7 @@ export const getObstaclesFromCircuitJson = (soup: AnySoupElement[]) => { } else if (element.hole_shape === "square") { obstacles.push({ type: "rect", + layers: EVERY_LAYER, center: { x: element.x, y: element.y, @@ -82,6 +89,7 @@ export const getObstaclesFromCircuitJson = (soup: AnySoupElement[]) => { } else if (element.hole_shape === "round") { obstacles.push({ type: "rect", + layers: EVERY_LAYER, center: { x: element.x, y: element.y, @@ -96,6 +104,7 @@ export const getObstaclesFromCircuitJson = (soup: AnySoupElement[]) => { obstacles.push({ // @ts-ignore type: "oval", + layers: EVERY_LAYER, center: { x: element.x, y: element.y, @@ -108,6 +117,7 @@ export const getObstaclesFromCircuitJson = (soup: AnySoupElement[]) => { obstacles.push({ // @ts-ignore type: "oval", + layers: EVERY_LAYER, center: { x: element.x, y: element.y, @@ -119,7 +129,11 @@ export const getObstaclesFromCircuitJson = (soup: AnySoupElement[]) => { } } else if (element.type === "pcb_trace") { const traceObstacles = getObstaclesFromRoute( - element.route, + element.route.map((rp) => ({ + x: rp.x, + y: rp.y, + layer: "layer" in rp ? rp.layer : rp.from_layer, + })), element.source_trace_id!, ) obstacles.push(...traceObstacles) diff --git a/module/lib/solver-utils/getObstaclesFromRoute.ts b/module/lib/solver-utils/getObstaclesFromRoute.ts index 8901e07..71694ca 100644 --- a/module/lib/solver-utils/getObstaclesFromRoute.ts +++ b/module/lib/solver-utils/getObstaclesFromRoute.ts @@ -3,6 +3,7 @@ import type { Obstacle } from "autorouting-dataset/lib/types" interface Point { x: number y: number + layer: string } export const getObstaclesFromRoute = ( @@ -24,6 +25,7 @@ export const getObstaclesFromRoute = ( const obstacle: Obstacle = { type: "rect", + layers: [start.layer], center: { x: (start.x + end.x) / 2, y: (start.y + end.y) / 2, diff --git a/module/lib/types.ts b/module/lib/types.ts index 6fefc37..c72c1b6 100644 --- a/module/lib/types.ts +++ b/module/lib/types.ts @@ -18,6 +18,7 @@ export interface Point { export type Obstacle = { // TODO include ovals type: "rect" // NOTE: most datasets do not contain ovals + layers: string[] center: { x: number; y: number } width: number height: number diff --git a/module/tests/getObstaclesFromCircuitJson.test.ts b/module/tests/getObstaclesFromCircuitJson.test.ts index 8f7d552..9f0f025 100644 --- a/module/tests/getObstaclesFromCircuitJson.test.ts +++ b/module/tests/getObstaclesFromCircuitJson.test.ts @@ -26,12 +26,14 @@ test("pcb_trace becomes an obstacle correctly", () => { center: { x: 5, y: 0 }, width: 10, height: 0.1, + layers: ["top"], connectedTo: ["trace1"], }) // Check the second obstacle (vertical trace) expect(obstacles[1]).toEqual({ type: "rect", + layers: ["top"], center: { x: 10, y: 5 }, width: 0.1, height: 10, diff --git a/package.json b/package.json index 12e9b44..109d762 100644 --- a/package.json +++ b/package.json @@ -18,8 +18,8 @@ "@tscircuit/builder": "1.11.2", "@tscircuit/pcb-viewer": "1.4.5", "@tscircuit/props": "^0.0.26", - "@tscircuit/soup": "^0.0.66", - "@tscircuit/soup-util": "^0.0.21", + "@tscircuit/soup": "^0.0.68", + "@tscircuit/soup-util": "^0.0.23", "@types/bun": "latest", "@types/d3-delaunay": "^6.0.4", "@types/debug": "^4.1.12",