compute_ntracks = function(parent) -- leaf nodes need 1 track if parent.children == nil then return 1 end -- otherwise add up the tracks needed by all children (parent will fit in among them) -- if we have a single child, it will slide into the same track. This is desirable. local result = 0 for _,child_id in ipairs(parent.children) do local child = Nodes[child_id] result = result + ntracks(child) end return result end