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 }