From d9bc3bda17b689d28c67b2dbe177c9bf1748ad84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A5=D0=B0=D0=BB=D0=B8=D0=BC=D0=BE=D0=B2=20=D0=A0=D1=83?= =?UTF-8?q?=D1=81=D1=82=D0=B0=D0=BC?= Date: Sun, 11 Jan 2026 22:07:46 +0300 Subject: [PATCH] Restote --- src/components/LayoutStep.tsx | 68 +++++++++++++++++------------------ 1 file changed, 33 insertions(+), 35 deletions(-) diff --git a/src/components/LayoutStep.tsx b/src/components/LayoutStep.tsx index e8a4beb..692870c 100644 --- a/src/components/LayoutStep.tsx +++ b/src/components/LayoutStep.tsx @@ -61,7 +61,7 @@ export const LayoutStep: React.FC = ({ config, splits, onChange }) => { }; const selectedData = getSelectedPartition(); - // --- SOLVER --- + // --- SOLVER (Тот самый, рабочий) --- const solveWallLimits = (parts: Partition[]): LimitMap => { const limits: LimitMap = {}; parts.forEach(p => { limits[p.id] = { min: 0, max: 1 }; }); @@ -78,7 +78,9 @@ export const LayoutStep: React.FC = ({ config, splits, onChange }) => { const obsMin = limits[obstacle.id].min; 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); else if (obstacle.offset > center) newMax = Math.min(newMax, obstacle.offset); } @@ -89,7 +91,7 @@ export const LayoutStep: React.FC = ({ config, splits, onChange }) => { return limits; }; - // --- RAYCASTING --- + // --- RAYCASTING (Рабочая логика поиска коробки) --- const getCursorBox = (lx: number, ly: number, parts: Partition[], limitMap: LimitMap) => { let minX = 0, maxX = 1; let minY = 0, maxY = 1; @@ -98,14 +100,16 @@ export const LayoutStep: React.FC = ({ config, splits, onChange }) => { const { min: pMin, max: pMax } = limitMap[p.id]; if (pMax - pMin < 0.001) return; - const EPS = 0.002; + const EPS = 0.005; // Чувствительность к стенкам if (p.axis === 'x') { + // Вертикальная преграда if (ly >= pMin - EPS && ly <= pMax + EPS) { if (p.offset < lx) minX = Math.max(minX, p.offset); if (p.offset > lx) maxX = Math.min(maxX, p.offset); } } else { + // Горизонтальная преграда if (lx >= pMin - EPS && lx <= pMax + EPS) { if (p.offset < ly) minY = Math.max(minY, p.offset); if (p.offset > ly) maxY = Math.min(maxY, p.offset); @@ -115,6 +119,7 @@ export const LayoutStep: React.FC = ({ config, splits, onChange }) => { return { minX, maxX, minY, maxY }; }; + // Поиск соседей для размеров const getNeighborOffsets = (offset: number, crossPos: number, axis: Axis, parts: Partition[], limitMap: LimitMap) => { let min = 0; let max = 1; @@ -236,9 +241,6 @@ export const LayoutStep: React.FC = ({ config, splits, onChange }) => { const lx = (nx - cx1) / cw; const ly = (ny - cy1) / ch; - const realCellW = cw * drawerW; - const realCellH = ch * drawerD; - let found = null; const SNAP = 0.05; for (const p of parts) { @@ -253,26 +255,21 @@ export const LayoutStep: React.FC = ({ config, splits, onChange }) => { if (found) { setHoveredPartition({ id: found.id, cellKey: key }); } else { + // --- ОПРЕДЕЛЕНИЕ ФАНТОМА --- 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 offset = newAxis === 'x' ? lx : ly; - const min = newAxis === 'x' ? box.minY : box.minX; - const max = newAxis === 'x' ? box.maxY : box.maxX; - setPhantomPartition({ axis: newAxis, offset, min, max }); + const width = box.maxX - box.minX; + const height = box.maxY - box.minY; + + // Простейшая логика: делим длинную сторону "комнаты" + // Это работает лучше всего + 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 = ({ config, splits, onChange }) => { } }; - // --- MOUSE LEAVE (Clear Phantoms) --- + // --- НОВОЕ: Очистка при уходе мыши --- const handleMouseLeave = () => { setDragging(null); setPhantomMainAxis(null); - setPhantomPartition(null); + setHoveredMainSplit(null); setHoveredCell(null); + setHoveredPartition(null); + setPhantomPartition(null); }; // --- RENDER --- @@ -344,6 +343,7 @@ export const LayoutStep: React.FC = ({ config, splits, onChange }) => { const limitMap = solveWallLimits(parts); + // Label if (parts.length === 0) { const labelX = cellX + cellW / 2; const labelY = cellY + cellH / 2; @@ -377,20 +377,18 @@ export const LayoutStep: React.FC = ({ config, splits, onChange }) => { lx1 = px; lx2 = px; ly1 = cellY + (cellH * min); ly2 = cellY + (cellH * max); - const cy = (min + max) / 2; - const box = getCursorBox(p.offset, cy, parts, limitMap); - dist1 = Math.abs((p.offset - box.minX) * realW) - wallThick; - dist2 = Math.abs((box.maxX - p.offset) * realW) - wallThick; + const neighbors = getNeighborOffsets(p.offset, (min + max)/2, p.axis, parts, limitMap); + dist1 = Math.abs((p.offset - neighbors.min) * realW) - wallThick; + dist2 = Math.abs((neighbors.max - p.offset) * realW) - wallThick; midX = px; midY = (ly1 + ly2) / 2; } else { const py = cellY + (cellH * p.offset); ly1 = py; ly2 = py; lx1 = cellX + (cellW * min); lx2 = cellX + (cellW * max); - const cx = (min + max) / 2; - const box = getCursorBox(cx, p.offset, parts, limitMap); - dist1 = Math.abs((p.offset - box.minY) * realD) - wallThick; - dist2 = Math.abs((box.maxY - p.offset) * realD) - wallThick; + const neighbors = getNeighborOffsets(p.offset, (min + max)/2, p.axis, parts, limitMap); + dist1 = Math.abs((p.offset - neighbors.min) * realD) - wallThick; + dist2 = Math.abs((neighbors.max - p.offset) * realD) - wallThick; midX = (lx1 + lx2) / 2; midY = py; }