3개 이상 연속점 체크 로직 수정
This commit is contained in:
parent
fb9e8386fc
commit
f79d94c1b7
@ -312,6 +312,25 @@ export function removeDuplicatePolygons(polygons) {
|
|||||||
|
|
||||||
// 같은 직선상에 있는지 확인 같은 직선이라면 polygon을 생성할 수 없으므로 false
|
// 같은 직선상에 있는지 확인 같은 직선이라면 polygon을 생성할 수 없으므로 false
|
||||||
const isValidPoints = (points) => {
|
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
|
||||||
|
}
|
||||||
|
|
||||||
function isColinear(p1, p2, p3) {
|
function isColinear(p1, p2, p3) {
|
||||||
return (p2.x - p1.x) * (p3.y - p1.y) === (p3.x - p1.x) * (p2.y - p1.y)
|
return (p2.x - p1.x) * (p3.y - p1.y) === (p3.x - p1.x) * (p2.y - p1.y)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user