From 5e32fa4985d71991165d97b0c33b84e8b4b892b5 Mon Sep 17 00:00:00 2001 From: nif Date: Mon, 12 Feb 2024 19:46:31 +0000 Subject: [PATCH 1/2] Fix branchedResetPropagation BREAKING CHANGE - Forces branches to be directed Signed-off-by: nif --- src/features/trees/tree.ts | 43 +++++++++++++------------------------- 1 file changed, 15 insertions(+), 28 deletions(-) diff --git a/src/features/trees/tree.ts b/src/features/trees/tree.ts index da77f60..37b5ee6 100644 --- a/src/features/trees/tree.ts +++ b/src/features/trees/tree.ts @@ -338,34 +338,21 @@ export const branchedResetPropagation = function ( tree: GenericTree, resettingNode: GenericTreeNode ): void { - const visitedNodes = [resettingNode]; - let currentNodes = [resettingNode]; - if (tree.branches != null) { - const branches = unref(tree.branches); - while (currentNodes.length > 0) { - const nextNodes: GenericTreeNode[] = []; - currentNodes.forEach(node => { - branches - .filter(branch => branch.startNode === node || branch.endNode === node) - .map(branch => { - if (branch.startNode === node) { - return branch.endNode; - } - return branch.startNode; - }) - .filter(node => !visitedNodes.includes(node)) - .forEach(node => { - // Check here instead of in the filter because this check's results may - // change as we go through each node - if (!nextNodes.includes(node)) { - nextNodes.push(node); - node.reset?.reset(); - } - }); - }); - currentNodes = nextNodes; - visitedNodes.push(...currentNodes); - } + const links = unref(tree.branches); + if (links === undefined) return; + let reset: GenericTreeNode[] = []; + let current = [resettingNode]; + while (current.length != 0) { + let next: GenericTreeNode[] = []; + for (let node of current) { + for (let link of links.filter(link => link.startNode === node)) { + if ([...reset, ...current].includes(link.endNode)) continue + next.push(link.endNode); + link.endNode.reset?.reset(); + } + }; + reset = reset.concat(current); + current = next; } }; -- 2.45.2 From 263c951cf85a0c1e156ff9c77f04e58e63dc47a1 Mon Sep 17 00:00:00 2001 From: TJCgames Date: Wed, 14 Feb 2024 15:56:18 +0000 Subject: [PATCH 2/2] Requested changes --- src/features/trees/tree.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/features/trees/tree.ts b/src/features/trees/tree.ts index 37b5ee6..8ec317f 100644 --- a/src/features/trees/tree.ts +++ b/src/features/trees/tree.ts @@ -339,19 +339,19 @@ export const branchedResetPropagation = function ( resettingNode: GenericTreeNode ): void { const links = unref(tree.branches); - if (links === undefined) return; - let reset: GenericTreeNode[] = []; + if (links == null) return; + const reset: GenericTreeNode[] = []; let current = [resettingNode]; while (current.length != 0) { - let next: GenericTreeNode[] = []; - for (let node of current) { - for (let link of links.filter(link => link.startNode === node)) { + const next: GenericTreeNode[] = []; + for (const node of current) { + for (const link of links.filter(link => link.startNode === node)) { if ([...reset, ...current].includes(link.endNode)) continue next.push(link.endNode); link.endNode.reset?.reset(); } }; - reset = reset.concat(current); + reset.push(...current); current = next; } }; -- 2.45.2