From 78258fc9c10e9a58695843112851a0a3917061d5 Mon Sep 17 00:00:00 2001 From: "hyojun.choi" Date: Wed, 7 May 2025 15:05:44 +0900 Subject: [PATCH] =?UTF-8?q?roof=20=EB=82=98=EB=88=8C=EB=95=8C=20point=20?= =?UTF-8?q?=EC=A4=91=EB=B3=B5=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/util/qpolygon-utils.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/util/qpolygon-utils.js b/src/util/qpolygon-utils.js index b1cf5ae1..d9923616 100644 --- a/src/util/qpolygon-utils.js +++ b/src/util/qpolygon-utils.js @@ -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 } }