첫번째 인덱스의 방향이 right 인 경우 대응

This commit is contained in:
hyojun.choi 2024-07-30 19:55:39 +09:00
parent e10e0d5b58
commit 60eab96d79

View File

@ -385,18 +385,37 @@ export const sortedPoints = (points) => {
// copyPoint에서 x1, y1 값을 기준으로 정렬 후 첫번째 값 // copyPoint에서 x1, y1 값을 기준으로 정렬 후 첫번째 값
const startIndex = getStartIndex(copyPoints) 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]] const resultPoints = [copyPoints[startIndex]]
let currentPoint = copyPoints[startIndex] let currentPoint = copyPoints[startIndex]
copyPoints.forEach((point, index) => { switch (startDirection) {
if (index === startIndex) return case 'right': {
copyPoints.forEach((point, index) => {
if (index === startIndex) return
const nextPoint = copyPoints.find((p) => p.x1 === currentPoint.x2 && p.y1 === currentPoint.y2) const nextPoint = copyPoints.find((p) => p.x2 === currentPoint.x && p.y2 === currentPoint.y)
resultPoints.push(nextPoint) resultPoints.push(nextPoint)
currentPoint = 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 resultPoints.map((point) => {
return { x: point.x, y: point.y } return { x: point.x, y: point.y }