Skip to content
Merged
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
66 changes: 66 additions & 0 deletions lib/fixtures/twoNodeExpansionFixture.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import RBush from "rbush"
import type {
RectDiffExpansionSolverInput,
RectDiffExpansionSolverSnapshot,
} from "../solvers/RectDiffExpansionSolver/RectDiffExpansionSolver"
import type { SimpleRouteJson } from "../types/srj-types"
import type { XYRect } from "../rectdiff-types"
import type { RTreeRect } from "lib/types/capacity-mesh-types"

/**
* Builds a minimal RectDiffExpansionSolver snapshot with exactly two nodes
* separated by empty space. This keeps the data close to the solver’s real
* input shape so we can reuse it for demos/tests that reproduce the gap issue.
*/
export const createTwoNodeExpansionInput = (): RectDiffExpansionSolverInput => {
const srj: SimpleRouteJson = {
bounds: { minX: 0, maxX: 12, minY: 0, maxY: 4 },
layerCount: 1,
minTraceWidth: 0.2,
obstacles: [],
connections: [],
}
const layerCount = srj.layerCount ?? 1
const bounds: XYRect = {
x: srj.bounds.minX,
y: srj.bounds.minY,
width: srj.bounds.maxX - srj.bounds.minX,
height: srj.bounds.maxY - srj.bounds.minY,
}

const obstacleIndexByLayer = Array.from(
{ length: layerCount },
() => new RBush<RTreeRect>(),
)
// Start with all-empty obstacle indexes for a "clean" scenario

const initialSnapshot: RectDiffExpansionSolverSnapshot = {
srj,
layerNames: ["top"],
layerCount,
bounds,
options: { gridSizes: [1] },
boardVoidRects: [],
gridIndex: 0,
candidates: [],
placed: [
{
rect: { x: 0.5, y: 0.5, width: 2, height: 3 },
zLayers: [0],
},
{
rect: { x: 9.5, y: 0.5, width: 2, height: 3 },
zLayers: [0],
},
],
expansionIndex: 0,
edgeAnalysisDone: true,
totalSeedsThisGrid: 0,
consumedSeedsThisGrid: 0,
}

return {
initialSnapshot,
obstacleIndexByLayer,
}
}
13 changes: 13 additions & 0 deletions pages/features/should-expand-node.page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { useMemo } from "react"
import { RectDiffExpansionSolver } from "lib/solvers/RectDiffExpansionSolver/RectDiffExpansionSolver"
import { createTwoNodeExpansionInput } from "lib/fixtures/twoNodeExpansionFixture"
import { SolverDebugger3d } from "../../components/SolverDebugger3d"

export default () => {
const solver = useMemo(
() => new RectDiffExpansionSolver(createTwoNodeExpansionInput()),
[],
)

return <SolverDebugger3d solver={solver} />
}
23 changes: 0 additions & 23 deletions pages/gap-fill-h-shape-should-expand-node.page.tsx

This file was deleted.

4 changes: 2 additions & 2 deletions tests/__snapshots__/should-expand-node.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 7 additions & 16 deletions tests/should-expand-node.test.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
import { expect, test } from "bun:test"
import middleGapFixture from "test-assets/gap-fill-h-shape-should-expand-node.json"
import { getSvgFromGraphicsObject } from "graphics-debug"
import { GapFillSolverPipeline } from "lib/solvers/GapFillSolver/GapFillSolverPipeline"
import type { CapacityMeshNode } from "lib/types/capacity-mesh-types"
import { RectDiffExpansionSolver } from "lib/solvers/RectDiffExpansionSolver/RectDiffExpansionSolver"
import { createTwoNodeExpansionInput } from "lib/fixtures/twoNodeExpansionFixture"
import { makeCapacityMeshNodeWithLayerInfo } from "./fixtures/makeCapacityMeshNodeWithLayerInfo"

test("should expand capacityMeshNode to fill the gap", async () => {
const solver = new GapFillSolverPipeline({
meshNodes: middleGapFixture.meshNodes as CapacityMeshNode[],
})
test("RectDiff expansion reproduces the two-node gap fixture", async () => {
const solver = new RectDiffExpansionSolver(createTwoNodeExpansionInput())

solver.solve()

const { outputNodes } = solver.getOutput()
const { meshNodes } = solver.getOutput()
expect(meshNodes.length).toBeGreaterThanOrEqual(2)

expect(outputNodes.length).toBeGreaterThanOrEqual(
middleGapFixture.meshNodes.length,
)

const finalGraphics = makeCapacityMeshNodeWithLayerInfo(outputNodes)
const finalGraphics = makeCapacityMeshNodeWithLayerInfo(meshNodes)
const svg = getSvgFromGraphicsObject(
{ rects: finalGraphics.values().toArray().flat() },
{
Expand All @@ -27,8 +21,5 @@ test("should expand capacityMeshNode to fill the gap", async () => {
},
)

// More means we have added new nodes to fill the gap
// expect(outputNodes.length).toEqual(3)

await expect(svg).toMatchSvgSnapshot(import.meta.path)
})