첫번째 인덱스의 방향이 right 인 경우 대응
This commit is contained in:
parent
e10e0d5b58
commit
60eab96d79
@ -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 }
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user