From 3432d64a3ca1a6c117d78c08245a2ee17e993dab Mon Sep 17 00:00:00 2001 From: "hyojun.choi" Date: Tue, 18 Mar 2025 10:23:42 +0900 Subject: [PATCH] =?UTF-8?q?8=EA=B0=81=20=EC=95=88=EB=82=98=EB=88=A0?= =?UTF-8?q?=EC=A7=80=EB=8A=94=20=ED=98=84=EC=83=81=20=EC=9E=91=EC=97=85=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/usePolygon.js | 2 +- src/util/canvas-util.js | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/hooks/usePolygon.js b/src/hooks/usePolygon.js index 54de877b..fd5b5a69 100644 --- a/src/hooks/usePolygon.js +++ b/src/hooks/usePolygon.js @@ -767,7 +767,7 @@ export const usePolygon = () => { obj.type === 'QLine' && obj.attributes?.type !== 'pitchSizeLine' && obj.attributes?.roofId === polygon.id && - (innerLineTypes.includes(obj.name) || !obj.name), + innerLineTypes.includes(obj.name), ) innerLines = [...polygon.innerLines] diff --git a/src/util/canvas-util.js b/src/util/canvas-util.js index 935097b0..1146afa7 100644 --- a/src/util/canvas-util.js +++ b/src/util/canvas-util.js @@ -518,14 +518,23 @@ export const sortedPointLessEightPoint = (points) => { */ // 직선의 방정식. // 방정식은 ax + by + c = 0이며, 점의 좌표를 대입하여 계산된 값은 직선과 점 사이의 관계를 나타낸다. -export function isPointOnLine(line, point) { - const a = line.y2 - line.y1 +export function isPointOnLine({ x1, y1, x2, y2 }, { x, y }) { + /*const a = line.y2 - line.y1 const b = line.x1 - line.x2 const c = line.x2 * line.y1 - line.x1 * line.y2 const result = Math.abs(a * point.x + b * point.y + c) / 100 // 점이 선 위에 있는지 확인 - return result <= 10 + return result <= 10*/ + // 직선 방정식 만족 여부 확인 + const crossProduct = (y - y1) * (x2 - x1) - (x - x1) * (y2 - y1) + if (Math.abs(crossProduct) > 5) return false // 작은 오차 허용 + + // 점이 선분의 범위 내에 있는지 확인 + const withinXRange = Math.min(x1, x2) <= x && x <= Math.max(x1, x2) + const withinYRange = Math.min(y1, y2) <= y && y <= Math.max(y1, y2) + + return withinXRange && withinYRange } /** * 점과 가까운 line 찾기