Clamp all objects/entrance to room bounds and draw entrance-to-object path flow in optimize mode

This commit is contained in:
2026-10-17 21:39:34 -04:00
parent 73bdecef2b
commit 75b391bad1
10 changed files with 217 additions and 35 deletions
+9 -4
View File
@@ -1,5 +1,6 @@
import type { LayoutEvaluation, LayoutState } from '../types';
import { evaluateLayout } from '../layout/evaluator';
import { clampRectToRoom } from '../geometry/bounds';
export interface NNOptions {
gridSize?: number;
@@ -55,10 +56,14 @@ export function optimizeWithNN(state: LayoutState, options: NNOptions = {}): { b
}
if (targetX < 0) targetX = 0;
if (targetY < 0) targetY = 0;
if (targetX + f.shape.width > candidate.room.width) targetX = candidate.room.width - f.shape.width;
if (targetY + f.shape.height > candidate.room.height) targetY = candidate.room.height - f.shape.height;
f.shape.x = targetX;
f.shape.y = targetY;
const b = clampRectToRoom(
{ x: targetX, y: targetY, width: f.shape.width, height: f.shape.height },
candidate.room,
);
f.shape.x = b.x;
f.shape.y = b.y;
f.shape.width = b.width;
f.shape.height = b.height;
}
const bestEval = evaluateLayout(candidate, options.gridSize || 10);