Restote
This commit is contained in:
@@ -61,7 +61,7 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
|||||||
};
|
};
|
||||||
const selectedData = getSelectedPartition();
|
const selectedData = getSelectedPartition();
|
||||||
|
|
||||||
// --- SOLVER ---
|
// --- SOLVER (Тот самый, рабочий) ---
|
||||||
const solveWallLimits = (parts: Partition[]): LimitMap => {
|
const solveWallLimits = (parts: Partition[]): LimitMap => {
|
||||||
const limits: LimitMap = {};
|
const limits: LimitMap = {};
|
||||||
parts.forEach(p => { limits[p.id] = { min: 0, max: 1 }; });
|
parts.forEach(p => { limits[p.id] = { min: 0, max: 1 }; });
|
||||||
@@ -78,7 +78,9 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
|||||||
const obsMin = limits[obstacle.id].min;
|
const obsMin = limits[obstacle.id].min;
|
||||||
const obsMax = limits[obstacle.id].max;
|
const obsMax = limits[obstacle.id].max;
|
||||||
|
|
||||||
if (target.offset >= obsMin - 0.001 && target.offset <= obsMax + 0.001) {
|
// EPSILON для надежности пересечений
|
||||||
|
const EPS = 0.002;
|
||||||
|
if (target.offset >= obsMin - EPS && target.offset <= obsMax + EPS) {
|
||||||
if (obstacle.offset < center) newMin = Math.max(newMin, obstacle.offset);
|
if (obstacle.offset < center) newMin = Math.max(newMin, obstacle.offset);
|
||||||
else if (obstacle.offset > center) newMax = Math.min(newMax, obstacle.offset);
|
else if (obstacle.offset > center) newMax = Math.min(newMax, obstacle.offset);
|
||||||
}
|
}
|
||||||
@@ -89,7 +91,7 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
|||||||
return limits;
|
return limits;
|
||||||
};
|
};
|
||||||
|
|
||||||
// --- RAYCASTING ---
|
// --- RAYCASTING (Рабочая логика поиска коробки) ---
|
||||||
const getCursorBox = (lx: number, ly: number, parts: Partition[], limitMap: LimitMap) => {
|
const getCursorBox = (lx: number, ly: number, parts: Partition[], limitMap: LimitMap) => {
|
||||||
let minX = 0, maxX = 1;
|
let minX = 0, maxX = 1;
|
||||||
let minY = 0, maxY = 1;
|
let minY = 0, maxY = 1;
|
||||||
@@ -98,14 +100,16 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
|||||||
const { min: pMin, max: pMax } = limitMap[p.id];
|
const { min: pMin, max: pMax } = limitMap[p.id];
|
||||||
if (pMax - pMin < 0.001) return;
|
if (pMax - pMin < 0.001) return;
|
||||||
|
|
||||||
const EPS = 0.002;
|
const EPS = 0.005; // Чувствительность к стенкам
|
||||||
|
|
||||||
if (p.axis === 'x') {
|
if (p.axis === 'x') {
|
||||||
|
// Вертикальная преграда
|
||||||
if (ly >= pMin - EPS && ly <= pMax + EPS) {
|
if (ly >= pMin - EPS && ly <= pMax + EPS) {
|
||||||
if (p.offset < lx) minX = Math.max(minX, p.offset);
|
if (p.offset < lx) minX = Math.max(minX, p.offset);
|
||||||
if (p.offset > lx) maxX = Math.min(maxX, p.offset);
|
if (p.offset > lx) maxX = Math.min(maxX, p.offset);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// Горизонтальная преграда
|
||||||
if (lx >= pMin - EPS && lx <= pMax + EPS) {
|
if (lx >= pMin - EPS && lx <= pMax + EPS) {
|
||||||
if (p.offset < ly) minY = Math.max(minY, p.offset);
|
if (p.offset < ly) minY = Math.max(minY, p.offset);
|
||||||
if (p.offset > ly) maxY = Math.min(maxY, p.offset);
|
if (p.offset > ly) maxY = Math.min(maxY, p.offset);
|
||||||
@@ -115,6 +119,7 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
|||||||
return { minX, maxX, minY, maxY };
|
return { minX, maxX, minY, maxY };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Поиск соседей для размеров
|
||||||
const getNeighborOffsets = (offset: number, crossPos: number, axis: Axis, parts: Partition[], limitMap: LimitMap) => {
|
const getNeighborOffsets = (offset: number, crossPos: number, axis: Axis, parts: Partition[], limitMap: LimitMap) => {
|
||||||
let min = 0;
|
let min = 0;
|
||||||
let max = 1;
|
let max = 1;
|
||||||
@@ -236,9 +241,6 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
|||||||
const lx = (nx - cx1) / cw;
|
const lx = (nx - cx1) / cw;
|
||||||
const ly = (ny - cy1) / ch;
|
const ly = (ny - cy1) / ch;
|
||||||
|
|
||||||
const realCellW = cw * drawerW;
|
|
||||||
const realCellH = ch * drawerD;
|
|
||||||
|
|
||||||
let found = null;
|
let found = null;
|
||||||
const SNAP = 0.05;
|
const SNAP = 0.05;
|
||||||
for (const p of parts) {
|
for (const p of parts) {
|
||||||
@@ -253,26 +255,21 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
|||||||
if (found) {
|
if (found) {
|
||||||
setHoveredPartition({ id: found.id, cellKey: key });
|
setHoveredPartition({ id: found.id, cellKey: key });
|
||||||
} else {
|
} else {
|
||||||
|
// --- ОПРЕДЕЛЕНИЕ ФАНТОМА ---
|
||||||
const box = getCursorBox(lx, ly, parts, limitMap);
|
const box = getCursorBox(lx, ly, parts, limitMap);
|
||||||
const boxW = (box.maxX - box.minX) * realCellW;
|
|
||||||
const boxH = (box.maxY - box.minY) * realCellH;
|
|
||||||
|
|
||||||
let newAxis: Axis = boxW > boxH ? 'x' : 'y';
|
|
||||||
|
|
||||||
const relL = (lx - box.minX) / (box.maxX - box.minX);
|
|
||||||
const relT = (ly - box.minY) / (box.maxY - box.minY);
|
|
||||||
const THRESHOLD = 0.2;
|
|
||||||
|
|
||||||
if (relL < THRESHOLD || relL > 1 - THRESHOLD) newAxis = 'x';
|
|
||||||
else if (relT < THRESHOLD || relT > 1 - THRESHOLD) newAxis = 'y';
|
|
||||||
|
|
||||||
const valid = (newAxis === 'x' && (box.maxX - box.minX) > 0.05) || (newAxis === 'y' && (box.maxY - box.minY) > 0.05);
|
|
||||||
|
|
||||||
if (valid) {
|
const width = box.maxX - box.minX;
|
||||||
const offset = newAxis === 'x' ? lx : ly;
|
const height = box.maxY - box.minY;
|
||||||
const min = newAxis === 'x' ? box.minY : box.minX;
|
|
||||||
const max = newAxis === 'x' ? box.maxY : box.maxX;
|
// Простейшая логика: делим длинную сторону "комнаты"
|
||||||
setPhantomPartition({ axis: newAxis, offset, min, max });
|
// Это работает лучше всего
|
||||||
|
const axis = width > height ? 'x' : 'y';
|
||||||
|
|
||||||
|
if ((axis === 'y' && height > 0.05) || (axis === 'x' && width > 0.05)) {
|
||||||
|
const offset = axis === 'x' ? lx : ly;
|
||||||
|
const min = axis === 'x' ? box.minY : box.minX;
|
||||||
|
const max = axis === 'x' ? box.maxY : box.maxX;
|
||||||
|
setPhantomPartition({ axis, offset, min, max });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -315,12 +312,14 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// --- MOUSE LEAVE (Clear Phantoms) ---
|
// --- НОВОЕ: Очистка при уходе мыши ---
|
||||||
const handleMouseLeave = () => {
|
const handleMouseLeave = () => {
|
||||||
setDragging(null);
|
setDragging(null);
|
||||||
setPhantomMainAxis(null);
|
setPhantomMainAxis(null);
|
||||||
setPhantomPartition(null);
|
setHoveredMainSplit(null);
|
||||||
setHoveredCell(null);
|
setHoveredCell(null);
|
||||||
|
setHoveredPartition(null);
|
||||||
|
setPhantomPartition(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
// --- RENDER ---
|
// --- RENDER ---
|
||||||
@@ -344,6 +343,7 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
|||||||
|
|
||||||
const limitMap = solveWallLimits(parts);
|
const limitMap = solveWallLimits(parts);
|
||||||
|
|
||||||
|
// Label
|
||||||
if (parts.length === 0) {
|
if (parts.length === 0) {
|
||||||
const labelX = cellX + cellW / 2;
|
const labelX = cellX + cellW / 2;
|
||||||
const labelY = cellY + cellH / 2;
|
const labelY = cellY + cellH / 2;
|
||||||
@@ -377,20 +377,18 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
|||||||
lx1 = px; lx2 = px;
|
lx1 = px; lx2 = px;
|
||||||
ly1 = cellY + (cellH * min); ly2 = cellY + (cellH * max);
|
ly1 = cellY + (cellH * min); ly2 = cellY + (cellH * max);
|
||||||
|
|
||||||
const cy = (min + max) / 2;
|
const neighbors = getNeighborOffsets(p.offset, (min + max)/2, p.axis, parts, limitMap);
|
||||||
const box = getCursorBox(p.offset, cy, parts, limitMap);
|
dist1 = Math.abs((p.offset - neighbors.min) * realW) - wallThick;
|
||||||
dist1 = Math.abs((p.offset - box.minX) * realW) - wallThick;
|
dist2 = Math.abs((neighbors.max - p.offset) * realW) - wallThick;
|
||||||
dist2 = Math.abs((box.maxX - p.offset) * realW) - wallThick;
|
|
||||||
midX = px; midY = (ly1 + ly2) / 2;
|
midX = px; midY = (ly1 + ly2) / 2;
|
||||||
} else {
|
} else {
|
||||||
const py = cellY + (cellH * p.offset);
|
const py = cellY + (cellH * p.offset);
|
||||||
ly1 = py; ly2 = py;
|
ly1 = py; ly2 = py;
|
||||||
lx1 = cellX + (cellW * min); lx2 = cellX + (cellW * max);
|
lx1 = cellX + (cellW * min); lx2 = cellX + (cellW * max);
|
||||||
|
|
||||||
const cx = (min + max) / 2;
|
const neighbors = getNeighborOffsets(p.offset, (min + max)/2, p.axis, parts, limitMap);
|
||||||
const box = getCursorBox(cx, p.offset, parts, limitMap);
|
dist1 = Math.abs((p.offset - neighbors.min) * realD) - wallThick;
|
||||||
dist1 = Math.abs((p.offset - box.minY) * realD) - wallThick;
|
dist2 = Math.abs((neighbors.max - p.offset) * realD) - wallThick;
|
||||||
dist2 = Math.abs((box.maxY - p.offset) * realD) - wallThick;
|
|
||||||
midX = (lx1 + lx2) / 2; midY = py;
|
midX = (lx1 + lx2) / 2; midY = py;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user