fix: mindmap connectors disappear (#11234)
Fixes [BS-2868](https://linear.app/affine-design/issue/BS-2868/mindmap-bug-布局四的线不见了)
This commit is contained in:
@@ -1,9 +1,12 @@
|
|||||||
import type { Bound, IVec3 } from '@blocksuite/global/gfx';
|
import { almostEqual, type Bound, type IVec3 } from '@blocksuite/global/gfx';
|
||||||
import { almostEqual } from '@blocksuite/global/gfx';
|
|
||||||
|
|
||||||
import { Graph } from './graph.js';
|
import { Graph } from './graph.js';
|
||||||
import { PriorityQueue } from './priority-queue.js';
|
import { PriorityQueue } from './priority-queue.js';
|
||||||
|
|
||||||
|
function isNullish<T>(val: T | null | undefined): val is null | undefined {
|
||||||
|
return val === null || val === undefined;
|
||||||
|
}
|
||||||
|
|
||||||
function cost(point: IVec3, point2: IVec3) {
|
function cost(point: IVec3, point2: IVec3) {
|
||||||
return Math.abs(point[0] - point2[0]) + Math.abs(point[1] - point2[1]);
|
return Math.abs(point[0] - point2[0]) + Math.abs(point[1] - point2[1]);
|
||||||
}
|
}
|
||||||
@@ -66,10 +69,11 @@ export class AStarRunner {
|
|||||||
const froms = this._cameFrom.get(current);
|
const froms = this._cameFrom.get(current);
|
||||||
if (!froms) return result;
|
if (!froms) return result;
|
||||||
const index = nextIndexs.shift();
|
const index = nextIndexs.shift();
|
||||||
if (index !== undefined && index !== null) {
|
if (isNullish(index)) {
|
||||||
nextIndexs.push(froms.indexs[index]);
|
break;
|
||||||
current = froms.from[index];
|
|
||||||
}
|
}
|
||||||
|
nextIndexs.push(froms.indexs[index]);
|
||||||
|
current = froms.from[index];
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -107,16 +111,16 @@ export class AStarRunner {
|
|||||||
private _neighbors(cur: IVec3) {
|
private _neighbors(cur: IVec3) {
|
||||||
const neighbors = this._graph.neighbors(cur);
|
const neighbors = this._graph.neighbors(cur);
|
||||||
const cameFroms = this._cameFrom.get(cur);
|
const cameFroms = this._cameFrom.get(cur);
|
||||||
if (!cameFroms) {
|
|
||||||
return [];
|
if (cameFroms) {
|
||||||
|
cameFroms.from.forEach(from => {
|
||||||
|
const index = neighbors.findIndex(n => pointAlmostEqual(n, from));
|
||||||
|
if (index >= 0) {
|
||||||
|
neighbors.splice(index, 1);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
cameFroms.from.forEach(from => {
|
|
||||||
const index = neighbors.findIndex(n => pointAlmostEqual(n, from));
|
|
||||||
if (index >= 0) {
|
|
||||||
neighbors.splice(index, 1);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (cur === this._ep) neighbors.push(this._originalEp);
|
if (cur === this._ep) neighbors.push(this._originalEp);
|
||||||
return neighbors;
|
return neighbors;
|
||||||
}
|
}
|
||||||
@@ -165,7 +169,7 @@ export class AStarRunner {
|
|||||||
(count, index) =>
|
(count, index) =>
|
||||||
count + getDiagonalCount(next, current, cameFroms.from[index])
|
count + getDiagonalCount(next, current, cameFroms.from[index])
|
||||||
);
|
);
|
||||||
if (!next[2]) {
|
if (isNullish(next[2])) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const newPointPrioritys = curPointPrioritys.map(
|
const newPointPrioritys = curPointPrioritys.map(
|
||||||
|
|||||||
Reference in New Issue
Block a user