From 7a47bb9fd2cf161a2bda935eca285939a4bcee7d Mon Sep 17 00:00:00 2001 From: Kieran Collienne Date: Tue, 2 Jul 2024 14:18:33 -0700 Subject: [PATCH 1/3] include optional depth component in tree --- src/lib/tree.typ | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/lib/tree.typ b/src/lib/tree.typ index ad596d1d2..39669636c 100644 --- a/src/lib/tree.typ +++ b/src/lib/tree.typ @@ -131,12 +131,20 @@ } assert(draw-node != none, message: "Node draw callback must be set!") - let build-node(tree, depth: 0, sibling: 0) = { + let build-node(tree-arr, depth: 0, sibling: 0) = { let children = () let content = none + + let (e, tree) = if type(tree-arr) == array and tree-arr.len() == 2 and type(tree-arr.at(0)) == int { + tree-arr + } else { + (1, tree-arr) + } + let depth = depth + e + if type(tree) == array { children = tree.slice(1).enumerate().map( - ((n, c)) => build-node(c, depth: depth + 1, sibling: n) + ((n, c)) => build-node(c, depth: depth, sibling: n) ) content = tree.at(0) } else { From a766aeb55811048153f88e732fcb59a228679e14 Mon Sep 17 00:00:00 2001 From: Kieran Collienne Date: Tue, 2 Jul 2024 15:01:35 -0700 Subject: [PATCH 2/3] allow float branch lengths --- src/lib/tree.typ | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/tree.typ b/src/lib/tree.typ index 39669636c..2e168ce10 100644 --- a/src/lib/tree.typ +++ b/src/lib/tree.typ @@ -135,7 +135,7 @@ let children = () let content = none - let (e, tree) = if type(tree-arr) == array and tree-arr.len() == 2 and type(tree-arr.at(0)) == int { + let (e, tree) = if type(tree-arr) == array and tree-arr.len() == 2 and type(tree-arr.at(0)) in (int,float) { tree-arr } else { (1, tree-arr) From a732b873c3906e02edbbada983dd7b8f046adb09 Mon Sep 17 00:00:00 2001 From: Kieran Collienne Date: Mon, 8 Jul 2024 11:20:11 -0700 Subject: [PATCH 3/3] add test-case for tree with specific branch lengths --- tests/tree/test.typ | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/tree/test.typ b/tests/tree/test.typ index 5516753bb..e4c58b3c3 100644 --- a/tests/tree/test.typ +++ b/tests/tree/test.typ @@ -42,3 +42,8 @@ }) h(.1cm) } + +#test-case({ + // Specify branch lengths + cetz.tree.tree(([], (1, ([], (1, []), (1, []))), (2, []))) +})