From a89634e15f0f2d132ed0b2ac4c63b2fee3765fcc Mon Sep 17 00:00:00 2001 From: ZivvW <1194291667@qq.com> Date: Fri, 13 Dec 2024 14:47:34 +0800 Subject: [PATCH] =?UTF-8?q?fix(core):=20=E4=BF=AE=E5=A4=8D=E8=8A=82?= =?UTF-8?q?=E7=82=B9=E6=97=8B=E8=BD=AC=E5=90=8E=E9=94=9A=E7=82=B9=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E8=A2=AB=E6=8E=A5=E7=BA=BF=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit isInNodeBbox 没处理旋转的场景,用的是旋转前的 bBox 进行判断。现将用于判断的点反向旋转后再进行判断 close #1871 --- packages/core/src/util/node.ts | 37 +++++++++++++++++----------------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/packages/core/src/util/node.ts b/packages/core/src/util/node.ts index 65f21fe46..30ce10ef2 100644 --- a/packages/core/src/util/node.ts +++ b/packages/core/src/util/node.ts @@ -13,6 +13,7 @@ import { } from '../model' import { SegmentDirection } from '../constant' import { isInSegment } from '../algorithm/edge' +import { Matrix } from './matrix' import Point = LogicFlow.Point import Direction = LogicFlow.Direction @@ -112,33 +113,33 @@ export const distance = ( ): number => Math.hypot(x1 - x2, y1 - y2) /* 是否在某个节点内,手否进行连接,有offset控制粒度,与outline有关,可以优化 */ -export const isInNode = (position: Point, node: BaseNodeModel): boolean => { +export const isInNode = ( + position: Point, + node: BaseNodeModel, + offset = 0, +): boolean => { let inNode = false - const offset = 0 const bBox = getNodeBBox(node) + const [x, y] = new Matrix([position.x, position.y, 1]) + .translate(-node.x, -node.y) + .rotate(-node.rotate) + .translate(node.x, node.y)[0] + const reverseRotatedPosition = { + x, + y, + } if ( - position.x >= bBox.minX - offset && - position.x <= bBox.maxX + offset && - position.y >= bBox.minY - offset && - position.y <= bBox.maxY + offset + reverseRotatedPosition.x >= bBox.minX - offset && + reverseRotatedPosition.x <= bBox.maxX + offset && + reverseRotatedPosition.y >= bBox.minY - offset && + reverseRotatedPosition.y <= bBox.maxY + offset ) { inNode = true } return inNode } export const isInNodeBbox = (position: Point, node: BaseNodeModel): boolean => { - let inNode = false - const offset = 5 - const bBox = getNodeBBox(node) - if ( - position.x >= bBox.minX - offset && - position.x <= bBox.maxX + offset && - position.y >= bBox.minY - offset && - position.y <= bBox.maxY + offset - ) { - inNode = true - } - return inNode + return isInNode(position, node, 5) } export type NodeBBox = {