diff options
| author | Terry Truong <terry06890@gmail.com> | 2022-05-24 17:37:34 +1000 |
|---|---|---|
| committer | Terry Truong <terry06890@gmail.com> | 2022-05-24 17:37:34 +1000 |
| commit | fa8111c3881a0e37ef203f2e0ceb9b85748bb27d (patch) | |
| tree | 5c5b6571cc99861e270caba24cb901cb75db0743 /src/layout.ts | |
| parent | c5101c0e34ba8db5aeb009f3a17c82fdaeb869ae (diff) | |
Add jump-to-searched-node setting
Diffstat (limited to 'src/layout.ts')
| -rw-r--r-- | src/layout.ts | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/layout.ts b/src/layout.ts index 7cec2a5..ece1c1a 100644 --- a/src/layout.ts +++ b/src/layout.ts @@ -107,6 +107,32 @@ export class LayoutNode { this.sepSweptArea = sepSweptArea; this.empSpc = empSpc; } + // Add descendant nodes, along a sequence from a child to a grandchild, and so on + addDescendantChain(nameChain: string[], tolMap: TolMap, map?: LayoutMap): void { + let layoutNode = this as LayoutNode; + for (let childName of nameChain){ + if (layoutNode.children.length > 0){ + throw new Error('Expected child node without children'); + } + // Add children + let tolNode = tolMap.get(layoutNode.name)!; + layoutNode.children = tolNode.children.map((name: string) => new LayoutNode(name, [])); + layoutNode.children.forEach(node => { + node.parent = layoutNode; + node.depth = layoutNode.depth + 1; + if (map != null){ + map.set(node.name, node); + } + }); + LayoutNode.updateDCounts(layoutNode, layoutNode.children.length); + // Get matching child node + let childNode = layoutNode.children.find(n => n.name == childName); + if (childNode == null){ + throw new Error('Child name not found'); + } + layoutNode = childNode; + } + } // Used to update a LayoutNode tree's dCount fields after adding/removing a node's children static updateDCounts(node: LayoutNode | null, diff: number): void { while (node != null){ |
