@logicflow/extension 2.2.0-alpha.7 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -0
- package/package.json +10 -7
- package/.turbo/turbo-build.log +0 -38
- package/CHANGELOG.md +0 -1829
- package/__test__/bpmn-adapter.test.js +0 -227
- package/es/materials/curved-edge/__test__/curved-edge.test.d.ts +0 -1
- package/es/materials/curved-edge/__test__/curved-edge.test.js +0 -18
- package/jest.config.js +0 -198
- package/lib/materials/curved-edge/__test__/curved-edge.test.d.ts +0 -1
- package/lib/materials/curved-edge/__test__/curved-edge.test.js +0 -20
- package/rollup.config.js +0 -52
- package/src/NodeResize/BasicShape/Ellipse.tsx +0 -22
- package/src/NodeResize/BasicShape/Polygon.tsx +0 -24
- package/src/NodeResize/BasicShape/Rect.tsx +0 -44
- package/src/NodeResize/control/Control.tsx +0 -537
- package/src/NodeResize/control/ControlGroup.tsx +0 -76
- package/src/NodeResize/control/Util.ts +0 -206
- package/src/NodeResize/index.ts +0 -26
- package/src/NodeResize/node/DiamondResize.tsx +0 -149
- package/src/NodeResize/node/EllipseResize.tsx +0 -140
- package/src/NodeResize/node/HtmlResize.tsx +0 -125
- package/src/NodeResize/node/RectResize.tsx +0 -126
- package/src/NodeResize/node/index.ts +0 -4
- package/src/bpmn/constant.ts +0 -56
- package/src/bpmn/events/EndEvent.ts +0 -73
- package/src/bpmn/events/StartEvent.ts +0 -52
- package/src/bpmn/events/index.ts +0 -2
- package/src/bpmn/flow/SequenceFlow.ts +0 -25
- package/src/bpmn/flow/index.ts +0 -1
- package/src/bpmn/gateways/ExclusiveGateway.ts +0 -71
- package/src/bpmn/gateways/index.ts +0 -1
- package/src/bpmn/getBpmnId.ts +0 -31
- package/src/bpmn/index.ts +0 -60
- package/src/bpmn/tasks/ServiceTask.ts +0 -63
- package/src/bpmn/tasks/UserTask.ts +0 -64
- package/src/bpmn/tasks/index.ts +0 -2
- package/src/bpmn-adapter/bpmnIds.ts +0 -31
- package/src/bpmn-adapter/index.ts +0 -835
- package/src/bpmn-adapter/json2xml.ts +0 -127
- package/src/bpmn-adapter/xml2json.ts +0 -544
- package/src/bpmn-elements/README.md +0 -223
- package/src/bpmn-elements/__tests__/definition.test.js +0 -72
- package/src/bpmn-elements/index.d.ts +0 -26
- package/src/bpmn-elements/index.ts +0 -107
- package/src/bpmn-elements/presets/Event/EndEventFactory.ts +0 -114
- package/src/bpmn-elements/presets/Event/IntermediateCatchEvent.ts +0 -108
- package/src/bpmn-elements/presets/Event/IntermediateThrowEvent.ts +0 -109
- package/src/bpmn-elements/presets/Event/StartEventFactory.ts +0 -114
- package/src/bpmn-elements/presets/Event/boundaryEventFactory.ts +0 -117
- package/src/bpmn-elements/presets/Event/index.ts +0 -14
- package/src/bpmn-elements/presets/Flow/flow.d.ts +0 -6
- package/src/bpmn-elements/presets/Flow/index.ts +0 -8
- package/src/bpmn-elements/presets/Flow/manhattan.ts +0 -691
- package/src/bpmn-elements/presets/Flow/sequenceFlow.ts +0 -65
- package/src/bpmn-elements/presets/Gateway/gateway.ts +0 -107
- package/src/bpmn-elements/presets/Gateway/index.ts +0 -23
- package/src/bpmn-elements/presets/Pool/Lane.ts +0 -211
- package/src/bpmn-elements/presets/Pool/Pool.ts +0 -284
- package/src/bpmn-elements/presets/Pool/index.ts +0 -89
- package/src/bpmn-elements/presets/Task/index.ts +0 -122
- package/src/bpmn-elements/presets/Task/subProcess.ts +0 -189
- package/src/bpmn-elements/presets/Task/task.ts +0 -193
- package/src/bpmn-elements/presets/icons.ts +0 -155
- package/src/bpmn-elements/utils.ts +0 -52
- package/src/bpmn-elements-adapter/README.md +0 -293
- package/src/bpmn-elements-adapter/__tests__/adapter_in.test.js +0 -528
- package/src/bpmn-elements-adapter/__tests__/adapter_out.test.js +0 -569
- package/src/bpmn-elements-adapter/constant.ts +0 -76
- package/src/bpmn-elements-adapter/index.ts +0 -1134
- package/src/bpmn-elements-adapter/json2xml.ts +0 -105
- package/src/bpmn-elements-adapter/xml2json.ts +0 -542
- package/src/components/context-menu/index.ts +0 -253
- package/src/components/control/index.ts +0 -155
- package/src/components/dnd-panel/index.ts +0 -137
- package/src/components/highlight/index.ts +0 -227
- package/src/components/menu/index.ts +0 -748
- package/src/components/mini-map/index.ts +0 -686
- package/src/components/selection-select/index.ts +0 -387
- package/src/dynamic-group/index.ts +0 -774
- package/src/dynamic-group/model.ts +0 -580
- package/src/dynamic-group/node.ts +0 -288
- package/src/dynamic-group/utils.ts +0 -46
- package/src/index.less +0 -1
- package/src/index.ts +0 -47
- package/src/insert-node-in-polyline/edge.ts +0 -175
- package/src/insert-node-in-polyline/index.ts +0 -193
- package/src/materials/curved-edge/__test__/curved-edge.test.ts +0 -46
- package/src/materials/curved-edge/index.ts +0 -217
- package/src/materials/group/GroupNode.ts +0 -437
- package/src/materials/group/index.ts +0 -542
- package/src/materials/node-selection/index.ts +0 -380
- package/src/mindmap/fakerRoot.ts +0 -19
- package/src/mindmap/index.ts +0 -328
- package/src/mindmap/markContent.ts +0 -81
- package/src/mindmap/markContentOption.ts +0 -81
- package/src/mindmap/markEntity.ts +0 -82
- package/src/mindmap/markRoot.ts +0 -83
- package/src/mindmap/theme.ts +0 -11
- package/src/pool/LaneModel.ts +0 -226
- package/src/pool/LaneView.ts +0 -220
- package/src/pool/PoolModel.ts +0 -631
- package/src/pool/PoolView.ts +0 -75
- package/src/pool/constant.ts +0 -19
- package/src/pool/index.ts +0 -621
- package/src/pool/utils.ts +0 -46
- package/src/rect-label-node/RectLabelNodeView.ts +0 -33
- package/src/rect-label-node/index.ts +0 -15
- package/src/style/index.less +0 -381
- package/src/style/raw.ts +0 -328
- package/src/tools/auto-layout/index.ts +0 -282
- package/src/tools/flow-path/index.ts +0 -233
- package/src/tools/label/Label.tsx +0 -357
- package/src/tools/label/LabelModel.ts +0 -83
- package/src/tools/label/LabelOverlay.tsx +0 -162
- package/src/tools/label/algorithm.ts +0 -42
- package/src/tools/label/index.ts +0 -479
- package/src/tools/label/mediumEditor.ts +0 -121
- package/src/tools/label/utils.ts +0 -395
- package/src/tools/proximity-connect/index.ts +0 -435
- package/src/tools/snapshot/README.md +0 -145
- package/src/tools/snapshot/index.ts +0 -701
- package/src/tools/snapshot/utils.ts +0 -163
- package/src/turbo-adapter/index.ts +0 -212
- package/stats.html +0 -4842
- package/tsconfig.json +0 -18
|
@@ -1,691 +0,0 @@
|
|
|
1
|
-
import { BBoxType } from './flow'
|
|
2
|
-
import LogicFlow from '@logicflow/core'
|
|
3
|
-
|
|
4
|
-
import Point = LogicFlow.Point
|
|
5
|
-
|
|
6
|
-
class NodeBase {
|
|
7
|
-
x: any
|
|
8
|
-
y: any
|
|
9
|
-
G: number
|
|
10
|
-
H: number
|
|
11
|
-
isProcessed: boolean
|
|
12
|
-
connection: any
|
|
13
|
-
from: any
|
|
14
|
-
|
|
15
|
-
constructor(x: number, y: number) {
|
|
16
|
-
this.x = x
|
|
17
|
-
this.y = y
|
|
18
|
-
this.G = 0
|
|
19
|
-
this.H = 0
|
|
20
|
-
this.isProcessed = false
|
|
21
|
-
this.connection = null
|
|
22
|
-
this.from = null
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
get F() {
|
|
26
|
-
return this.G + this.H
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
setProcessed() {
|
|
30
|
-
this.isProcessed = true
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
setConnection(connection: any) {
|
|
34
|
-
this.connection = connection
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
setFrom(from: any) {
|
|
38
|
-
this.from = from
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
setG(g: number) {
|
|
42
|
-
this.G = g
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
setH(h: number) {
|
|
46
|
-
this.H = h
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
getManhattanDistanceTo(point: { x: number; y: number }) {
|
|
50
|
-
const { x: x1, y: y1 } = this
|
|
51
|
-
const { x: x2, y: y2 } = point
|
|
52
|
-
return Math.abs(x1 - x2) + Math.abs(y1 - y2)
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export class PriorityQueue {
|
|
57
|
-
heap: any[]
|
|
58
|
-
|
|
59
|
-
constructor() {
|
|
60
|
-
this.heap = []
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
enqueue(node: { x: never; y: never }, priority: number) {
|
|
64
|
-
this.heap.push({
|
|
65
|
-
node,
|
|
66
|
-
priority,
|
|
67
|
-
})
|
|
68
|
-
this.bubbleUp(this.heap.length - 1)
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
dequeue() {
|
|
72
|
-
const min = this.heap[0]
|
|
73
|
-
const end = this.heap.pop()
|
|
74
|
-
if (this.heap.length > 0) {
|
|
75
|
-
this.heap[0] = end
|
|
76
|
-
this.sinkDown(0)
|
|
77
|
-
}
|
|
78
|
-
return min
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
bubbleUp(index: number) {
|
|
82
|
-
const node = this.heap[index]
|
|
83
|
-
while (index > 0) {
|
|
84
|
-
const parentIndex = Math.floor((index - 1) / 2)
|
|
85
|
-
const parent = this.heap[parentIndex]
|
|
86
|
-
if (node.priority >= parent.priority) break
|
|
87
|
-
this.heap[parentIndex] = node
|
|
88
|
-
this.heap[index] = parent
|
|
89
|
-
index = parentIndex
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
sinkDown(index: number) {
|
|
94
|
-
const leftChildIndex = 2 * index + 1
|
|
95
|
-
const rightChildIndex = 2 * index + 2
|
|
96
|
-
let smallestChildIndex = index
|
|
97
|
-
const { length } = this.heap
|
|
98
|
-
|
|
99
|
-
if (
|
|
100
|
-
leftChildIndex < length &&
|
|
101
|
-
this.heap[leftChildIndex].priority <
|
|
102
|
-
this.heap[smallestChildIndex].priority
|
|
103
|
-
) {
|
|
104
|
-
smallestChildIndex = leftChildIndex
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if (
|
|
108
|
-
rightChildIndex < length &&
|
|
109
|
-
this.heap[rightChildIndex].priority <
|
|
110
|
-
this.heap[smallestChildIndex].priority
|
|
111
|
-
) {
|
|
112
|
-
smallestChildIndex = rightChildIndex
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
if (smallestChildIndex !== index) {
|
|
116
|
-
const swapNode = this.heap[smallestChildIndex]
|
|
117
|
-
this.heap[smallestChildIndex] = this.heap[index]
|
|
118
|
-
this.heap[index] = swapNode
|
|
119
|
-
this.sinkDown(smallestChildIndex)
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
isEmpty() {
|
|
124
|
-
return this.heap.length === 0
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
function expandBBox(bbox: BBoxType, offset: number) {
|
|
129
|
-
const { minX, minY, maxX, maxY } = bbox
|
|
130
|
-
return {
|
|
131
|
-
minX: minX - offset,
|
|
132
|
-
minY: minY - offset,
|
|
133
|
-
maxX: maxX + offset,
|
|
134
|
-
maxY: maxY + offset,
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
function getPointsFromBBoxBorder(bbox: BBoxType) {
|
|
139
|
-
const { minX, minY, maxX, maxY } = bbox
|
|
140
|
-
return [
|
|
141
|
-
{
|
|
142
|
-
x: minX,
|
|
143
|
-
y: minY,
|
|
144
|
-
},
|
|
145
|
-
{
|
|
146
|
-
x: minX + (maxX - minX) / 2,
|
|
147
|
-
y: minY,
|
|
148
|
-
},
|
|
149
|
-
{
|
|
150
|
-
x: maxX,
|
|
151
|
-
y: minY,
|
|
152
|
-
},
|
|
153
|
-
{
|
|
154
|
-
x: maxX,
|
|
155
|
-
y: minY + (maxY - minY) / 2,
|
|
156
|
-
},
|
|
157
|
-
{
|
|
158
|
-
x: maxX,
|
|
159
|
-
y: maxY,
|
|
160
|
-
},
|
|
161
|
-
{
|
|
162
|
-
x: minX + (maxX - minX) / 2,
|
|
163
|
-
y: maxY,
|
|
164
|
-
},
|
|
165
|
-
{
|
|
166
|
-
x: minX,
|
|
167
|
-
y: maxY,
|
|
168
|
-
},
|
|
169
|
-
{
|
|
170
|
-
x: minX,
|
|
171
|
-
y: minY + (maxY - minY) / 2,
|
|
172
|
-
},
|
|
173
|
-
]
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
function getHull(points: any[]) {
|
|
177
|
-
const xs = points.map((item: { x: any }) => item.x)
|
|
178
|
-
const ys = points.map((item: { y: any }) => item.y)
|
|
179
|
-
return {
|
|
180
|
-
minX: Math.min(...xs),
|
|
181
|
-
minY: Math.min(...ys),
|
|
182
|
-
maxX: Math.max(...xs),
|
|
183
|
-
maxY: Math.max(...ys),
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
function isPointInsideTheBoxes(point: NodeBase | Point, bboxes: BBoxType[]) {
|
|
188
|
-
let flag = false
|
|
189
|
-
for (const bbox of bboxes) {
|
|
190
|
-
if (isBBoxContainThePoint(bbox, point)) {
|
|
191
|
-
flag = true
|
|
192
|
-
break
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
return flag
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
function isBBoxContainThePoint(bbox: BBoxType, p: NodeBase | Point) {
|
|
199
|
-
const { x, y } = p
|
|
200
|
-
const { minX, minY, maxX, maxY } = bbox
|
|
201
|
-
// ignore the point on the border
|
|
202
|
-
return x > minX && x < maxX && y > minY && y < maxY
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
function isSegmentsIntersected(seg1: any[], seg2: any[]) {
|
|
206
|
-
const [p0, p1] = seg1
|
|
207
|
-
const [p2, p3] = seg2
|
|
208
|
-
const s1x = p1.x - p0.x
|
|
209
|
-
const s1y = p1.y - p0.y
|
|
210
|
-
const s2x = p3.x - p2.x
|
|
211
|
-
const s2y = p3.y - p2.y
|
|
212
|
-
|
|
213
|
-
const s =
|
|
214
|
-
(-s1y * (p0.x - p2.x) + s1x * (p0.y - p2.y)) / (-s2x * s1y + s1x * s2y)
|
|
215
|
-
const t =
|
|
216
|
-
(s2x * (p0.y - p2.y) - s2y * (p0.x - p2.x)) / (-s2x * s1y + s1x * s2y)
|
|
217
|
-
|
|
218
|
-
return s >= 0 && s <= 1 && t >= 0 && t <= 1
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
function getVerticesFromBBox(bbox: BBoxType) {
|
|
222
|
-
const { minX, minY, maxX, maxY } = bbox
|
|
223
|
-
return [
|
|
224
|
-
{
|
|
225
|
-
x: minX,
|
|
226
|
-
y: minY,
|
|
227
|
-
},
|
|
228
|
-
{
|
|
229
|
-
x: maxX,
|
|
230
|
-
y: minY,
|
|
231
|
-
},
|
|
232
|
-
{
|
|
233
|
-
x: maxX,
|
|
234
|
-
y: maxY,
|
|
235
|
-
},
|
|
236
|
-
{
|
|
237
|
-
x: minX,
|
|
238
|
-
y: maxY,
|
|
239
|
-
},
|
|
240
|
-
]
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
function isSegmentCrossingBBox(line: any, bbox: BBoxType) {
|
|
244
|
-
const [p1, p2] = line
|
|
245
|
-
const { minX, minY, maxX, maxY } = bbox
|
|
246
|
-
const width = Math.abs(maxX - minX)
|
|
247
|
-
const height = Math.abs(maxY - minY)
|
|
248
|
-
if (width === 0 && height === 0) {
|
|
249
|
-
return false
|
|
250
|
-
}
|
|
251
|
-
const [pa, pb, pc, pd] = getVerticesFromBBox(bbox)
|
|
252
|
-
let count = 0
|
|
253
|
-
if (isSegmentsIntersected([p1, p2], [pa, pb])) {
|
|
254
|
-
count++
|
|
255
|
-
}
|
|
256
|
-
if (isSegmentsIntersected([p1, p2], [pa, pd])) {
|
|
257
|
-
count++
|
|
258
|
-
}
|
|
259
|
-
if (isSegmentsIntersected([p1, p2], [pb, pc])) {
|
|
260
|
-
count++
|
|
261
|
-
}
|
|
262
|
-
if (isSegmentsIntersected([p1, p2], [pc, pd])) {
|
|
263
|
-
count++
|
|
264
|
-
}
|
|
265
|
-
return count !== 0
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
function aStarFindPathByGrid(
|
|
269
|
-
startNode: NodeBase,
|
|
270
|
-
endNode: NodeBase,
|
|
271
|
-
step: number,
|
|
272
|
-
bboxes: any[],
|
|
273
|
-
outside: BBoxType,
|
|
274
|
-
) {
|
|
275
|
-
let toSearch = [startNode]
|
|
276
|
-
const searchSet = new Set()
|
|
277
|
-
|
|
278
|
-
while (toSearch.length) {
|
|
279
|
-
let current = toSearch[0]
|
|
280
|
-
|
|
281
|
-
for (const item of toSearch) {
|
|
282
|
-
if (item.F < current.F || (item.F === current.F && item.H < current.H)) {
|
|
283
|
-
current = item
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
if (`${current.x}/${current.y}` === `${endNode.x}/${endNode.y}`) {
|
|
288
|
-
const res = [
|
|
289
|
-
{
|
|
290
|
-
x: current.x,
|
|
291
|
-
y: current.y,
|
|
292
|
-
},
|
|
293
|
-
]
|
|
294
|
-
while (current.connection) {
|
|
295
|
-
const { connection } = current
|
|
296
|
-
res.push({
|
|
297
|
-
x: connection.x,
|
|
298
|
-
y: connection.y,
|
|
299
|
-
})
|
|
300
|
-
current = current.connection
|
|
301
|
-
}
|
|
302
|
-
return res.reverse()
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
const val = `${current.x}/${current.y}`
|
|
306
|
-
|
|
307
|
-
!searchSet.has(val) && searchSet.add(val)
|
|
308
|
-
|
|
309
|
-
toSearch = toSearch.filter(
|
|
310
|
-
(item) => `${current.x}/${current.y}` !== `${item.x}/${item.y}`,
|
|
311
|
-
)
|
|
312
|
-
|
|
313
|
-
const neighborsRes = findNeighborsByGridStep(
|
|
314
|
-
current,
|
|
315
|
-
step,
|
|
316
|
-
bboxes,
|
|
317
|
-
outside,
|
|
318
|
-
).filter((item) => {
|
|
319
|
-
const flag = !isPointInsideTheBoxes(item, bboxes)
|
|
320
|
-
return flag
|
|
321
|
-
})
|
|
322
|
-
|
|
323
|
-
const tmpRes: NodeBase[] = []
|
|
324
|
-
neighborsRes.forEach((item: NodeBase) => {
|
|
325
|
-
const key = `${item.x}/${item.y}`
|
|
326
|
-
if (!searchSet.has(key)) {
|
|
327
|
-
tmpRes.push(item)
|
|
328
|
-
tmpRes.push(item)
|
|
329
|
-
}
|
|
330
|
-
})
|
|
331
|
-
|
|
332
|
-
for (const neighbor of tmpRes) {
|
|
333
|
-
if (neighbor.isProcessed) continue
|
|
334
|
-
const inSearch = toSearch.includes(current)
|
|
335
|
-
const costToNeighbor =
|
|
336
|
-
current.G + current.getManhattanDistanceTo(neighbor)
|
|
337
|
-
|
|
338
|
-
if (!inSearch || costToNeighbor < neighbor.G) {
|
|
339
|
-
neighbor.setG(costToNeighbor)
|
|
340
|
-
neighbor.setConnection(current)
|
|
341
|
-
current.setFrom(neighbor)
|
|
342
|
-
|
|
343
|
-
if (!inSearch) {
|
|
344
|
-
neighbor.setH(neighbor.getManhattanDistanceTo(endNode))
|
|
345
|
-
toSearch.push(neighbor)
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
return null
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
function findNeighborsByGridStep(
|
|
354
|
-
cur: NodeBase,
|
|
355
|
-
step: number,
|
|
356
|
-
bboxes: any,
|
|
357
|
-
outside: BBoxType,
|
|
358
|
-
) {
|
|
359
|
-
const neighbors: NodeBase[] = []
|
|
360
|
-
const { x, y } = cur
|
|
361
|
-
const { minX, minY, maxX, maxY } = outside
|
|
362
|
-
const x1 = x - step
|
|
363
|
-
const x2 = x + step
|
|
364
|
-
const y1 = y - step
|
|
365
|
-
const y2 = y + step
|
|
366
|
-
|
|
367
|
-
// eslint-disable-next-line no-shadow
|
|
368
|
-
function isValid(
|
|
369
|
-
cur: NodeBase | Point,
|
|
370
|
-
neighbor: NodeBase | Point,
|
|
371
|
-
bboxes: BBoxType[],
|
|
372
|
-
) {
|
|
373
|
-
let flag =
|
|
374
|
-
!isPointInsideTheBoxes(neighbor, bboxes) &&
|
|
375
|
-
!isPointInsideTheBoxes(cur, bboxes)
|
|
376
|
-
if (!flag) return false
|
|
377
|
-
for (const bbox of bboxes) {
|
|
378
|
-
if (
|
|
379
|
-
isSegmentCrossingBBox(
|
|
380
|
-
[
|
|
381
|
-
{
|
|
382
|
-
x: cur.x,
|
|
383
|
-
y: cur.y,
|
|
384
|
-
},
|
|
385
|
-
{
|
|
386
|
-
x: neighbor.x,
|
|
387
|
-
y: neighbor.y,
|
|
388
|
-
},
|
|
389
|
-
],
|
|
390
|
-
bbox,
|
|
391
|
-
)
|
|
392
|
-
) {
|
|
393
|
-
flag = false
|
|
394
|
-
break
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
return flag
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
if (x1 >= minX) {
|
|
401
|
-
isValid(
|
|
402
|
-
cur,
|
|
403
|
-
{
|
|
404
|
-
x: x1,
|
|
405
|
-
y,
|
|
406
|
-
},
|
|
407
|
-
bboxes,
|
|
408
|
-
) && neighbors.push(new NodeBase(x1, y))
|
|
409
|
-
}
|
|
410
|
-
if (x2 <= maxX) {
|
|
411
|
-
isValid(
|
|
412
|
-
cur,
|
|
413
|
-
{
|
|
414
|
-
x: x2,
|
|
415
|
-
y,
|
|
416
|
-
},
|
|
417
|
-
bboxes,
|
|
418
|
-
) && neighbors.push(new NodeBase(x2, y))
|
|
419
|
-
}
|
|
420
|
-
if (y1 >= minY) {
|
|
421
|
-
isValid(
|
|
422
|
-
cur,
|
|
423
|
-
{
|
|
424
|
-
x,
|
|
425
|
-
y: y1,
|
|
426
|
-
},
|
|
427
|
-
bboxes,
|
|
428
|
-
) && neighbors.push(new NodeBase(x, y1))
|
|
429
|
-
}
|
|
430
|
-
if (y2 <= maxY) {
|
|
431
|
-
isValid(
|
|
432
|
-
cur,
|
|
433
|
-
{
|
|
434
|
-
x,
|
|
435
|
-
y: y2,
|
|
436
|
-
},
|
|
437
|
-
bboxes,
|
|
438
|
-
) && neighbors.push(new NodeBase(x, y2))
|
|
439
|
-
}
|
|
440
|
-
return neighbors
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
function getAnchorWithOffset({ bbox }: any, node: NodeBase, offset: number) {
|
|
444
|
-
const { minX, minY, maxX, maxY } = bbox
|
|
445
|
-
const { x, y } = node
|
|
446
|
-
if (x === minX) {
|
|
447
|
-
return {
|
|
448
|
-
x: x - offset,
|
|
449
|
-
y,
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
if (x === maxX) {
|
|
453
|
-
return {
|
|
454
|
-
x: x + offset,
|
|
455
|
-
y,
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
if (y === minY) {
|
|
459
|
-
return {
|
|
460
|
-
x,
|
|
461
|
-
y: y - offset,
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
if (y === maxY) {
|
|
465
|
-
return {
|
|
466
|
-
x,
|
|
467
|
-
y: y + offset,
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
function perpendicularDistance(
|
|
473
|
-
point: NodeBase,
|
|
474
|
-
lineStart: NodeBase,
|
|
475
|
-
lineEnd: NodeBase,
|
|
476
|
-
) {
|
|
477
|
-
const { x: x1, y: y1 } = lineStart
|
|
478
|
-
const { x: x2, y: y2 } = lineEnd
|
|
479
|
-
const { x, y } = point
|
|
480
|
-
|
|
481
|
-
if (x1 === x2) {
|
|
482
|
-
// 线段是垂直的
|
|
483
|
-
return Math.abs(x - x1)
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
if (y1 === y2) {
|
|
487
|
-
// 线段是水平的
|
|
488
|
-
return Math.abs(y - y1)
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
// 计算点到线段垂直点的坐标
|
|
492
|
-
const px =
|
|
493
|
-
x1 +
|
|
494
|
-
((x2 - x1) * ((x - x1) * (x2 - x1) + (y - y1) * (y2 - y1))) /
|
|
495
|
-
((x2 - x1) ** 2 + (y2 - y1) ** 2)
|
|
496
|
-
const py =
|
|
497
|
-
y1 +
|
|
498
|
-
((y2 - y1) * ((x - x1) * (x2 - x1) + (y - y1) * (y2 - y1))) /
|
|
499
|
-
((x2 - x1) ** 2 + (y2 - y1) ** 2)
|
|
500
|
-
|
|
501
|
-
// 计算曼哈顿距离
|
|
502
|
-
return Math.abs(x - px) + Math.abs(y - py)
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
function perpendicularToStraight(line: string | any[]) {
|
|
506
|
-
// Step 1: Convert perpendicular segments to straight lines
|
|
507
|
-
const straightLine = [line[0]]
|
|
508
|
-
for (let i = 0; i < line.length - 2; i++) {
|
|
509
|
-
const point1 = line[i]
|
|
510
|
-
const point2 = line[i + 1]
|
|
511
|
-
const point3 = line[i + 2]
|
|
512
|
-
|
|
513
|
-
if (
|
|
514
|
-
isVertical(point1, point2, point3) ||
|
|
515
|
-
isHorizontal(point1, point2, point3)
|
|
516
|
-
) {
|
|
517
|
-
// Remove point2 to make it a straight line
|
|
518
|
-
continue
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
straightLine.push(point2)
|
|
522
|
-
}
|
|
523
|
-
straightLine.push(line[line.length - 1])
|
|
524
|
-
|
|
525
|
-
// Step 2: Douglas-Peucker algorithm to remove redundant points
|
|
526
|
-
// return straightLine;
|
|
527
|
-
const epsilon = 1.0 // Adjust epsilon based on your requirements
|
|
528
|
-
return douglasPeucker(straightLine, epsilon)
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
function isVertical(p1: { x: any }, p2: { x: any }, p3: { x: any }) {
|
|
532
|
-
return p1.x === p2.x && p2.x === p3.x
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
function isHorizontal(p1: { y: any }, p2: { y: any }, p3: { y: any }) {
|
|
536
|
-
return p1.y === p2.y && p2.y === p3.y
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
function douglasPeucker(points: string | any[], epsilon: number) {
|
|
540
|
-
let dmax = 0
|
|
541
|
-
let index = 0
|
|
542
|
-
|
|
543
|
-
for (let i = 1; i < points.length - 1; i++) {
|
|
544
|
-
const d = perpendicularDistance(
|
|
545
|
-
points[i],
|
|
546
|
-
points[0],
|
|
547
|
-
points[points.length - 1],
|
|
548
|
-
)
|
|
549
|
-
if (d > dmax) {
|
|
550
|
-
index = i
|
|
551
|
-
dmax = d
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
if (dmax > epsilon) {
|
|
556
|
-
const left = douglasPeucker(points.slice(0, index + 1), epsilon)
|
|
557
|
-
const right = douglasPeucker(points.slice(index), epsilon)
|
|
558
|
-
|
|
559
|
-
return left.slice(0, left.length - 1).concat(right)
|
|
560
|
-
}
|
|
561
|
-
return [points[0], points[points.length - 1]]
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
// 每三个点如果其横坐标或者纵坐标都相同,则取其二
|
|
565
|
-
function getSimplePath(path: string | any[]) {
|
|
566
|
-
// if (path.length < 5) return path;
|
|
567
|
-
path = circleDetection(path)
|
|
568
|
-
const res: NodeBase[] = []
|
|
569
|
-
for (let i = 0; i < path.length; ) {
|
|
570
|
-
const point1 = path[i]
|
|
571
|
-
const point2 = path[i + 1]
|
|
572
|
-
const point3 = path[i + 2]
|
|
573
|
-
if (!point3) {
|
|
574
|
-
res.push(point1)
|
|
575
|
-
i++
|
|
576
|
-
continue
|
|
577
|
-
}
|
|
578
|
-
if (
|
|
579
|
-
(point1.x === point2.x && point2.x === point3.x) ||
|
|
580
|
-
(point1.y === point2.y && point2.y === point3.y)
|
|
581
|
-
) {
|
|
582
|
-
res.push(point1)
|
|
583
|
-
res.push(point3)
|
|
584
|
-
i += 3
|
|
585
|
-
} else {
|
|
586
|
-
res.push(point1)
|
|
587
|
-
i++
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
return res
|
|
591
|
-
}
|
|
592
|
-
|
|
593
|
-
// 回环检测 & 处理
|
|
594
|
-
function circleDetection(path: string | any[]) {
|
|
595
|
-
if (path.length < 6) return path
|
|
596
|
-
|
|
597
|
-
const res: Array<NodeBase | Point> = []
|
|
598
|
-
for (let i = 0; i < path.length; ) {
|
|
599
|
-
const point1 = path[i]
|
|
600
|
-
const point2 = path[i + 1]
|
|
601
|
-
const point4 = path[i + 3]
|
|
602
|
-
const point5 = path[i + 4]
|
|
603
|
-
if (!point5) {
|
|
604
|
-
res.push(point1)
|
|
605
|
-
i++
|
|
606
|
-
continue
|
|
607
|
-
}
|
|
608
|
-
if (isSegmentsIntersected([point1, point2], [point4, point5])) {
|
|
609
|
-
let x = 0
|
|
610
|
-
let y = 0
|
|
611
|
-
if (point1.x === point2.x) {
|
|
612
|
-
x = point1.x
|
|
613
|
-
y = point4.y
|
|
614
|
-
} else {
|
|
615
|
-
x = point4.x
|
|
616
|
-
y = point1.y
|
|
617
|
-
}
|
|
618
|
-
res.push({
|
|
619
|
-
x,
|
|
620
|
-
y,
|
|
621
|
-
})
|
|
622
|
-
res.push(point5)
|
|
623
|
-
i += 4
|
|
624
|
-
continue
|
|
625
|
-
}
|
|
626
|
-
res.push(point1)
|
|
627
|
-
i++
|
|
628
|
-
}
|
|
629
|
-
return res
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
export function getOrient(start: NodeBase, end: NodeBase) {
|
|
633
|
-
const { x: x1, y: y1 } = start
|
|
634
|
-
const { x: x2, y: y2 } = end
|
|
635
|
-
let prefix = ''
|
|
636
|
-
let suffix = ''
|
|
637
|
-
if (x1 >= x2) {
|
|
638
|
-
prefix = 'left'
|
|
639
|
-
} else {
|
|
640
|
-
prefix = 'right'
|
|
641
|
-
}
|
|
642
|
-
if (y1 >= y2) {
|
|
643
|
-
suffix = 'top'
|
|
644
|
-
} else {
|
|
645
|
-
suffix = 'bottom'
|
|
646
|
-
}
|
|
647
|
-
return `${prefix}:${suffix}`
|
|
648
|
-
}
|
|
649
|
-
|
|
650
|
-
export function ManhattanLayout(
|
|
651
|
-
startAnchor: any,
|
|
652
|
-
endAnchor: any,
|
|
653
|
-
startNode: { bbox: any },
|
|
654
|
-
endNode: { bbox: any },
|
|
655
|
-
// obstacles,
|
|
656
|
-
offset: any,
|
|
657
|
-
) {
|
|
658
|
-
// get expanded bbox
|
|
659
|
-
const { bbox: startBBox } = startNode
|
|
660
|
-
const { bbox: endBBox } = endNode
|
|
661
|
-
const startExpandBBox = expandBBox(startNode.bbox, offset)
|
|
662
|
-
const endExpandBBox = expandBBox(endNode.bbox, offset)
|
|
663
|
-
// get points from bbox border
|
|
664
|
-
const points1 = getPointsFromBBoxBorder(startExpandBBox)
|
|
665
|
-
const points2 = getPointsFromBBoxBorder(endExpandBBox)
|
|
666
|
-
// is bbox overlap
|
|
667
|
-
// const overlap = isBBoxOverlap(startBBox, endBBox);
|
|
668
|
-
const outsideBBox = getHull([...points1, ...points2])
|
|
669
|
-
|
|
670
|
-
const sNode = getAnchorWithOffset(startNode, startAnchor, offset)
|
|
671
|
-
const eNode = getAnchorWithOffset(endNode, endAnchor, offset)
|
|
672
|
-
|
|
673
|
-
const sNodeBase = new NodeBase(sNode!.x, sNode!.y)
|
|
674
|
-
const eNodeBase = new NodeBase(eNode!.x, eNode!.y)
|
|
675
|
-
|
|
676
|
-
const path = aStarFindPathByGrid(
|
|
677
|
-
eNodeBase,
|
|
678
|
-
sNodeBase,
|
|
679
|
-
10,
|
|
680
|
-
// obstacles,
|
|
681
|
-
[startBBox, endBBox],
|
|
682
|
-
// [startExpandBBox, endExpandBBox],
|
|
683
|
-
outsideBBox,
|
|
684
|
-
)
|
|
685
|
-
|
|
686
|
-
if (path) {
|
|
687
|
-
const simplifiedPath = perpendicularToStraight(path)
|
|
688
|
-
|
|
689
|
-
return getSimplePath([endAnchor, ...simplifiedPath, startAnchor].reverse())
|
|
690
|
-
}
|
|
691
|
-
}
|