연속된 3point 체크 로직 수정
This commit is contained in:
parent
f79d94c1b7
commit
a05a63ebdc
@ -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) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user