7
This commit is contained in:
@@ -19,6 +19,7 @@ type DragTarget =
|
||||
|
||||
export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
||||
const svgRef = useRef<SVGSVGElement>(null);
|
||||
const containerRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
// -- STATE --
|
||||
const [mode, setMode] = useState<EditMode>('lines');
|
||||
@@ -50,7 +51,7 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
||||
const sortedX = useMemo(() => [0, ...safeX, 1].sort((a, b) => a - b), [safeX]);
|
||||
const sortedY = useMemo(() => [0, ...safeY, 1].sort((a, b) => a - b), [safeY]);
|
||||
|
||||
// -- HELPERS --
|
||||
// -- HELPER: Get Selected --
|
||||
const getSelectedPartition = () => {
|
||||
if (!selectedPartitionId) return null;
|
||||
for (const key in safePartitions) {
|
||||
@@ -61,7 +62,7 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
||||
};
|
||||
const selectedData = getSelectedPartition();
|
||||
|
||||
// --- SOLVER (Копия из geometryGenerator для синхронизации) ---
|
||||
// --- SOLVER (Синхронизирован с 3D) ---
|
||||
const solveWallLimits = (parts: Partition[]): LimitMap => {
|
||||
const limits: LimitMap = {};
|
||||
parts.forEach(p => { limits[p.id] = { min: 0, max: 1 }; });
|
||||
@@ -73,8 +74,7 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
||||
const center = target.offset;
|
||||
|
||||
parts.forEach(obstacle => {
|
||||
if (target.id === obstacle.id) return;
|
||||
if (target.axis === obstacle.axis) return;
|
||||
if (target.id === obstacle.id || target.axis === obstacle.axis) return;
|
||||
|
||||
const obsMin = limits[obstacle.id].min;
|
||||
const obsMax = limits[obstacle.id].max;
|
||||
@@ -90,22 +90,42 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
||||
return limits;
|
||||
};
|
||||
|
||||
// Расчет границ для НОВОЙ стенки (используем уже решенные границы существующих)
|
||||
// Поиск ближайших соседей для текста размеров
|
||||
const getNeighborOffsets = (currentOffset: number, crossPos: number, axis: Axis, parts: Partition[]) => {
|
||||
let minLimit = 0;
|
||||
let maxLimit = 1;
|
||||
const limitMap = solveWallLimits(parts); // Используем решенные границы для соседей
|
||||
|
||||
parts.forEach(p => {
|
||||
if (p.axis === axis) { // Параллельные
|
||||
const { min: pMin, max: pMax } = limitMap[p.id];
|
||||
// Пересекаются ли проекции?
|
||||
if (crossPos > pMin && crossPos < pMax) {
|
||||
if (p.offset < currentOffset) minLimit = Math.max(minLimit, p.offset);
|
||||
if (p.offset > currentOffset) maxLimit = Math.min(maxLimit, p.offset);
|
||||
}
|
||||
}
|
||||
});
|
||||
return { min: minLimit, max: maxLimit };
|
||||
};
|
||||
|
||||
// Границы для курсора (Raycasting)
|
||||
const getCursorBox = (lx: number, ly: number, parts: Partition[], limitMap: LimitMap) => {
|
||||
let minX = 0, maxX = 1;
|
||||
let minY = 0, maxY = 1;
|
||||
|
||||
parts.forEach(p => {
|
||||
// Берем актуальные границы
|
||||
const { min: pMin, max: pMax } = limitMap[p.id];
|
||||
if (pMax - pMin < 0.001) return;
|
||||
|
||||
if (p.axis === 'x') {
|
||||
// Вертикальная преграда
|
||||
if (ly > pMin && ly < pMax) {
|
||||
if (p.offset < lx) minX = Math.max(minX, p.offset);
|
||||
if (p.offset > lx) maxX = Math.min(maxX, p.offset);
|
||||
}
|
||||
} else {
|
||||
// Горизонтальная преграда
|
||||
if (lx > pMin && lx < pMax) {
|
||||
if (p.offset < ly) minY = Math.max(minY, p.offset);
|
||||
if (p.offset > ly) maxY = Math.min(maxY, p.offset);
|
||||
@@ -196,6 +216,7 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
||||
setPhantomPartition(null);
|
||||
setHoveredCell(null);
|
||||
|
||||
// 1. Находим ячейку
|
||||
let cellIdx = null;
|
||||
for (let i = 0; i < sortedX.length - 1; i++) {
|
||||
if (nx >= sortedX[i] && nx <= sortedX[i+1]) {
|
||||
@@ -211,7 +232,7 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
||||
setHoveredCell(cellIdx);
|
||||
const key = `${cellIdx.i}-${cellIdx.j}`;
|
||||
const parts = safePartitions[key] || [];
|
||||
const limitMap = solveWallLimits(parts); // Вызываем солвер
|
||||
const limitMap = solveWallLimits(parts);
|
||||
|
||||
const cx1 = sortedX[cellIdx.i]; const cx2 = sortedX[cellIdx.i+1];
|
||||
const cy1 = sortedY[cellIdx.j]; const cy2 = sortedY[cellIdx.j+1];
|
||||
@@ -233,17 +254,14 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
||||
if (found) {
|
||||
setHoveredPartition({ id: found.id, cellKey: key });
|
||||
} else {
|
||||
// Вычисляем бокс под курсором
|
||||
const box = getCursorBox(lx, ly, parts, limitMap);
|
||||
|
||||
const axis = (lx - box.minX < box.maxX - lx) && (lx - box.minX < Math.min(ly - box.minY, box.maxY - ly)) ? 'x' :
|
||||
(box.maxX - lx < lx - box.minX) && (box.maxX - lx < Math.min(ly - box.minY, box.maxY - ly)) ? 'x' :
|
||||
Math.min(lx - box.minX, box.maxX - lx) < Math.min(ly - box.minY, box.maxY - ly) ? 'x' : 'y';
|
||||
|
||||
// Лучше: перпендикулярно ближайшей стороне
|
||||
const distL = lx - box.minX; const distR = box.maxX - lx;
|
||||
const distT = ly - box.minY; const distB = box.maxY - ly;
|
||||
const minD = Math.min(distL, distR, distT, distB);
|
||||
|
||||
// Выбираем ось перпендикулярно ближайшей границе
|
||||
const minD = Math.min(distL, distR, distT, distB);
|
||||
const newAxis = (minD === distL || minD === distR) ? 'x' : 'y';
|
||||
|
||||
const width = box.maxX - box.minX;
|
||||
@@ -296,7 +314,6 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
||||
}
|
||||
};
|
||||
|
||||
// --- RENDER ---
|
||||
const renderCellsAndPartitions = () => {
|
||||
const elements = [];
|
||||
for (let i = 0; i < sortedX.length - 1; i++) {
|
||||
@@ -315,7 +332,8 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
||||
const realW = (x2 - x1) * drawerW;
|
||||
const realD = (y2 - y1) * drawerD;
|
||||
|
||||
const limitMap = solveWallLimits(parts); // SOLVER для отрисовки
|
||||
// ВАЖНО: Вычисляем границы для отображения
|
||||
const limitMap = solveWallLimits(parts);
|
||||
|
||||
if (parts.length === 0) {
|
||||
const labelX = cellX + cellW / 2;
|
||||
@@ -350,20 +368,21 @@ export const LayoutStep: React.FC<Props> = ({ 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);
|
||||
|
||||
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);
|
||||
|
||||
dist1 = Math.abs((p.offset - neighbors.min) * realD) - wallThick;
|
||||
dist2 = Math.abs((neighbors.max - p.offset) * realD) - wallThick;
|
||||
midX = (lx1 + lx2) / 2; midY = py;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user