From 516d3b32a18a76c89365e3d62c42e74d320fbd5f Mon Sep 17 00:00:00 2001 From: "hyojun.choi" Date: Mon, 9 Mar 2026 10:05:39 +0900 Subject: [PATCH] =?UTF-8?q?#1526=20=EB=B3=B4=EC=A1=B0=EC=84=A0=20=EC=9D=B4?= =?UTF-8?q?=EC=9A=A9=ED=95=B4=EC=84=9C=20=ED=95=A0=EB=8B=B9=20=EC=8B=9C=20?= =?UTF-8?q?=EA=B8=B8=EC=9D=B4=20=EA=B3=84=EC=82=B0=20=EC=95=88=EB=90=98?= =?UTF-8?q?=EB=8A=94=20=ED=98=84=EC=83=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/usePolygon.js | 79 ++++++++++++++++++++++++++++++++--------- 1 file changed, 63 insertions(+), 16 deletions(-) diff --git a/src/hooks/usePolygon.js b/src/hooks/usePolygon.js index 40a3d85f..3a83c947 100644 --- a/src/hooks/usePolygon.js +++ b/src/hooks/usePolygon.js @@ -1023,6 +1023,9 @@ export const usePolygon = () => { const line = divideLines[i] const { intersections, startPoint, endPoint } = line + // 원본 라인의 기하학적 길이 (비율 계산용) + const originalGeomLength = Math.round(Math.hypot(line.x2 - line.x1, line.y2 - line.y1)) * 10 + if (intersections.length === 1) { const newLinePoint1 = [line.x1, line.y1, intersections[0].x, intersections[0].y] const newLinePoint2 = [intersections[0].x, intersections[0].y, line.x2, line.y2] @@ -1042,25 +1045,43 @@ export const usePolygon = () => { name: 'newLine', }) - // 두 라인 중 큰 길이로 통일 + // 분할된 각 세그먼트의 기하학적 길이 const length1 = Math.round(Math.hypot(newLine1.x1 - newLine1.x2, newLine1.y1 - newLine1.y2)) * 10 const length2 = Math.round(Math.hypot(newLine2.x1 - newLine2.x2, newLine2.y1 - newLine2.y2)) * 10 - const maxLength = Math.max(length1, length2) - const unifiedPlaneSize = line.attributes.planeSize ?? maxLength - const unifiedActualSize = line.attributes.actualSize ?? maxLength + + // 원본에 planeSize/actualSize가 있으면 비율로 분배, 없으면 기하학적 길이 사용 + let planeSize1, planeSize2, actualSize1, actualSize2 + if (line.attributes.planeSize && originalGeomLength > 0) { + const ratio1 = length1 / originalGeomLength + const ratio2 = length2 / originalGeomLength + planeSize1 = Math.round(line.attributes.planeSize * ratio1) + planeSize2 = Math.round(line.attributes.planeSize * ratio2) + } else { + planeSize1 = length1 + planeSize2 = length2 + } + if (line.attributes.actualSize && originalGeomLength > 0) { + const ratio1 = length1 / originalGeomLength + const ratio2 = length2 / originalGeomLength + actualSize1 = Math.round(line.attributes.actualSize * ratio1) + actualSize2 = Math.round(line.attributes.actualSize * ratio2) + } else { + actualSize1 = length1 + actualSize2 = length2 + } newLine1.attributes = { ...line.attributes, - planeSize: unifiedPlaneSize, - actualSize: unifiedActualSize, + planeSize: planeSize1, + actualSize: actualSize1, } - newLine1.length = maxLength + newLine1.length = length1 newLine2.attributes = { ...line.attributes, - planeSize: unifiedPlaneSize, - actualSize: unifiedActualSize, + planeSize: planeSize2, + actualSize: actualSize2, } - newLine2.length = maxLength + newLine2.length = length2 newLines.push(newLine1, newLine2) divideLines.splice(i, 1) // 기존 line 제거 @@ -1080,12 +1101,25 @@ export const usePolygon = () => { }) const calcLength = Math.round(Math.hypot(newLine.x1 - newLine.x2, newLine.y1 - newLine.y2)) * 10 + + let segPlaneSize, segActualSize + if (line.attributes.planeSize && originalGeomLength > 0) { + segPlaneSize = Math.round(line.attributes.planeSize * (calcLength / originalGeomLength)) + } else { + segPlaneSize = calcLength + } + if (line.attributes.actualSize && originalGeomLength > 0) { + segActualSize = Math.round(line.attributes.actualSize * (calcLength / originalGeomLength)) + } else { + segActualSize = calcLength + } + newLine.attributes = { ...line.attributes, - planeSize: line.attributes.planeSize ?? calcLength, - actualSize: line.attributes.actualSize ?? calcLength, + planeSize: segPlaneSize, + actualSize: segActualSize, } - newLine.length = line.attributes.planeSize ?? calcLength + newLine.length = calcLength newLines.push(newLine) currentPoint = minDistancePoint @@ -1100,12 +1134,25 @@ export const usePolygon = () => { name: 'newLine', }) const lastCalcLength = Math.round(Math.hypot(newLine.x1 - newLine.x2, newLine.y1 - newLine.y2)) * 10 + + let lastPlaneSize, lastActualSize + if (line.attributes.planeSize && originalGeomLength > 0) { + lastPlaneSize = Math.round(line.attributes.planeSize * (lastCalcLength / originalGeomLength)) + } else { + lastPlaneSize = lastCalcLength + } + if (line.attributes.actualSize && originalGeomLength > 0) { + lastActualSize = Math.round(line.attributes.actualSize * (lastCalcLength / originalGeomLength)) + } else { + lastActualSize = lastCalcLength + } + newLine.attributes = { ...line.attributes, - planeSize: line.attributes.planeSize ?? lastCalcLength, - actualSize: line.attributes.actualSize ?? lastCalcLength, + planeSize: lastPlaneSize, + actualSize: lastActualSize, } - newLine.length = line.attributes.planeSize ?? lastCalcLength + newLine.length = lastCalcLength newLines.push(newLine) divideLines.splice(i, 1) // 기존 line 제거