From 9249b424fe491c55544aa9938f2ca15548e25c93 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: Sat, 10 Jan 2026 22:35:25 +0300 Subject: [PATCH] Try add wals --- src/components/LayoutStep.tsx | 498 ++++++++++++++++-------------- src/services/geometryGenerator.ts | 25 +- src/types.ts | 5 +- 3 files changed, 291 insertions(+), 237 deletions(-) diff --git a/src/components/LayoutStep.tsx b/src/components/LayoutStep.tsx index d272083..5a1d06b 100644 --- a/src/components/LayoutStep.tsx +++ b/src/components/LayoutStep.tsx @@ -1,6 +1,6 @@ import React, { useRef, useState, useMemo } from 'react'; import { AppConfig, LayoutSplits, Partition } from '../types'; -import { Grid, MousePointer2, Trash2, RotateCcw, X, Plus } from 'lucide-react'; +import { Grid, MousePointer2, RotateCcw, X, Move } from 'lucide-react'; interface Props { config: AppConfig; @@ -19,17 +19,18 @@ export const LayoutStep: React.FC = ({ config, splits, onChange }) => { const svgRef = useRef(null); const [mode, setMode] = useState('lines'); - - const [mousePos, setMousePos] = useState({ x: 0, y: 0 }); - const [isButtonHovered, setIsButtonHovered] = useState(false); + const [mousePos, setMousePos] = useState({ x: 0, y: 0 }); const [dragging, setDragging] = useState(null); - + const [isButtonHovered, setIsButtonHovered] = useState(false); + + // Main Grid const [phantomMainAxis, setPhantomMainAxis] = useState(null); const [hoveredMainSplit, setHoveredMainSplit] = useState<{ axis: Axis; index: number } | null>(null); + // Partitions const [hoveredCell, setHoveredCell] = useState<{ i: number; j: number } | null>(null); const [hoveredPartition, setHoveredPartition] = useState<{ id: string; cellKey: string } | null>(null); - const [phantomPartition, setPhantomPartition] = useState<{ axis: Axis; offset: number } | null>(null); + const [phantomPartition, setPhantomPartition] = useState<{ axis: Axis; offset: number; min: number; max: number } | null>(null); const [selectedPartitionId, setSelectedPartitionId] = useState(null); // --- Safe Data --- @@ -49,15 +50,42 @@ export const LayoutStep: React.FC = ({ config, splits, onChange }) => { // --- Helpers --- const getSelectedPartition = () => { - if (!selectedPartitionId) return null; - for (const key in safePartitions) { - const part = safePartitions[key].find(p => p.id === selectedPartitionId); - if (part) return { key, part }; - } - return null; + if (!selectedPartitionId) return null; + for (const key in safePartitions) { + const part = safePartitions[key].find(p => p.id === selectedPartitionId); + if (part) return { key, part }; + } + return null; }; const selectedData = getSelectedPartition(); + // --- Logic: Find Sub-Area Bounds --- + // Определяет границы прямоугольника под мышкой внутри ячейки, учитывая существующие стенки + const getHoveredBoundaries = (lx: number, ly: number, parts: Partition[]) => { + let minX = 0, maxX = 1; + let minY = 0, maxY = 1; + + // Сужаем границы на основе существующих стенок + parts.forEach(p => { + if (p.axis === 'x') { + // Вертикальная стенка. Проверяем, пересекаемся ли мы с ней по Y + // (то есть мышь находится в диапазоне min/max этой стенки) + if (ly >= p.min && ly <= p.max) { + if (p.offset < lx) minX = Math.max(minX, p.offset); + if (p.offset > lx) maxX = Math.min(maxX, p.offset); + } + } else { + // Горизонтальная стенка + if (lx >= p.min && lx <= p.max) { + if (p.offset < ly) minY = Math.max(minY, p.offset); + if (p.offset > ly) maxY = Math.min(maxY, p.offset); + } + } + }); + + return { minX, maxX, minY, maxY }; + }; + // --- Actions --- const removeMainSplit = (axis: Axis, index: number) => { const newSplits = { ...splits, x: [...safeX], y: [...safeY] }; @@ -68,28 +96,33 @@ export const LayoutStep: React.FC = ({ config, splits, onChange }) => { setIsButtonHovered(false); }; - const createPartition = (i: number, j: number, axis: Axis, offset: number) => { - const key = `${i}-${j}`; - const current = safePartitions[key] || []; - const newPart: Partition = { - id: Math.random().toString(36).substr(2, 9), - axis, offset, height: config.drawer.height || 80, rounded: false - }; - onChange({ ...splits, partitions: { ...safePartitions, [key]: [...current, newPart] } }); - setSelectedPartitionId(newPart.id); + const createPartition = (i: number, j: number, axis: Axis, offset: number, min: number, max: number) => { + const key = `${i}-${j}`; + const current = safePartitions[key] || []; + const newPart: Partition = { + id: Math.random().toString(36).substr(2, 9), + axis, + offset, + min, + max, + height: config.drawer.height || 80, + rounded: false + }; + onChange({ ...splits, partitions: { ...safePartitions, [key]: [...current, newPart] } }); + setSelectedPartitionId(newPart.id); }; const updatePartition = (key: string, id: string, updates: Partial) => { - const current = safePartitions[key] || []; - const updated = current.map(p => p.id === id ? { ...p, ...updates } : p); - onChange({ ...splits, partitions: { ...safePartitions, [key]: updated } }); + const current = safePartitions[key] || []; + const updated = current.map(p => p.id === id ? { ...p, ...updates } : p); + onChange({ ...splits, partitions: { ...safePartitions, [key]: updated } }); }; const removePartition = (key: string, id: string) => { - const current = safePartitions[key] || []; - onChange({ ...splits, partitions: { ...safePartitions, [key]: current.filter(p => p.id !== id) } }); - if (selectedPartitionId === id) setSelectedPartitionId(null); - setHoveredPartition(null); + const current = safePartitions[key] || []; + onChange({ ...splits, partitions: { ...safePartitions, [key]: current.filter(p => p.id !== id) } }); + if (selectedPartitionId === id) setSelectedPartitionId(null); + setHoveredPartition(null); }; // --- Handlers --- @@ -103,94 +136,120 @@ export const LayoutStep: React.FC = ({ config, splits, onChange }) => { setMousePos({ x: nx, y: ny }); if (dragging) { - if (dragging.type === 'main') { - const newSplits = { ...splits, x: [...safeX], y: [...safeY] }; - const val = dragging.axis === 'x' ? nx : ny; - newSplits[dragging.axis][dragging.index] = val; - onChange(newSplits); + if (dragging.type === 'main') { + const newSplits = { ...splits, x: [...safeX], y: [...safeY] }; + const val = dragging.axis === 'x' ? nx : ny; + newSplits[dragging.axis][dragging.index] = val; + onChange(newSplits); + } else { + // Drag Partition + const [iStr, jStr] = dragging.cellKey.split('-'); + const i = parseInt(iStr); const j = parseInt(jStr); + const cellX1 = sortedX[i]; const cellX2 = sortedX[i+1]; + const cellY1 = sortedY[j]; const cellY2 = sortedY[j+1]; + + let newOffset = 0; + if (dragging.axis === 'x') { + newOffset = (nx - cellX1) / (cellX2 - cellX1); } else { - const [iStr, jStr] = dragging.cellKey.split('-'); - const i = parseInt(iStr); const j = parseInt(jStr); - const cellX1 = sortedX[i]; const cellX2 = sortedX[i+1]; - const cellY1 = sortedY[j]; const cellY2 = sortedY[j+1]; - let newOffset = 0; - if (dragging.axis === 'x') { - newOffset = (nx - cellX1) / (cellX2 - cellX1); - } else { - newOffset = (ny - cellY1) / (cellY2 - cellY1); - } - newOffset = Math.max(0.05, Math.min(0.95, newOffset)); - if (!isNaN(newOffset)) { - updatePartition(dragging.cellKey, dragging.id, { offset: newOffset }); - } + newOffset = (ny - cellY1) / (cellY2 - cellY1); } - return; + + // Ограничиваем перетаскивание пределами "родительской" зоны (чтобы не наехать на соседей) + // Для простоты пока ограничиваем 0.05-0.95 всей ячейки, но в идеале нужно проверять bounds + newOffset = Math.max(0.02, Math.min(0.98, newOffset)); + + if (!isNaN(newOffset)) { + updatePartition(dragging.cellKey, dragging.id, { offset: newOffset }); + } + } + return; } if (isButtonHovered) return; if (mode === 'lines') { - setHoveredMainSplit(null); - const SNAP = 0.015; - if (nx > SNAP && nx < 1-SNAP && ny > SNAP && ny < 1-SNAP) { - const closeToX = safeX.some(val => Math.abs(nx - val) < SNAP); - const closeToY = safeY.some(val => Math.abs(ny - val) < SNAP); - if (!closeToX && !closeToY) { - const distRight = 1 - nx; const distBottom = 1 - ny; - setPhantomMainAxis(Math.min(nx, distRight) < Math.min(ny, distBottom) ? 'y' : 'x'); - } else { setPhantomMainAxis(null); } - } - } else if (mode === 'cells') { - setHoveredPartition(null); - setPhantomPartition(null); - setHoveredCell(null); + setHoveredMainSplit(null); + const SNAP = 0.015; + if (nx > SNAP && nx < 1 - SNAP && ny > SNAP && ny < 1 - SNAP) { + const closeToX = safeX.some(val => Math.abs(nx - val) < SNAP); + const closeToY = safeY.some(val => Math.abs(ny - val) < SNAP); + if (!closeToX && !closeToY) { + const distRight = 1 - nx; const distBottom = 1 - ny; + setPhantomMainAxis(Math.min(nx, distRight) < Math.min(ny, distBottom) ? 'y' : 'x'); + } else { setPhantomMainAxis(null); } + } + } else { + // Cells Mode + setHoveredPartition(null); + setPhantomPartition(null); + setHoveredCell(null); - let cellIdx = null; - for(let i=0; i= sortedX[i] && nx <= sortedX[i+1]) { - for(let j=0; j= sortedY[j] && ny <= sortedY[j+1]) { - cellIdx = { i, j }; - break; - } - } + // 1. Находим ячейку + let cellIdx = null; + for (let i = 0; i < sortedX.length - 1; i++) { + if (nx >= sortedX[i] && nx <= sortedX[i+1]) { + for (let j = 0; j < sortedY.length - 1; j++) { + if (ny >= sortedY[j] && ny <= sortedY[j+1]) { + cellIdx = { i, j }; + break; } + } + } + } + + if (cellIdx) { + setHoveredCell(cellIdx); + const key = `${cellIdx.i}-${cellIdx.j}`; + const parts = safePartitions[key] || []; + + const cx1 = sortedX[cellIdx.i]; const cx2 = sortedX[cellIdx.i+1]; + const cy1 = sortedY[cellIdx.j]; const cy2 = sortedY[cellIdx.j+1]; + const cw = cx2 - cx1; const ch = cy2 - cy1; + const lx = (nx - cx1) / cw; + const ly = (ny - cy1) / ch; + + // 2. Проверяем наведение на существующие (для удаления/выделения) + let found = null; + const SNAP = 0.05; + for (const p of parts) { + // Учитываем min/max при наведении + if (p.axis === 'x') { + if (ly >= p.min && ly <= p.max && Math.abs(lx - p.offset) < SNAP * (aspectRatio > 1 ? 1 : aspectRatio)) found = p; + } else { + if (lx >= p.min && lx <= p.max && Math.abs(ly - p.offset) < SNAP * (aspectRatio < 1 ? 1 : 1/aspectRatio)) found = p; + } } - if (cellIdx) { - setHoveredCell(cellIdx); - const key = `${cellIdx.i}-${cellIdx.j}`; - const parts = safePartitions[key] || []; - - const cx1 = sortedX[cellIdx.i]; const cx2 = sortedX[cellIdx.i+1]; - const cy1 = sortedY[cellIdx.j]; const cy2 = sortedY[cellIdx.j+1]; - const cw = cx2 - cx1; const ch = cy2 - cy1; - const lx = (nx - cx1) / cw; - const ly = (ny - cy1) / ch; - - let found = null; - const SNAP = 0.05; - for (const p of parts) { - if (p.axis === 'x') { - if (Math.abs(lx - p.offset) < SNAP * (aspectRatio > 1 ? 1 : aspectRatio)) found = p; - } else { - if (Math.abs(ly - p.offset) < SNAP * (aspectRatio < 1 ? 1 : 1/aspectRatio)) found = p; - } - } - - if (found) { - setHoveredPartition({ id: found.id, cellKey: key }); - } else { - const distLeft = lx; const distRight = 1 - lx; - const distTop = ly; const distBottom = 1 - ly; - const minX = Math.min(distLeft, distRight); - const minY = Math.min(distTop, distBottom); - const axis = minX < minY ? 'y' : 'x'; - if (lx > 0.05 && lx < 0.95 && ly > 0.05 && ly < 0.95) { - setPhantomPartition({ axis, offset: axis === 'x' ? lx : ly }); - } - } + if (found) { + setHoveredPartition({ id: found.id, cellKey: key }); + } else { + // 3. Вычисляем границы для новой фантомной стенки + const bounds = getHoveredBoundaries(lx, ly, parts); + + const distL = lx - bounds.minX; + const distR = bounds.maxX - lx; + const distT = ly - bounds.minY; + const distB = bounds.maxY - ly; + + const minX = Math.min(distL, distR); + const minY = Math.min(distT, distB); + + const axis = minX < minY ? 'y' : 'x'; // Перпендикулярно ближайшему краю + + // Проверяем, чтобы было место + const width = bounds.maxX - bounds.minX; + const height = bounds.maxY - bounds.minY; + + if ((axis === 'y' && height > 0.1) || (axis === 'x' && width > 0.1)) { + const offset = axis === 'x' ? lx : ly; + const min = axis === 'x' ? bounds.minY : bounds.minX; + const max = axis === 'x' ? bounds.maxY : bounds.maxX; + + setPhantomPartition({ axis, offset, min, max }); + } } + } } }; @@ -198,55 +257,58 @@ export const LayoutStep: React.FC = ({ config, splits, onChange }) => { if (isButtonHovered) return; if (mode === 'lines') { - if (hoveredMainSplit) { - if (e.button === 0) setDragging({ type: 'main', ...hoveredMainSplit }); - else if (e.button === 2) removeMainSplit(hoveredMainSplit.axis, hoveredMainSplit.index); - } else if (phantomMainAxis) { - const val = phantomMainAxis === 'x' ? mousePos.x : mousePos.y; - const newSplits = { ...splits, x: [...safeX], y: [...safeY] }; - newSplits[phantomMainAxis] = [...newSplits[phantomMainAxis], val]; - onChange(newSplits); - setDragging({ type: 'main', axis: phantomMainAxis, index: newSplits[phantomMainAxis].length - 1 }); + if (hoveredMainSplit) { + if (e.button === 0) setDragging({ type: 'main', ...hoveredMainSplit }); + else if (e.button === 2) removeMainSplit(hoveredMainSplit.axis, hoveredMainSplit.index); + } else if (phantomMainAxis) { + const val = phantomMainAxis === 'x' ? mousePos.x : mousePos.y; + const newSplits = { ...splits, x: [...safeX], y: [...safeY] }; + newSplits[phantomMainAxis] = [...newSplits[phantomMainAxis], val]; + onChange(newSplits); + setDragging({ type: 'main', axis: phantomMainAxis, index: newSplits[phantomMainAxis].length - 1 }); + } + } else { + if (hoveredPartition) { + const key = hoveredPartition.cellKey; + const parts = safePartitions[key] || []; + const part = parts.find(p => p.id === hoveredPartition.id); + if (part) { + if (e.button === 0) { + setDragging({ type: 'partition', cellKey: key, id: part.id, axis: part.axis }); + setSelectedPartitionId(part.id); + } else if (e.button === 2) { + removePartition(key, part.id); + } } - } else if (mode === 'cells') { - if (hoveredPartition) { - const key = hoveredPartition.cellKey; - const parts = safePartitions[key] || []; - const part = parts.find(p => p.id === hoveredPartition.id); - if (part) { - if (e.button === 0) { - setDragging({ type: 'partition', cellKey: key, id: part.id, axis: part.axis }); - setSelectedPartitionId(part.id); - } else if (e.button === 2) { - removePartition(key, part.id); - } - } - } else if (hoveredCell && phantomPartition) { - if (e.button === 0) { - createPartition(hoveredCell.i, hoveredCell.j, phantomPartition.axis, phantomPartition.offset); - } - } else { - setSelectedPartitionId(null); + } else if (hoveredCell && phantomPartition) { + if (e.button === 0) { + createPartition( + hoveredCell.i, + hoveredCell.j, + phantomPartition.axis, + phantomPartition.offset, + phantomPartition.min, + phantomPartition.max + ); } + } else { + setSelectedPartitionId(null); + } } }; - // --- RENDER HELPERS --- + // --- Render --- const renderCells = () => { const elements = []; for (let i = 0; i < sortedX.length - 1; i++) { for (let j = 0; j < sortedY.length - 1; j++) { - const x1 = sortedX[i]; - const x2 = sortedX[i + 1]; - const y1 = sortedY[j]; - const y2 = sortedY[j + 1]; + const x1 = sortedX[i]; const x2 = sortedX[i + 1]; + const y1 = sortedY[j]; const y2 = sortedY[j + 1]; if (y2 === undefined || x2 === undefined) continue; - const cellX = x1 * viewBoxW; - const cellY = y1 * viewBoxH; - const cellW = (x2 - x1) * viewBoxW; - const cellH = (y2 - y1) * viewBoxH; + const cellX = x1 * viewBoxW; const cellY = y1 * viewBoxH; + const cellW = (x2 - x1) * viewBoxW; const cellH = (y2 - y1) * viewBoxH; const key = `${i}-${j}`; const isHovered = hoveredCell?.i === i && hoveredCell?.j === j && mode === 'cells'; @@ -258,18 +320,28 @@ export const LayoutStep: React.FC = ({ config, splits, onChange }) => { {isHovered && ( )} - {isSelected && mode === 'cells' && ( - - )} + {parts.map(p => { + // Рендер с учетом min/max + const pMin = p.min ?? 0; + const pMax = p.max ?? 1; + let lx1, ly1, lx2, ly2; + if (p.axis === 'x') { const px = cellX + (cellW * p.offset); - lx1 = px; ly1 = cellY; lx2 = px; ly2 = cellY + cellH; + lx1 = px; + lx2 = px; + ly1 = cellY + (cellH * pMin); + ly2 = cellY + (cellH * pMax); } else { const py = cellY + (cellH * p.offset); - lx1 = cellX; ly1 = py; lx2 = cellX + cellW; ly2 = py; + ly1 = py; + ly2 = py; + lx1 = cellX + (cellW * pMin); + lx2 = cellX + (cellW * pMax); } + const isPSelected = selectedPartitionId === p.id; const isPHovered = hoveredPartition?.id === p.id; const stroke = isPSelected ? "#a855f7" : (isPHovered ? "#d8b4fe" : "#7e22ce"); @@ -281,13 +353,28 @@ export const LayoutStep: React.FC = ({ config, splits, onChange }) => { ); })} + {isHovered && phantomPartition && !hoveredPartition && !dragging && ( - {phantomPartition.axis === 'x' ? ( - - ) : ( - - )} + {(() => { + // Рендер фантома с учетом min/max + const pMin = phantomPartition.min; + const pMax = phantomPartition.max; + + let fx1, fy1, fx2, fy2; + if (phantomPartition.axis === 'x') { + const px = cellX + (cellW * phantomPartition.offset); + fx1 = px; fx2 = px; + fy1 = cellY + (cellH * pMin); + fy2 = cellY + (cellH * pMax); + } else { + const py = cellY + (cellH * phantomPartition.offset); + fy1 = py; fy2 = py; + fx1 = cellX + (cellW * pMin); + fx2 = cellX + (cellW * pMax); + } + return ; + })()} )} @@ -299,113 +386,62 @@ export const LayoutStep: React.FC = ({ config, splits, onChange }) => { return (
- - {/* HEADER */}
-

- 2. Редактор макета -

+

2. Редактор

- - + +
- +
- {/* INSTRUCTIONS */}
{mode === 'lines' ? ( -
- ЛКМ: Линия - ПКМ: Удалить -
+
ЛКМ: ЛинияПКМ: Удалить
) : ( -
- ЛКМ в ячейке: Стенка - Драг: Двигать - 2xЛКМ: Удалить -
+
ЛКМ в ячейке: Стенка (умная)Драг: Двигать2xЛКМ: Удалить
)}
- {/* CANVAS */}
-
1 ? 'auto' : '100%', - height: aspectRatio > 1 ? '100%' : 'auto', - aspectRatio: `${1/aspectRatio}`, - maxHeight: '100%', maxWidth: '100%', - cursor: mode === 'lines' ? (dragging ? 'grabbing' : hoveredMainSplit ? 'col-resize' : 'crosshair') - : (dragging ? 'grabbing' : hoveredPartition ? 'grab' : hoveredCell ? 'crosshair' : 'default'), - }} - > +
1 ? 'auto' : '100%', height: aspectRatio > 1 ? '100%' : 'auto', aspectRatio: `${1/aspectRatio}`, maxHeight: '100%', maxWidth: '100%', cursor: mode === 'lines' ? 'crosshair' : 'default' }}> setDragging(null)} onMouseLeave={() => setDragging(null)} onContextMenu={(e) => e.preventDefault()} > - - - - - + - {renderCells()} - - {/* Main Grid Lines */} - {safeX.map((x, i) => { - const isHovered = hoveredMainSplit?.axis === 'x' && hoveredMainSplit.index === i; - return ( - { if(mode === 'lines' && !dragging) { e.stopPropagation(); setHoveredMainSplit({axis: 'x', index: i}); setPhantomMainAxis(null); }}} onDoubleClick={(e) => { e.stopPropagation(); removeMainSplit('x', i); }}> - - - - ); - })} - {safeY.map((y, i) => { - const isHovered = hoveredMainSplit?.axis === 'y' && hoveredMainSplit.index === i; - return ( - { if(mode === 'lines' && !dragging) { e.stopPropagation(); setHoveredMainSplit({axis: 'y', index: i}); setPhantomMainAxis(null); }}} onDoubleClick={(e) => { e.stopPropagation(); removeMainSplit('y', i); }}> - - - - ); - })} - - {/* Phantoms */} - {mode === 'lines' && !hoveredMainSplit && !dragging && phantomMainAxis === 'x' && } - {mode === 'lines' && !hoveredMainSplit && !dragging && phantomMainAxis === 'y' && } + {safeX.map((x, i) => ( + { if(mode === 'lines' && !dragging) { e.stopPropagation(); setHoveredMainSplit({axis: 'x', index: i}); setPhantomMainAxis(null); }}} onDoubleClick={(e) => { e.stopPropagation(); removeMainSplit('x', i); }}> + + + + ))} + {safeY.map((y, i) => ( + { if(mode === 'lines' && !dragging) { e.stopPropagation(); setHoveredMainSplit({axis: 'y', index: i}); setPhantomMainAxis(null); }}} onDoubleClick={(e) => { e.stopPropagation(); removeMainSplit('y', i); }}> + + + + ))} + {mode === 'lines' && !hoveredMainSplit && !dragging && phantomMainAxis && ( + + )}
- {/* SIDEBAR */} {mode === 'cells' && selectedData && (
-
-

Настройки стенки

- -
+

Настройки стенки

-
-
Высота {selectedData.part.height} мм
- updatePartition(selectedData.key, selectedData.part.id, { height: parseFloat(e.target.value) })} className="w-full h-1 bg-slate-600 rounded-lg appearance-none cursor-pointer accent-purple-500"/> -
-
- - updatePartition(selectedData.key, selectedData.part.id, { rounded: e.target.checked })} className="w-4 h-4 rounded bg-slate-700 border-slate-600 text-purple-500 focus:ring-0 cursor-pointer"/> -
- +
Высота {selectedData.part.height} мм
updatePartition(selectedData.key, selectedData.part.id, { height: parseFloat(e.target.value) })} className="w-full h-1 bg-slate-600 rounded-lg appearance-none cursor-pointer accent-purple-500"/>
+
updatePartition(selectedData.key, selectedData.part.id, { rounded: e.target.checked })} className="w-4 h-4 rounded bg-slate-700 border-slate-600 text-purple-500 focus:ring-0 cursor-pointer"/>
+
-
Выделите стенку для настройки.
Двойной клик удаляет её.
)}
diff --git a/src/services/geometryGenerator.ts b/src/services/geometryGenerator.ts index 584d6ac..825409a 100644 --- a/src/services/geometryGenerator.ts +++ b/src/services/geometryGenerator.ts @@ -100,13 +100,30 @@ export const createBinGeometry = ( partitions.forEach(p => { let pWidth = 0, pDepth = 0, pX = 0, pY = 0; + + const pMin = p.min ?? 0; + const pMax = p.max ?? 1; + const lengthRatio = pMax - pMin; + const midRatio = pMin + (lengthRatio / 2); + if (p.axis === 'x') { - pWidth = thickness; pDepth = innerDepth; - pX = (-innerWidth / 2) + (innerWidth * p.offset); pY = 0; + // Вертикальная стенка + pWidth = thickness; + pDepth = lengthRatio * innerDepth; + + pX = (-innerWidth / 2) + (innerWidth * p.offset); + // Центр по Z (Y в 2D) зависит от min/max + // innerTop = -innerDepth/2. Позиция = innerTop + (innerDepth * midRatio) + pY = (-innerDepth / 2) + (innerDepth * midRatio); } else { - pWidth = innerWidth; pDepth = thickness; - pX = 0; pY = (-innerDepth / 2) + (innerDepth * p.offset); + // Горизонтальная стенка + pWidth = lengthRatio * innerWidth; + pDepth = thickness; + + pX = (-innerWidth / 2) + (innerWidth * midRatio); + pY = (-innerDepth / 2) + (innerDepth * p.offset); } + const pRadius = p.rounded ? Math.min(radius, thickness / 1.5) : 0; const partShape = createRoundedRectShape(pWidth, pDepth, pRadius); const partGeo = new THREE.ExtrudeGeometry(partShape, { depth: p.height, bevelEnabled: false, curveSegments: 8 }); diff --git a/src/types.ts b/src/types.ts index caff0da..0d65891 100644 --- a/src/types.ts +++ b/src/types.ts @@ -14,7 +14,9 @@ export interface AppConfig { export interface Partition { id: string; axis: 'x' | 'y'; - offset: number; // 0.0 - 1.0 + offset: number; // Положение (0.0 - 1.0) + min: number; // Начало линии (0.0 - 1.0) + max: number; // Конец линии (0.0 - 1.0) height: number; rounded: boolean; } @@ -22,7 +24,6 @@ export interface Partition { export interface LayoutSplits { x: number[]; y: number[]; - // Ключ "i-j", Значение - массив перегородок partitions: Record; }