Skip to content

Commit a89634e

Browse files
ZivvWboyongjiong
authored andcommitted
fix(core): 修复节点旋转后锚点无法被接线的问题
isInNodeBbox 没处理旋转的场景,用的是旋转前的 bBox 进行判断。现将用于判断的点反向旋转后再进行判断 close #1871
1 parent 505ba57 commit a89634e

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

packages/core/src/util/node.ts

+19-18
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
} from '../model'
1414
import { SegmentDirection } from '../constant'
1515
import { isInSegment } from '../algorithm/edge'
16+
import { Matrix } from './matrix'
1617

1718
import Point = LogicFlow.Point
1819
import Direction = LogicFlow.Direction
@@ -112,33 +113,33 @@ export const distance = (
112113
): number => Math.hypot(x1 - x2, y1 - y2)
113114

114115
/* 是否在某个节点内,手否进行连接,有offset控制粒度,与outline有关,可以优化 */
115-
export const isInNode = (position: Point, node: BaseNodeModel): boolean => {
116+
export const isInNode = (
117+
position: Point,
118+
node: BaseNodeModel,
119+
offset = 0,
120+
): boolean => {
116121
let inNode = false
117-
const offset = 0
118122
const bBox = getNodeBBox(node)
123+
const [x, y] = new Matrix([position.x, position.y, 1])
124+
.translate(-node.x, -node.y)
125+
.rotate(-node.rotate)
126+
.translate(node.x, node.y)[0]
127+
const reverseRotatedPosition = {
128+
x,
129+
y,
130+
}
119131
if (
120-
position.x >= bBox.minX - offset &&
121-
position.x <= bBox.maxX + offset &&
122-
position.y >= bBox.minY - offset &&
123-
position.y <= bBox.maxY + offset
132+
reverseRotatedPosition.x >= bBox.minX - offset &&
133+
reverseRotatedPosition.x <= bBox.maxX + offset &&
134+
reverseRotatedPosition.y >= bBox.minY - offset &&
135+
reverseRotatedPosition.y <= bBox.maxY + offset
124136
) {
125137
inNode = true
126138
}
127139
return inNode
128140
}
129141
export const isInNodeBbox = (position: Point, node: BaseNodeModel): boolean => {
130-
let inNode = false
131-
const offset = 5
132-
const bBox = getNodeBBox(node)
133-
if (
134-
position.x >= bBox.minX - offset &&
135-
position.x <= bBox.maxX + offset &&
136-
position.y >= bBox.minY - offset &&
137-
position.y <= bBox.maxY + offset
138-
) {
139-
inNode = true
140-
}
141-
return inNode
142+
return isInNode(position, node, 5)
142143
}
143144

144145
export type NodeBBox = {

0 commit comments

Comments
 (0)