diff --git a/pages/gap-fill-h-shape-should-expand-node.page.tsx b/pages/gap-fill-h-shape-should-expand-node.page.tsx new file mode 100644 index 0000000..ce84755 --- /dev/null +++ b/pages/gap-fill-h-shape-should-expand-node.page.tsx @@ -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 ( + + ) +} diff --git a/test-assets/gap-fill-h-shape-should-expand-node.json b/test-assets/gap-fill-h-shape-should-expand-node.json new file mode 100644 index 0000000..aee7b90 --- /dev/null +++ b/test-assets/gap-fill-h-shape-should-expand-node.json @@ -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-" + } + ] +} diff --git a/tests/__snapshots__/should-expand-node.snap.svg b/tests/__snapshots__/should-expand-node.snap.svg new file mode 100644 index 0000000..8282007 --- /dev/null +++ b/tests/__snapshots__/should-expand-node.snap.svg @@ -0,0 +1,44 @@ + \ No newline at end of file diff --git a/tests/should-expand-node.test.ts b/tests/should-expand-node.test.ts new file mode 100644 index 0000000..2e7deab --- /dev/null +++ b/tests/should-expand-node.test.ts @@ -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) +})