1
%%---------------------------------------------------------------------
2
%% This is added as a test because it was giving a false positive
3
%% (function move/4 will nevr be called) due to the strange use of
4
%% self-recursive fun construction in placex/3.
6
%% The analysis was getting confused that the foldl call will never
7
%% terminate (due to a wrong hard-coded type for foldl) and inferred
8
%% that the remaining calls in the body of placex/3 will not be
9
%% reached. Fixed 11 March 2005.
10
%%---------------------------------------------------------------------
12
-module(appmon_place).
16
case appmon_dg:get(data, DG, Root) of
24
appmon_dg:set(y, DG, V, Y),
26
lists:foreach(fun(C) -> placey(DG, C, Y1) end, appmon_dg:get(out, DG, V)).
28
placex(DG, V, LastX) ->
29
Ch = appmon_dg:get(out, DG, V),
30
ChLX = lists:foldl(fun(C, Accu) -> placex(DG, C, Accu) end,
33
Width = appmon_dg:get(w, DG, V),
34
MyX = calc_mid(DG, Width, Ch),
35
DeltaX = calc_delta(MyX, hdd(LastX)+20),
36
appmon_dg:set(x, DG, V, MyX),
37
move(DG, V, [MyX+Width | ChLX], DeltaX).
39
move(_DG, _L, LastX, 0) -> LastX;
40
move(DG, V, LastX, DeltaX) -> move2(DG, V, LastX, DeltaX).
42
move2(DG, V, LastX, DeltaX) ->
43
NewX = appmon_dg:get(x, DG, V)+DeltaX,
44
appmon_dg:set(x, DG, V, NewX),
45
ChLX = lists:foldl(fun(C, LX) -> move2(DG, C, LX, DeltaX) end,
47
appmon_dg:get(out, DG, V)),
48
[max(NewX+appmon_dg:get(w, DG, V), hdd(LastX)) | ChLX].
50
max(A, B) when A>B -> A;
53
calc_mid(_DG, _Width, []) -> 0;
54
calc_mid(DG, Width, ChList) ->
55
LeftMostX = appmon_dg:get(x, DG, hd(ChList)),
56
Z2 = lists:last(ChList),
57
RightMostX = appmon_dg:get(x, DG, Z2)+appmon_dg:get(w, DG, Z2),
58
trunc((LeftMostX+RightMostX)/2)-trunc(Width/2).
60
calc_delta(Mid, Right) ->
61
if Right>Mid -> Right-Mid;
65
%% Special head and tail
66
%% Handles empty list in a non-standard way