aboutsummaryrefslogtreecommitdiff
path: root/src/layout.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/layout.ts')
-rw-r--r--src/layout.ts26
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){