@@ -12,7 +12,7 @@ positions co-ordinates of the layout
12
12
"""
13
13
module Buchheim
14
14
15
- using GeometryTypes
15
+ using GeometryBasics
16
16
17
17
struct Tree{A<: AbstractVector ,P<: AbstractVector ,F}
18
18
nodes:: A
@@ -41,7 +41,7 @@ function Tree(tree::AbstractVector, nodesize)
41
41
end
42
42
43
43
function layout (t:: AbstractVector ; nodesize= ones (length (t)))
44
- layout! (t, nodesize)
44
+ return layout! (t, nodesize)
45
45
end
46
46
47
47
function layout! (t:: AbstractVector , nodesize)
54
54
function parent (v, t:: Tree )
55
55
tree = t. nodes
56
56
for i in 1 : length (tree)
57
- y = findall (x -> (x== v), tree[i])
57
+ y = findall (x -> (x == v), tree[i])
58
58
if length (y) != 0
59
59
return i
60
60
end
@@ -67,28 +67,28 @@ function first_walk(v, t::Tree)
67
67
mod = t. mod
68
68
tree = t. nodes
69
69
nodesize = t. nodesize
70
- p = parent (v,t)
70
+ p = parent (v, t)
71
71
if p != nothing
72
- index = findall (x -> (x== v), tree[p])[1 ]
72
+ index = findall (x -> (x == v), tree[p])[1 ]
73
73
else
74
74
index = 1
75
75
end
76
76
if length (tree[v]) == 0
77
77
if v != tree[p][1 ]
78
- prelim[v] = prelim[tree[p][index- 1 ]] + (nodesize[tree[p][index- 1 ]])
78
+ prelim[v] = prelim[tree[p][index - 1 ]] + (nodesize[tree[p][index - 1 ]])
79
79
else
80
- prelim[v] = 0
80
+ prelim[v] = 0
81
81
end
82
82
else
83
83
defaultAncestor = tree[v][1 ]
84
84
for w in tree[v]
85
- first_walk (w,t)
85
+ first_walk (w, t)
86
86
defaultAncestor = apportion (w, defaultAncestor, t)
87
87
end
88
88
execute_shifts (v, t)
89
89
midpoint = (prelim[tree[v][1 ]] + prelim[tree[v][end ]]) / 2
90
90
if index > 1
91
- w = tree[p][index- 1 ]
91
+ w = tree[p][index - 1 ]
92
92
prelim[v] = prelim[w] + (nodesize[w] + 1.0 )
93
93
mod[v] = prelim[v] - midpoint
94
94
else
@@ -106,28 +106,29 @@ function apportion(v::T, defaultAncestor::T, t::Tree) where {T}
106
106
p = parent (v, t)
107
107
nodesize = t. nodesize
108
108
if p != nothing
109
- index = findall (x-> (x== v), tree[p])[1 ]
109
+ index = findall (x -> (x == v), tree[p])[1 ]
110
110
else
111
111
index = 1
112
112
end
113
113
if index > 1
114
- w = tree[p][index- 1 ]
114
+ w = tree[p][index - 1 ]
115
115
v_in_right = v_out_right = v
116
116
v_in_left = w
117
117
v_out_left = tree[parent (v_in_right, t)][1 ]
118
118
s_in_right = mod[v_in_right]
119
119
s_out_right = mod[v_out_right]
120
120
s_in_left = mod[v_in_left]
121
121
s_out_left = mod[v_out_left]
122
- while next_right (v_in_left, t)!= 0 && next_left (v_in_right, t)!= 0
122
+ while next_right (v_in_left, t) != 0 && next_left (v_in_right, t) != 0
123
123
v_in_left = next_right (v_in_left, t)
124
124
v_in_right = next_left (v_in_right, t)
125
125
v_out_left = next_left (v_out_left, t)
126
126
v_out_right = next_right (v_out_right, t)
127
127
ancestor[v_out_right] = v
128
- shift = (prelim[v_in_left] + s_in_left) - (prelim[v_in_right] + s_in_right) + (nodesize[v_in_left])
128
+ shift = (prelim[v_in_left] + s_in_left) - (prelim[v_in_right] + s_in_right) +
129
+ (nodesize[v_in_left])
129
130
if shift > 0
130
- move_subtree (find_ancestor (v_in_left, v, defaultAncestor,t), v,shift, t)
131
+ move_subtree (find_ancestor (v_in_left, v, defaultAncestor, t), v, shift, t)
131
132
s_in_right += shift
132
133
s_out_right += shift
133
134
end
@@ -140,7 +141,7 @@ function apportion(v::T, defaultAncestor::T, t::Tree) where {T}
140
141
thread[v_out_right] = next_right (v_in_left, t)
141
142
mod[v_out_right] += s_in_left - s_out_right
142
143
else
143
- if next_left (v_in_right,t) != 0 && next_left (v_out_left,t) == 0
144
+ if next_left (v_in_right, t) != 0 && next_left (v_out_left, t) == 0
144
145
thread[v_out_left] = next_left (v_in_right, t)
145
146
mod[v_out_left] += s_in_right - s_out_left
146
147
defaultAncestor = v
152
153
153
154
function number (v, t:: Tree )
154
155
p = parent (v, t)
155
- index = findall (x -> (x== v), t. nodes[p])[1 ]
156
+ index = findall (x -> (x == v), t. nodes[p])[1 ]
156
157
return index
157
158
end
158
159
@@ -169,22 +170,22 @@ function move_subtree(w_left::T, w_right::T, shift::Float64, t::Tree) where {T}
169
170
shifttree[w_right] += shift
170
171
change[w_left] += shift / subtrees
171
172
prelim[w_right] += shift
172
- mod[w_right] += shift
173
+ return mod[w_right] += shift
173
174
end
174
175
175
176
function second_walk (v, m:: Float64 , depth:: Float64 , t:: Tree )
176
177
prelim = t. prelim
177
178
mod = t. mod
178
179
positions = t. positions
179
180
nodesize = t. nodesize
180
- positions[v] = Point (prelim[v]+ m, - depth)
181
+ positions[v] = Point (prelim[v] + m, - depth)
181
182
if length (t. nodes[v]) != 0
182
183
maxdist = maximum ([nodesize[i] for i in t. nodes[v]])
183
184
else
184
185
maxdist = 0
185
186
end
186
187
for w in t. nodes[v]
187
- second_walk (w, m+ mod[v], Float64 (depth + 1 + maxdist), t)
188
+ second_walk (w, m + mod[v], Float64 (depth + 1 + maxdist), t)
188
189
end
189
190
end
190
191
0 commit comments