Show optimization score in optimize tab; prevent overlaps via collision resolution and overlap penalty
This commit is contained in:
+10
-5
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user