Skip to content
Closed
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
8 changes: 6 additions & 2 deletions lib/data-structures/ObstacleTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ export class ObstacleSpatialHashIndex {
obstacles: Obstacle[] = [],
) {
if (implementation === "flatbush") {
this.idx = new FlatbushIndex<Obstacle>(obstacles.length)
this.idx =
obstacles.length === 0
? new RbushIndex<Obstacle>()
: new FlatbushIndex<Obstacle>(obstacles.length)
} else if (implementation === "rbush") {
this.idx = new RbushIndex<Obstacle>()
} else {
Expand Down Expand Up @@ -50,7 +53,8 @@ export class ObstacleSpatialHashIndex {

// bulk-load initial obstacles
obstacles.forEach((o) => this.insert(o))
if (implementation === "flatbush") this.idx.finish?.()
if (implementation === "flatbush" && obstacles.length > 0)
this.idx.finish?.()
}

insert(o: Obstacle) {
Expand Down
91 changes: 91 additions & 0 deletions tests/__snapshots__/e2e3_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.
2 changes: 1 addition & 1 deletion tests/core3.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ test("core3 - 0402 columns", async () => {
expect(convertCircuitJsonToPcbSvg(circuitJson)).toMatchSvgSnapshot(
import.meta.path,
)
})
}, 20_000)
37 changes: 37 additions & 0 deletions tests/e2e3_4layer.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { expect, test } from "bun:test"
import { CapacityMeshSolver } from "../lib"
import type { SimpleRouteJson } from "lib/types"
import { convertSrjToGraphicsObject } from "./fixtures/convertSrjToGraphicsObject"

test("routes a simple 4-layer board", () => {
const srj: SimpleRouteJson = {
layerCount: 4,
minTraceWidth: 0.15,
obstacles: [],
connections: [
{
name: "conn1",
pointsToConnect: [
{ x: 1, y: 1, layer: "top" },
{ x: 9, y: 9, layer: "bottom" },
],
},
{
name: "conn2",
pointsToConnect: [
{ x: 1, y: 9, layer: "top" },
{ x: 9, y: 1, layer: "bottom" },
],
},
],
bounds: { minX: 0, maxX: 10, minY: 0, maxY: 10 },
}

const solver = new CapacityMeshSolver(srj)
solver.solve()
const result = solver.getOutputSimpleRouteJson()

expect(convertSrjToGraphicsObject(result)).toMatchGraphicsSvg(
import.meta.path,
)
})
6 changes: 4 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 @@ -66,7 +66,9 @@ export const convertSrjToGraphicsObject = (srj: SimpleRouteJson) => {
bottom: "blue",
inner1: "green",
inner2: "yellow",
}[routePoint.layer]!,
inner3: "purple",
inner4: "orange",
}[routePoint.layer] ?? "black",
0.5,
),
// For some reason this is too small, likely a graphics-debug bug
Expand Down