roofPoints valid 체크 추가

This commit is contained in:
hyojun.choi 2025-05-07 11:21:26 +09:00
parent 92c33c9c11
commit 381c639d18

View File

@ -294,7 +294,7 @@ function arePolygonsEqual(polygon1, polygon2) {
}
export function removeDuplicatePolygons(polygons) {
const uniquePolygons = []
let uniquePolygons = []
polygons.forEach((polygon) => {
const isDuplicate = uniquePolygons.some((uniquePolygon) => arePolygonsEqual(polygon, uniquePolygon))
@ -304,12 +304,32 @@ export function removeDuplicatePolygons(polygons) {
})
// x가 전부 같거나, y가 전부 같은 경우 제거
return uniquePolygons.filter((polygon) => {
const xValues = polygon.map((point) => point.x)
const yValues = polygon.map((point) => point.y)
return !(xValues.every((x) => x === xValues[0]) || yValues.every((y) => y === yValues[0]))
uniquePolygons = uniquePolygons.filter((polygon) => {
return isValidPoints(polygon)
})
return uniquePolygons
}
// 현재 point의 x와 이전 포인트의 x와 같을경우, 다음 포인트의 x와 달라야 함.
// 현재 point의 y와 이전 포인트의 y와 같을경우, 다음 포인트의 y와 달라야 함.
const isValidPoints = (points) => {
for (let i = 1; i < points.length - 1; i++) {
const prev = points[i - 1]
const curr = points[i]
const next = points[i + 1]
// 현재와 이전의 x가 같다면 다음의 x는 달라야 함
if (curr.x === prev.x && curr.x === next.x) {
return false
}
// 현재와 이전의 y가 같다면 다음의 y는 달라야 함
if (curr.y === prev.y && curr.y === next.y) {
return false
}
}
return true
}
export const isSamePoint = (a, b) => {