a6cbcc273e
Made-with: Cursor
27 lines
1.3 KiB
TypeScript
27 lines
1.3 KiB
TypeScript
import type { GraphNodeId, SceneGraphEdge, SceneGraphNode, SceneId } from '../types';
|
|
|
|
/**
|
|
* true — связь добавлять нельзя: нет узлов, петля по одной сцене, то же ребро уже есть,
|
|
* или с этого узла уже ведёт связь к другой карточке той же целевой сцены.
|
|
* Разрешены несколько исходящих «вариантов» с одной ноды только на разные сцены.
|
|
*/
|
|
export function isSceneGraphEdgeRejected(
|
|
sceneGraphNodes: SceneGraphNode[],
|
|
sceneGraphEdges: SceneGraphEdge[],
|
|
sourceGraphNodeId: GraphNodeId,
|
|
targetGraphNodeId: GraphNodeId,
|
|
): boolean {
|
|
const gnScene = new Map<GraphNodeId, SceneId>(sceneGraphNodes.map((n) => [n.id, n.sceneId]));
|
|
const srcScene = gnScene.get(sourceGraphNodeId);
|
|
const tgtScene = gnScene.get(targetGraphNodeId);
|
|
if (srcScene === undefined || tgtScene === undefined) return true;
|
|
if (srcScene === tgtScene) return true;
|
|
|
|
for (const e of sceneGraphEdges) {
|
|
if (e.sourceGraphNodeId !== sourceGraphNodeId) continue;
|
|
if (e.targetGraphNodeId === targetGraphNodeId) return true;
|
|
if (gnScene.get(e.targetGraphNodeId) === tgtScene) return true;
|
|
}
|
|
return false;
|
|
}
|