From 60eab96d7959a89680eca1e7cbf68b50d07ccaeb Mon Sep 17 00:00:00 2001 From: "hyojun.choi" Date: Tue, 30 Jul 2024 19:55:39 +0900 Subject: [PATCH] =?UTF-8?q?=EC=B2=AB=EB=B2=88=EC=A7=B8=20=EC=9D=B8?= =?UTF-8?q?=EB=8D=B1=EC=8A=A4=EC=9D=98=20=EB=B0=A9=ED=96=A5=EC=9D=B4=20rig?= =?UTF-8?q?ht=20=EC=9D=B8=20=EA=B2=BD=EC=9A=B0=20=EB=8C=80=EC=9D=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/util/canvas-util.js | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/src/util/canvas-util.js b/src/util/canvas-util.js index d7a740ef..c8aeafe2 100644 --- a/src/util/canvas-util.js +++ b/src/util/canvas-util.js @@ -385,18 +385,37 @@ export const sortedPoints = (points) => { // copyPoint에서 x1, y1 값을 기준으로 정렬 후 첫번째 값 const startIndex = getStartIndex(copyPoints) + const startDirection = getDirectionByPoint( + { x: copyPoints[startIndex].x1, y: copyPoints[startIndex].y1 }, + { x: copyPoints[startIndex].x2, y: copyPoints[startIndex].y2 }, + ) const resultPoints = [copyPoints[startIndex]] let currentPoint = copyPoints[startIndex] - copyPoints.forEach((point, index) => { - if (index === startIndex) return + switch (startDirection) { + case 'right': { + copyPoints.forEach((point, index) => { + if (index === startIndex) return - const nextPoint = copyPoints.find((p) => p.x1 === currentPoint.x2 && p.y1 === currentPoint.y2) - resultPoints.push(nextPoint) - currentPoint = nextPoint - }) + const nextPoint = copyPoints.find((p) => p.x2 === currentPoint.x && p.y2 === currentPoint.y) + resultPoints.push(nextPoint) + currentPoint = nextPoint + }) + break + } + case 'bottom': { + copyPoints.forEach((point, index) => { + if (index === startIndex) return + + const nextPoint = copyPoints.find((p) => p.x1 === currentPoint.x2 && p.y1 === currentPoint.y2) + resultPoints.push(nextPoint) + currentPoint = nextPoint + }) + break + } + } return resultPoints.map((point) => { return { x: point.x, y: point.y }