From a05a63ebdc63b7e6f79508694d3ae9e6ff150be8 Mon Sep 17 00:00:00 2001 From: "hyojun.choi" Date: Tue, 8 Jul 2025 15:48:08 +0900 Subject: [PATCH] =?UTF-8?q?=EC=97=B0=EC=86=8D=EB=90=9C=203point=20?= =?UTF-8?q?=EC=B2=B4=ED=81=AC=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/util/qpolygon-utils.js | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/src/util/qpolygon-utils.js b/src/util/qpolygon-utils.js index 677cc09b..610d043d 100644 --- a/src/util/qpolygon-utils.js +++ b/src/util/qpolygon-utils.js @@ -312,23 +312,20 @@ export function removeDuplicatePolygons(polygons) { // 같은 직선상에 있는지 확인 같은 직선이라면 polygon을 생성할 수 없으므로 false const isValidPoints = (points) => { - // x값별로 점들을 그룹화 - const xGroups = {} - const yGroups = {} - - points.forEach(point => { - if (!xGroups[point.x]) xGroups[point.x] = [] - if (!yGroups[point.y]) yGroups[point.y] = [] - xGroups[point.x].push(point) - yGroups[point.y].push(point) - }) - - // 3개 이상 같은 x 또는 y 값을 가지는 점이 있는지 확인 - for (const x in xGroups) { - if (xGroups[x].length >= 3) return false - } - for (const y in yGroups) { - if (yGroups[y].length >= 3) return false + // 연속된 3개 이상의 점이 같은 x 또는 y 값을 가지는지 확인 (원형 배열로 처리) + for (let i = 0; i < points.length; i++) { + const point1 = points[i] + const point2 = points[(i + 1) % points.length] + const point3 = points[(i + 2) % points.length] + + // x값이 같은 연속된 3개 점 확인 + if (point1.x === point2.x && point2.x === point3.x) { + return false + } + // y값이 같은 연속된 3개 점 확인 + if (point1.y === point2.y && point2.y === point3.y) { + return false + } } function isColinear(p1, p2, p3) {