@@ -13,6 +13,7 @@ import {
1313} from '../model'
1414import { SegmentDirection } from '../constant'
1515import { isInSegment } from '../algorithm/edge'
16+ import { Matrix } from './matrix'
1617
1718import Point = LogicFlow . Point
1819import 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}
129141export 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
144145export type NodeBBox = {
0 commit comments