Skip to content

Commit 1d56481

Browse files
committed
WIP
1 parent c72091d commit 1d56481

File tree

2 files changed

+73
-8
lines changed

2 files changed

+73
-8
lines changed

lib/RectDiffPipeline.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { GridFill3DOptions } from "./solvers/rectdiff/types"
44
import { RectDiffSolver } from "./solvers/RectDiffSolver"
55
import type { CapacityMeshNode } from "./types/capacity-mesh-types"
66
import type { GraphicsObject } from "graphics-debug"
7+
import { createBaseVisualization } from "./solvers/rectdiff/visualization"
78

89
export interface RectDiffPipelineInput {
910
simpleRouteJson: SimpleRouteJson
@@ -44,13 +45,11 @@ export class RectDiffPipeline extends BasePipelineSolver<RectDiffPipelineInput>
4445
if (solver) {
4546
return solver.visualize()
4647
}
47-
// Return empty visualization if solver not initialized yet
48-
return {
49-
title: "RectDiff Pipeline (initializing...)",
50-
coordinateSystem: "cartesian",
51-
rects: [],
52-
points: [],
53-
lines: [],
54-
}
48+
49+
// Show board and obstacles even before solver is initialized
50+
return createBaseVisualization(
51+
this.inputProblem.simpleRouteJson,
52+
"RectDiff Pipeline (not started)",
53+
)
5554
}
5655
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import type { GraphicsObject } from "graphics-debug"
2+
import type { SimpleRouteJson } from "../../types/srj-types"
3+
4+
/**
5+
* Create basic visualization showing board bounds/outline and obstacles.
6+
* This can be used before solver initialization to show the problem space.
7+
*/
8+
export function createBaseVisualization(
9+
srj: SimpleRouteJson,
10+
title: string = "RectDiff",
11+
): GraphicsObject {
12+
const rects: NonNullable<GraphicsObject["rects"]> = []
13+
const lines: NonNullable<GraphicsObject["lines"]> = []
14+
15+
const boardBounds = {
16+
minX: srj.bounds.minX,
17+
maxX: srj.bounds.maxX,
18+
minY: srj.bounds.minY,
19+
maxY: srj.bounds.maxY,
20+
}
21+
22+
// Draw board outline or bounds rectangle
23+
if (srj.outline && srj.outline.length > 1) {
24+
lines.push({
25+
points: [...srj.outline, srj.outline[0]!],
26+
strokeColor: "#111827",
27+
strokeWidth: 0.01,
28+
label: "outline",
29+
})
30+
} else {
31+
rects.push({
32+
center: {
33+
x: (boardBounds.minX + boardBounds.maxX) / 2,
34+
y: (boardBounds.minY + boardBounds.maxY) / 2,
35+
},
36+
width: boardBounds.maxX - boardBounds.minX,
37+
height: boardBounds.maxY - boardBounds.minY,
38+
fill: "none",
39+
stroke: "#111827",
40+
label: "board",
41+
})
42+
}
43+
44+
// Draw obstacles
45+
for (const obstacle of srj.obstacles ?? []) {
46+
if (obstacle.type === "rect" || obstacle.type === "oval") {
47+
rects.push({
48+
center: { x: obstacle.center.x, y: obstacle.center.y },
49+
width: obstacle.width,
50+
height: obstacle.height,
51+
fill: "#fee2e2",
52+
stroke: "#ef4444",
53+
layer: "obstacle",
54+
label: "obstacle",
55+
})
56+
}
57+
}
58+
59+
return {
60+
title,
61+
coordinateSystem: "cartesian",
62+
rects,
63+
points: [],
64+
lines,
65+
}
66+
}

0 commit comments

Comments
 (0)