Merge branch 'feature/test' into test-yj
This commit is contained in:
commit
dc4930af55
@ -23,6 +23,7 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"postcss": "^8",
|
"postcss": "^8",
|
||||||
|
"prettier": "^3.3.3",
|
||||||
"prisma": "^5.17.0",
|
"prisma": "^5.17.0",
|
||||||
"tailwindcss": "^3.4.1"
|
"tailwindcss": "^3.4.1"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -422,6 +422,68 @@ export const sortedPoints = (points) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const sortedPointLessEightPoint = (points) => {
|
||||||
|
const copyPoints = [...points]
|
||||||
|
//points를 x,y좌표를 기준으로 정렬합니다.
|
||||||
|
copyPoints.sort((a, b) => {
|
||||||
|
if (a.x === b.x) {
|
||||||
|
return a.y - b.y
|
||||||
|
}
|
||||||
|
return a.x - b.x
|
||||||
|
})
|
||||||
|
|
||||||
|
const resultPoints = [copyPoints[0]]
|
||||||
|
let index = 1
|
||||||
|
let currentPoint = { ...copyPoints[0] }
|
||||||
|
copyPoints.splice(0, 1)
|
||||||
|
while (index < points.length) {
|
||||||
|
if (index === points.length - 1) {
|
||||||
|
resultPoints.push(copyPoints[0])
|
||||||
|
index++
|
||||||
|
break
|
||||||
|
} else if (index % 2 === 0) {
|
||||||
|
// 짝수번째는 y값이 같은 점을 찾는다.
|
||||||
|
for (let i = 0; i < copyPoints.length; i++) {
|
||||||
|
// y값이 같은 point가 많은 경우 그 중 x값이 가장 큰걸 찾는다.
|
||||||
|
let temp = copyPoints.filter((point) => point.y === currentPoint.y)
|
||||||
|
if (temp.length === 0) {
|
||||||
|
// temp가 비어있을 경우 copyPoints에서 가장 가까운 점을 찾는다.
|
||||||
|
temp = Array.of(findClosestPointByY(currentPoint, copyPoints))
|
||||||
|
}
|
||||||
|
// temp중 x값이 가장 가까운 값
|
||||||
|
|
||||||
|
const min = temp.reduce((prev, current) => (Math.abs(current.x - currentPoint.x) <= Math.abs(prev.x - currentPoint.x) ? current : prev))
|
||||||
|
|
||||||
|
resultPoints.push(min)
|
||||||
|
currentPoint = min
|
||||||
|
copyPoints.splice(copyPoints.indexOf(min), 1)
|
||||||
|
index++
|
||||||
|
break
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 홀수번째는 x값이 같은 점을 찾는다.
|
||||||
|
for (let i = 0; i < copyPoints.length; i++) {
|
||||||
|
// x값이 같은 point가 많은 경우 그 중 y값이 가장 큰걸 찾는다.
|
||||||
|
let temp = copyPoints.filter((point) => point.x === currentPoint.x)
|
||||||
|
if (temp.length === 0) {
|
||||||
|
// temp가 비어있을 경우 copyPoints에서 가장 가까운 점을 찾는다.
|
||||||
|
|
||||||
|
temp = Array.of(findClosestPointByX(currentPoint, copyPoints))
|
||||||
|
}
|
||||||
|
// temp중 y값이 가장 가까운 값
|
||||||
|
const min = temp.reduce((prev, current) => (Math.abs(current.y - currentPoint.y) <= Math.abs(prev.y - currentPoint.y) ? current : prev))
|
||||||
|
|
||||||
|
resultPoints.push(min)
|
||||||
|
currentPoint = min
|
||||||
|
copyPoints.splice(copyPoints.indexOf(min), 1)
|
||||||
|
index++
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return resultPoints
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* point가 선 위에 있는지 확인
|
* point가 선 위에 있는지 확인
|
||||||
* @param line
|
* @param line
|
||||||
|
|||||||
@ -3221,6 +3221,11 @@ postcss@^8, postcss@^8.4.23:
|
|||||||
picocolors "^1.0.0"
|
picocolors "^1.0.0"
|
||||||
source-map-js "^1.2.0"
|
source-map-js "^1.2.0"
|
||||||
|
|
||||||
|
prettier@^3.3.3:
|
||||||
|
version "3.3.3"
|
||||||
|
resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.3.3.tgz#30c54fe0be0d8d12e6ae61dbb10109ea00d53105"
|
||||||
|
integrity sha512-i2tDNA0O5IrMO757lfrdQZCc2jPNDVntV0m/+4whiDfWaTKfMNgR7Qz0NAeGz/nRqF4m5/6CLzbP4/liHt12Ew==
|
||||||
|
|
||||||
prisma@^5.17.0:
|
prisma@^5.17.0:
|
||||||
version "5.17.0"
|
version "5.17.0"
|
||||||
resolved "https://registry.yarnpkg.com/prisma/-/prisma-5.17.0.tgz#267b43921ab94805b010537cffa5ccaf530fa066"
|
resolved "https://registry.yarnpkg.com/prisma/-/prisma-5.17.0.tgz#267b43921ab94805b010537cffa5ccaf530fa066"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user