From c60db3cda56005746c34a3fc55f97cf1bde819c0 Mon Sep 17 00:00:00 2001 From: "hyojun.choi" Date: Mon, 4 Nov 2024 15:07:27 +0900 Subject: [PATCH] =?UTF-8?q?=EA=B0=99=EC=9D=80=EC=A2=8C=ED=91=9C=ED=8C=90?= =?UTF-8?q?=EB=8B=A8=201=EC=98=A4=EC=B0=A8=20=ED=97=88=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/util/qpolygon-utils.js | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/util/qpolygon-utils.js b/src/util/qpolygon-utils.js index 65cbc96d..a574c393 100644 --- a/src/util/qpolygon-utils.js +++ b/src/util/qpolygon-utils.js @@ -1380,22 +1380,27 @@ export const splitPolygonWithLines = (polygon) => { }) } -const removeDuplicatePolygons = (polygons) => { +function normalizePoint(point) { + return { + x: Math.round(point.x), + y: Math.round(point.y), + } +} + +function arePolygonsEqual(polygon1, polygon2) { + if (polygon1.length !== polygon2.length) return false + + const normalizedPolygon1 = polygon1.map(normalizePoint).sort((a, b) => a.x - b.x || a.y - b.y) + const normalizedPolygon2 = polygon2.map(normalizePoint).sort((a, b) => a.x - b.x || a.y - b.y) + + return normalizedPolygon1.every((point, index) => arePointsEqual(point, normalizedPolygon2[index])) +} + +function removeDuplicatePolygons(polygons) { const uniquePolygons = [] polygons.forEach((polygon) => { - const sortedPolygon = polygon - .map((point) => `${Math.floor(point.x)},${Math.floor(point.y)}`) - .sort() - .join('|') - const isDuplicate = uniquePolygons.some((uniquePolygon) => { - const sortedUniquePolygon = uniquePolygon - .map((point) => `${Math.floor(point.x)},${Math.floor(point.y)}`) - .sort() - .join('|') - return sortedPolygon === sortedUniquePolygon - }) - + const isDuplicate = uniquePolygons.some((uniquePolygon) => arePolygonsEqual(polygon, uniquePolygon)) if (!isDuplicate) { uniquePolygons.push(polygon) } @@ -3551,7 +3556,7 @@ function createRoofPaddingPolygon(polygon, lines, arcSegments = 0) { } function arePointsEqual(point1, point2) { - return Math.abs(point1.x - point2.x) < 1 && Math.abs(point1.y - point2.y) - 1 + return Math.abs(point1.x - point2.x) <= 1 && Math.abs(point1.y - point2.y) <= 1 } function arraysHaveSamePoints(array1, array2) {