Skip to content

Commit 660c5f2

Browse files
authored
Add simplified out-of-bounds Cosmos fixture (#122)
* Add simplified out-of-bounds Cosmos fixture * Update simplified out-of-bounds fixture dimensions * Add simplified out-of-bounds regression test * Format simplified out-of-bounds regression test
1 parent 49121c0 commit 660c5f2

3 files changed

Lines changed: 67 additions & 0 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import simpleRouteJson from "../test-assets/simplified-out-of-bounds-example.json"
2+
import { RectDiffPipeline } from "../lib/RectDiffPipeline"
3+
import { useMemo } from "react"
4+
import { SolverDebugger3d } from "../components/SolverDebugger3d"
5+
6+
export default () => {
7+
const solver = useMemo(() => new RectDiffPipeline({ simpleRouteJson }), [])
8+
9+
return <SolverDebugger3d solver={solver} simpleRouteJson={simpleRouteJson} />
10+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"bounds": {
3+
"minX": -5.5,
4+
"maxX": 5.5,
5+
"minY": -6,
6+
"maxY": 6
7+
},
8+
"obstacles": [
9+
{
10+
"type": "rect",
11+
"layers": ["top"],
12+
"center": {
13+
"x": -5.856893060790263,
14+
"y": -8.275436101920713
15+
},
16+
"width": 2,
17+
"height": 2,
18+
"connectedTo": []
19+
}
20+
],
21+
"connections": [],
22+
"layerCount": 2,
23+
"minTraceWidth": 0.15
24+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { expect, test } from "bun:test"
2+
import simpleRouteJson from "../test-assets/simplified-out-of-bounds-example.json"
3+
import { RectDiffPipeline } from "../lib/RectDiffPipeline"
4+
5+
test("simplified out-of-bounds fixture currently creates a generated node outside the board bounds", () => {
6+
const solver = new RectDiffPipeline({ simpleRouteJson })
7+
8+
solver.solve()
9+
10+
const { meshNodes } = solver.getOutput()
11+
const outsideGeneratedNodes = meshNodes.filter((node) => {
12+
if (!node.capacityMeshNodeId.startsWith("new-")) return false
13+
14+
const minX = node.center.x - node.width / 2
15+
const maxX = node.center.x + node.width / 2
16+
const minY = node.center.y - node.height / 2
17+
const maxY = node.center.y + node.height / 2
18+
19+
return (
20+
minX < simpleRouteJson.bounds.minX ||
21+
maxX > simpleRouteJson.bounds.maxX ||
22+
minY < simpleRouteJson.bounds.minY ||
23+
maxY > simpleRouteJson.bounds.maxY
24+
)
25+
})
26+
27+
expect(solver.solved).toBe(true)
28+
expect(meshNodes.length).toBeGreaterThan(0)
29+
expect(outsideGeneratedNodes.length).toBeGreaterThan(0)
30+
expect(outsideGeneratedNodes[0]!.capacityMeshNodeId.startsWith("new-")).toBe(
31+
true,
32+
)
33+
})

0 commit comments

Comments
 (0)