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
23 changes: 23 additions & 0 deletions pages/gap-fill-h-shape-should-expand-node.page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import fixture from "../test-assets/gap-fill-h-shape-should-expand-node.json"
import { GapFillSolverPipeline } from "../lib/solvers/GapFillSolver/GapFillSolverPipeline"
import type { CapacityMeshNode } from "../lib/types/capacity-mesh-types"
import { useMemo } from "react"
import { SolverDebugger3d } from "../components/SolverDebugger3d"

export default () => {
const solver = useMemo(
() =>
new GapFillSolverPipeline({
meshNodes: fixture.meshNodes as CapacityMeshNode[],
}),
[],
)

return (
<SolverDebugger3d
solver={solver}
defaultShowOutput={true}
defaultShowRoot={true}
/>
)
}
72 changes: 72 additions & 0 deletions test-assets/gap-fill-h-shape-should-expand-node.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"description": "H-shaped configuration - two vertical nodes with a horizontal connector in the middle",
"expectedBehavior": "Should detect segments on all exposed edges and expand into empty spaces around the H shape",
"meshNodes": [
{
"capacityMeshNodeId": "node-left-vertical",
"center": { "x": -3, "y": 0 },
"width": 1,
"height": 6,
"layer": "top",
"availableZ": [0]
},
{
"capacityMeshNodeId": "node-right-vertical",
"center": { "x": 3, "y": 0 },
"width": 1,
"height": 6,
"layer": "top",
"availableZ": [0]
},
{
"capacityMeshNodeId": "node-middle-horizontal",
"center": { "x": 0, "y": 0 },
"width": 2,
"height": 1,
"layer": "top",
"availableZ": [0]
}
],
"expectedSegments": [
{
"description": "Left vertical - left edge",
"parentNodeId": "node-left-vertical",
"facingDirection": "x-"
},
{
"description": "Left vertical - top edge (above horizontal)",
"parentNodeId": "node-left-vertical",
"facingDirection": "y+"
},
{
"description": "Left vertical - bottom edge (below horizontal)",
"parentNodeId": "node-left-vertical",
"facingDirection": "y-"
},
{
"description": "Right vertical - right edge",
"parentNodeId": "node-right-vertical",
"facingDirection": "x+"
},
{
"description": "Right vertical - top edge (above horizontal)",
"parentNodeId": "node-right-vertical",
"facingDirection": "y+"
},
{
"description": "Right vertical - bottom edge (below horizontal)",
"parentNodeId": "node-right-vertical",
"facingDirection": "y-"
},
{
"description": "Middle horizontal - top edge",
"parentNodeId": "node-middle-horizontal",
"facingDirection": "y+"
},
{
"description": "Middle horizontal - bottom edge",
"parentNodeId": "node-middle-horizontal",
"facingDirection": "y-"
}
]
}
44 changes: 44 additions & 0 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.
34 changes: 34 additions & 0 deletions tests/should-expand-node.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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 { makeCapacityMeshNodeWithLayerInfo } from "./fixtures/makeCapacityMeshNodeWithLayerInfo"

test("should expand capacityMeshNode to fill the gap", async () => {
const solver = new GapFillSolverPipeline({
meshNodes: middleGapFixture.meshNodes as CapacityMeshNode[],
})

solver.solve()

const { outputNodes } = solver.getOutput()

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

const finalGraphics = makeCapacityMeshNodeWithLayerInfo(outputNodes)
const svg = getSvgFromGraphicsObject(
{ rects: finalGraphics.values().toArray().flat() },
{
svgWidth: 640,
svgHeight: 480,
},
)

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

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