Skip to content

Commit

Permalink
add layers to obstacles
Browse files Browse the repository at this point in the history
  • Loading branch information
seveibar committed Sep 9, 2024
1 parent 3dd3f8a commit 3684fba
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Binary file modified bun.lockb
Binary file not shown.
20 changes: 17 additions & 3 deletions module/lib/solver-utils/getObstaclesFromCircuitJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions module/lib/solver-utils/getObstaclesFromRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { Obstacle } from "autorouting-dataset/lib/types"
interface Point {
x: number
y: number
layer: string
}

export const getObstaclesFromRoute = (
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions module/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions module/tests/getObstaclesFromCircuitJson.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 3684fba

Please sign in to comment.