@@ -13,6 +13,7 @@ import {
13
13
} from '../model'
14
14
import { SegmentDirection } from '../constant'
15
15
import { isInSegment } from '../algorithm/edge'
16
+ import { Matrix } from './matrix'
16
17
17
18
import Point = LogicFlow . Point
18
19
import Direction = LogicFlow . Direction
@@ -112,33 +113,33 @@ export const distance = (
112
113
) : number => Math . hypot ( x1 - x2 , y1 - y2 )
113
114
114
115
/* 是否在某个节点内,手否进行连接,有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 => {
116
121
let inNode = false
117
- const offset = 0
118
122
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
+ }
119
131
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
124
136
) {
125
137
inNode = true
126
138
}
127
139
return inNode
128
140
}
129
141
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 )
142
143
}
143
144
144
145
export type NodeBBox = {
0 commit comments