Show optimization score in optimize tab; prevent overlaps via collision resolution and overlap penalty

This commit is contained in:
2026-10-17 21:57:44 -04:00
parent 8f8211c9b7
commit d1af53cf07
10 changed files with 179 additions and 43 deletions
+10 -5
View File
@@ -1,6 +1,6 @@
import type { LayoutEvaluation, LayoutState } from '../types';
import { evaluateLayout } from '../layout/evaluator';
import { clampRectToRoom } from '../geometry/bounds';
import { entranceRect, findFreeSpot, overlapsAny, resolveMove } from '../geometry/bounds';
export interface NNOptions {
gridSize?: number;
@@ -56,10 +56,15 @@ export function optimizeWithNN(state: LayoutState, options: NNOptions = {}): { b
}
if (targetX < 0) targetX = 0;
if (targetY < 0) targetY = 0;
const b = clampRectToRoom(
{ x: targetX, y: targetY, width: f.shape.width, height: f.shape.height },
candidate.room,
);
const room = candidate.room;
const others: any[] = candidate.furniture
.filter((o) => o.id !== f.id)
.map((o) => ({ x: o.shape.x, y: o.shape.y, width: o.shape.width, height: o.shape.height }));
const ent = entranceRect(candidate);
if (ent) others.push(ent);
const b = overlapsAny({ x: targetX, y: targetY, width: f.shape.width, height: f.shape.height }, others)
? findFreeSpot(room, { width: f.shape.width, height: f.shape.height }, others)
: resolveMove({ x: targetX, y: targetY, width: f.shape.width, height: f.shape.height }, others, room);
f.shape.x = b.x;
f.shape.y = b.y;
f.shape.width = b.width;