Skip to content

Commit

Permalink
fix(core): 修复节点旋转后锚点无法被接线的问题
Browse files Browse the repository at this point in the history
isInNodeBbox 没处理旋转的场景,用的是旋转前的 bBox 进行判断。现将用于判断的点反向旋转后再进行判断

close #1871
  • Loading branch information
ZivvW authored and boyongjiong committed Dec 15, 2024
1 parent 505ba57 commit a89634e
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions packages/core/src/util/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = {
Expand Down

0 comments on commit a89634e

Please sign in to comment.