roof 나눌때 point 중복 제거
This commit is contained in:
parent
8da2ab0820
commit
78258fc9c1
@ -296,6 +296,7 @@ function arePolygonsEqual(polygon1, polygon2) {
|
||||
export function removeDuplicatePolygons(polygons) {
|
||||
let uniquePolygons = []
|
||||
|
||||
// x가 전부 같거나, y가 전부 같은 경우 제거
|
||||
polygons.forEach((polygon) => {
|
||||
const isDuplicate = uniquePolygons.some((uniquePolygon) => arePolygonsEqual(polygon, uniquePolygon))
|
||||
if (!isDuplicate) {
|
||||
@ -303,7 +304,6 @@ export function removeDuplicatePolygons(polygons) {
|
||||
}
|
||||
})
|
||||
|
||||
// x가 전부 같거나, y가 전부 같은 경우 제거
|
||||
uniquePolygons = uniquePolygons.filter((polygon) => {
|
||||
return isValidPoints(polygon)
|
||||
})
|
||||
@ -314,18 +314,24 @@ export function removeDuplicatePolygons(polygons) {
|
||||
// 현재 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]
|
||||
for (let i = 1; i < points.length; i++) {
|
||||
let prev = points[i - 1]
|
||||
let curr = points[i]
|
||||
let next = points[i + 1]
|
||||
|
||||
if (i === points.length - 1) {
|
||||
prev = points[i - 1]
|
||||
curr = points[i]
|
||||
next = points[0]
|
||||
}
|
||||
|
||||
// 현재와 이전의 x가 같다면 다음의 x는 달라야 함
|
||||
if (curr.x === prev.x && curr.x === next.x) {
|
||||
if (Math.abs(curr.x - prev.x) < 1 && Math.abs(curr.x - next.x) < 1) {
|
||||
return false
|
||||
}
|
||||
|
||||
// 현재와 이전의 y가 같다면 다음의 y는 달라야 함
|
||||
if (curr.y === prev.y && curr.y === next.y) {
|
||||
if (Math.abs(curr.y - prev.y) < 1 && Math.abs(curr.y - next.y) < 1) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user