Skip to content

Commit

Permalink
Merge pull request 'Fix branchedResetPropagation' (#57) from nif/Prof…
Browse files Browse the repository at this point in the history
…ectus-Niffix:main into main

Reviewed-on: https://code.incremental.social/profectus/Profectus/pulls/57
  • Loading branch information
thepaperpilot committed Feb 14, 2024
2 parents 1b809a9 + 04a5e96 commit cba79df
Showing 1 changed file with 15 additions and 28 deletions.
43 changes: 15 additions & 28 deletions src/features/trees/tree.ts
Expand Up @@ -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 == null) return;
const reset: GenericTreeNode[] = [];
let current = [resettingNode];
while (current.length != 0) {
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.push(...current);
current = next;
}
};

Expand Down

0 comments on commit cba79df

Please sign in to comment.