연속된 3point 체크 로직 수정
This commit is contained in:
parent
f79d94c1b7
commit
a05a63ebdc
@ -312,23 +312,20 @@ export function removeDuplicatePolygons(polygons) {
|
|||||||
|
|
||||||
// 같은 직선상에 있는지 확인 같은 직선이라면 polygon을 생성할 수 없으므로 false
|
// 같은 직선상에 있는지 확인 같은 직선이라면 polygon을 생성할 수 없으므로 false
|
||||||
const isValidPoints = (points) => {
|
const isValidPoints = (points) => {
|
||||||
// x값별로 점들을 그룹화
|
// 연속된 3개 이상의 점이 같은 x 또는 y 값을 가지는지 확인 (원형 배열로 처리)
|
||||||
const xGroups = {}
|
for (let i = 0; i < points.length; i++) {
|
||||||
const yGroups = {}
|
const point1 = points[i]
|
||||||
|
const point2 = points[(i + 1) % points.length]
|
||||||
|
const point3 = points[(i + 2) % points.length]
|
||||||
|
|
||||||
points.forEach(point => {
|
// x값이 같은 연속된 3개 점 확인
|
||||||
if (!xGroups[point.x]) xGroups[point.x] = []
|
if (point1.x === point2.x && point2.x === point3.x) {
|
||||||
if (!yGroups[point.y]) yGroups[point.y] = []
|
return false
|
||||||
xGroups[point.x].push(point)
|
}
|
||||||
yGroups[point.y].push(point)
|
// y값이 같은 연속된 3개 점 확인
|
||||||
})
|
if (point1.y === point2.y && point2.y === point3.y) {
|
||||||
|
return false
|
||||||
// 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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function isColinear(p1, p2, p3) {
|
function isColinear(p1, p2, p3) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user