annotate pkg-src/tree-x/tree.c @ 163:0132846995bd r20-3b8

Import from CVS: tag r20-3b8
author cvs
date Mon, 13 Aug 2007 09:43:35 +0200
parents
children 85ec50267440
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
1 /* ----------------------------------------------------------------------------
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
2 * File : tree.c
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
3 * Purpose : dynamic tree program based on Sven Moen's algorithm
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
4 * ----------------------------------------------------------------------------
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
5 */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
6
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
7 #include "defs.h"
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
8 #include "tree.h"
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
9 #include "dbl.h"
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
10 #include "intf.h"
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
11 #include <string.h>
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
12
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
13 /* ------------------------------------------------------------------------- */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
14 /* Global Variables */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
15 /* ------------------------------------------------------------------------- */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
16
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
17 int NumLines = 0;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
18 int NumNodes = 0;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
19
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
20
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
21 /* ----------------------------------------------------------------------------
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
22 *
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
23 * MakeLine() allocates the memory required for a Polyline and
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
24 * initializes the fields of a Polyline to the arguments. The
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
25 * newly-allocated Polyline is returned by the function.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
26 *
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
27 * ----------------------------------------------------------------------------
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
28 */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
29
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
30 Polyline*
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
31 MakeLine(dx, dy, link)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
32 short dx;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
33 short dy;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
34 Polyline *link;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
35 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
36 Polyline *new;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
37
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
38 new = (Polyline *) malloc(sizeof(Polyline));
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
39 NASSERT(new, "could not allocate memory for polyline");
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
40 NumLines++;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
41
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
42 new->dx = dx;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
43 new->dy = dy;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
44 new->link = link;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
45
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
46 return (new);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
47 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
48
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
49 /* ----------------------------------------------------------------------------
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
50 *
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
51 * MakeNode() allocates the memory required for a tree node, and
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
52 * zeros out all the fields in the Node. It returns a pointer to the
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
53 * tree node upon success, and NULL upon failure.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
54 *
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
55 * ----------------------------------------------------------------------------
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
56 */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
57
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
58 Tree*
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
59 MakeNode()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
60 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
61 Tree *node;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
62
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
63 node = (Tree *) malloc(sizeof(Tree));
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
64 NASSERT(node, "could not allocate memory for node");
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
65 NumNodes++;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
66
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
67 if (node == NULL)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
68 return (NULL);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
69 else {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
70 #ifdef SYSV
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
71 memset((char *) node, 0, sizeof(Tree));
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
72 #else
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
73 bzero((char *) node, sizeof(Tree));
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
74 #endif
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
75 return (node);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
76 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
77 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
78
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
79 /* ----------------------------------------------------------------------------
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
80 *
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
81 * MakeBridge()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
82 *
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
83 * ----------------------------------------------------------------------------
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
84 */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
85
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
86 Polyline*
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
87 MakeBridge(line1, x1, y1, line2, x2, y2)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
88 Polyline *line1, *line2;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
89 int x1, x2, y1, y2;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
90 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
91 int dx, dy, s;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
92 Polyline *r;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
93
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
94 dx = x2 + line2->dx - x1;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
95 if (line2->dx == 0)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
96 dy = line2->dy;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
97 else {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
98 s = dx * line2->dy;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
99 dy = s / line2->dx;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
100 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
101 r = MakeLine(dx, dy, line2->link);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
102 line1->link = MakeLine(0, y2 + line2->dy - dy - y1, r);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
103
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
104 return (r);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
105 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
106
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
107 /* ----------------------------------------------------------------------------
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
108 *
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
109 * Offset() computes the necessary offset that prevents two line segments
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
110 * from intersecting each other. This is the "heart" of the merge step
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
111 * that computes how two subtree contours should be separated.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
112 *
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
113 * The code is taken directly from Sven Moen's paper, with changes in
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
114 * some variable names to give more meaning:
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
115 *
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
116 * - px,py indicate the x- and y-coordinates of the point on the longer
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
117 * segment if the previous Offset() call had two unequal segments
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
118 *
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
119 * - lx,ly indicate the dx and dy values of the "lower" line segment
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
120 *
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
121 * - ux,uy indicate the dx and dy values of the "upper" line segment
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
122 *
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
123 * ----------------------------------------------------------------------------
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
124 */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
125
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
126 int
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
127 Offset(px, py, lx, ly, ux, uy)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
128 int px, py, lx, ly, ux, uy;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
129 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
130 int d, s, t;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
131
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
132 if (ux <= px || px+lx <= 0)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
133 return 0;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
134
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
135 t = ux*ly - lx*uy;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
136
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
137 if (t > 0) {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
138 if (px < 0) {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
139 s = px*ly;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
140 d = s/lx - py;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
141 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
142 else if (px > 0) {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
143 s = px*uy;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
144 d = s/ux - py;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
145 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
146 else {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
147 d = -py;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
148 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
149 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
150 else {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
151 if (ux < px+lx) {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
152 s = (ux-px) * ly;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
153 d = uy - (py + s/lx);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
154 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
155 else if (ux > px+lx) {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
156 s = (lx+px) * uy;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
157 d = s/ux - (py+ly);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
158 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
159 else {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
160 d = uy - (py+ly);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
161 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
162 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
164 return MAX(0, d);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
165 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
166
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
167 /* ----------------------------------------------------------------------------
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
168 *
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
169 * Merge()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
170 *
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
171 * ----------------------------------------------------------------------------
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
172 */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
173
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
174 int
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
175 Merge(c1, c2)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
176 Polygon *c1, *c2;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
177 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
178 int x, y, total, d;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
179 Polyline *lower, *upper, *bridge;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
180
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
181 x = y = total = 0;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
182
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
183 /* compare lower part of upper child's contour
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
184 * with upper part of lower child's contour
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
185 */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
186 upper = c1->lower.head;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
187 lower = c2->upper.head;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
188
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
189 while (lower && upper) {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
190 d = Offset(x, y, lower->dx, lower->dy, upper->dx, upper->dy);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
191 y += d;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
192 total += d;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
193
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
194 if (x + lower->dx <= upper->dx) {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
195 x += lower->dx;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
196 y += lower->dy;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
197 lower = lower->link;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
198 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
199 else {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
200 x -= upper->dx;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
201 y -= upper->dy;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
202 upper = upper->link;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
203 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
204 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
205
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
206 if (lower) {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
207 bridge = MakeBridge(c1->upper.tail, 0, 0, lower, x, y);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
208 c1->upper.tail = (bridge->link) ? c2->upper.tail : bridge;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
209 c1->lower.tail = c2->lower.tail;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
210 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
211 else {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
212 bridge = MakeBridge(c2->lower.tail, x, y, upper, 0, 0);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
213 if (!bridge->link)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
214 c1->lower.tail = bridge;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
215 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
216 c1->lower.head = c2->lower.head;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
217
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
218 return (total);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
219 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
220
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
221 /* ----------------------------------------------------------------------------
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
222 *
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
223 * DetachParent() reverses the effects of AttachParent by removing
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
224 * the four line segments that connect the subtree contour to the
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
225 * node specified by 'tree'.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
226 *
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
227 * ----------------------------------------------------------------------------
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
228 */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
229
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
230 void
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
231 DetachParent(tree)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
232 Tree *tree;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
233 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
234 free(tree->contour.upper.head->link);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
235 free(tree->contour.upper.head);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
236 tree->contour.upper.head = NULL;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
237 tree->contour.upper.tail = NULL;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
238
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
239 free(tree->contour.lower.head->link);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
240 free(tree->contour.lower.head);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
241 tree->contour.lower.head = NULL;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
242 tree->contour.lower.tail = NULL;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
243
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
244 NumLines -= 4;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
245 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
246
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
247 /* ----------------------------------------------------------------------------
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
248 *
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
249 * AttachParent()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
250 * This function also establishes the position of the first child
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
251 * The code follows Sven Moen's version, with slight modification to
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
252 * support varying borders at different levels.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
253 *
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
254 * ----------------------------------------------------------------------------
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
255 */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
256
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
257 void
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
258 AttachParent(tree, h)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
259 Tree *tree;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
260 int h;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
261 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
262 int x, y1, y2;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
263
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
264 if (TreeAlignNodes)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
265 x = tree->border + (TreeParentDistance * 2) +
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
266 (TreeParentDistance - tree->width);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
267 else
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
268 x = tree->border + TreeParentDistance;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
269 y2 = (h - tree->height)/2 - tree->border;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
270 y1 = y2 + tree->height + (2 * tree->border) - h;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
271 tree->child->offset.x = x + tree->width;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
272 tree->child->offset.y = y1;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
273 tree->contour.upper.head = MakeLine(tree->width, 0,
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
274 MakeLine(x, y1,
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
275 tree->contour.upper.head));
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
276 tree->contour.lower.head = MakeLine(tree->width, 0,
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
277 MakeLine(x, y2,
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
278 tree->contour.lower.head));
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
279 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
280
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
281 /* ----------------------------------------------------------------------------
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
282 *
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
283 * Split()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
284 * The tree passed to Split() must have at least 1 child, because
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
285 * it doesn't make sense to split a leaf (there are no bridges)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
286 *
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
287 * ----------------------------------------------------------------------------
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
288 */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
289
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
290 void
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
291 Split(tree)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
292 Tree *tree;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
293 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
294 Tree *child;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
295 Polyline *link;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
296
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
297 FOREACH_CHILD(child, tree) {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
298 if (link = child->contour.upper.tail->link) {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
299 free(link->link);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
300 free(link);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
301 child->contour.upper.tail->link = NULL;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
302 NumLines -= 2;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
303 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
304 if (link = child->contour.lower.tail->link) {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
305 free(link->link);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
306 free(link);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
307 NumLines -= 2;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
308 child->contour.lower.tail->link = NULL;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
309 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
310 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
311 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
312
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
313 /* ----------------------------------------------------------------------------
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
314 *
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
315 * Join() merges all subtree contours of the given tree and returns the
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
316 * height of the entire tree contour.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
317 *
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
318 * ----------------------------------------------------------------------------
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
319 */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
320
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
321 int
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
322 Join(tree)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
323 Tree *tree;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
324 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
325 Tree *child;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
326 int d, h, sum;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
327
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
328 /* to start, set the parent's contour and height
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
329 * to contour and height of first child
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
330 */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
331 child = tree->child;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
332 tree->contour = child->contour;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
333 sum = h = child->height + (2 * child->border);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
334
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
335 /* extend contour to include contours of all children of parent */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
336 for (child = child->sibling ; child ; child = child->sibling) {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
337 d = Merge(&tree->contour, &child->contour);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
338 child->offset.y = d + h;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
339 child->offset.x = 0;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
340 h = child->height + (2 * child->border);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
341 /* keep cumulative heights of subtree contours */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
342 sum += d + h;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
343 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
344 return sum;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
345 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
346
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
347 /* ----------------------------------------------------------------------------
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
348 *
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
349 * RuboutLeaf() accepts a single node (leaf) and removes its contour.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
350 * The memory associated with the contour is deallocated.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
351 *
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
352 * ----------------------------------------------------------------------------
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
353 */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
354
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
355 void
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
356 RuboutLeaf(tree)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
357 Tree *tree;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
358 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
359 free(tree->contour.upper.head);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
360 free(tree->contour.lower.tail);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
361 free(tree->contour.lower.head);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
362 tree->contour.upper.head = NULL;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
363 tree->contour.upper.tail = NULL;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
364 tree->contour.lower.head = NULL;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
365 tree->contour.lower.tail = NULL;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
366 NumLines -= 3;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
367 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
368
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
369 /* ----------------------------------------------------------------------------
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
370 *
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
371 * LayoutLeaf() accepts a single node (leaf) and forms its contour. This
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
372 * function assumes that the width, height, and border fields of the
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
373 * node have been assigned meaningful values.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
374 *
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
375 * ----------------------------------------------------------------------------
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
376 */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
377
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
378 void
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
379 LayoutLeaf(tree)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
380 Tree *tree;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
381 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
382 tree->node_height = 0;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
383 tree->border = TreeBorderSize;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
384
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
385 tree->contour.upper.tail = MakeLine(tree->width + 2 * tree->border, 0,
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
386 NULL);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
387 tree->contour.upper.head = tree->contour.upper.tail;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
388
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
389 tree->contour.lower.tail = MakeLine(0, -tree->height - 2 * tree->border,
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
390 NULL);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
391 tree->contour.lower.head = MakeLine(tree->width + 2 * tree->border, 0,
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
392 tree->contour.lower.tail);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
393
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
394 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
395
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
396 /* ----------------------------------------------------------------------------
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
397 *
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
398 * LayoutTree() traverses the given tree (in depth-first order), and forms
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
399 * subtree or leaf contours at each node as needed. Each node's contour is
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
400 * stored in its "contour" field. Elision is also supported by generating
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
401 * the contour for both the expanded and collapsed node. This routine
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
402 * also computes the tree height of each node in the tree, so that variable
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
403 * density layout can be demonstrated.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
404 *
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
405 * ----------------------------------------------------------------------------
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
406 */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
407
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
408 void
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
409 LayoutTree(tree)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
410 Tree *tree;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
411 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
412 Tree *child;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
413 int height = 0;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
414
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
415 FOREACH_CHILD(child, tree) {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
416 LayoutTree(child);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
417
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
418 if (child->elision) { /* support elision */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
419 child->old_contour = child->contour;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
420 LayoutLeaf(child);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
421 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
422
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
423 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
424
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
425 if (tree->child) {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
426
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
427 FOREACH_CHILD(child, tree)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
428 height = MAX(child->node_height, height);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
429 tree->node_height = height + 1;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
430
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
431 if (TreeLayoutDensity == Fixed)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
432 tree->border = TreeBorderSize;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
433 else
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
434 tree->border =
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
435 (int) (TreeBorderSize * (tree->node_height * DENSITY_FACTOR));
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
436
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
437 AttachParent(tree, Join(tree));
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
438 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
439 else
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
440 LayoutLeaf(tree);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
441 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
442
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
443 /* ------------------------------------------------------------------------- */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
444
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
445 void
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
446 Unzip(tree)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
447 Tree *tree;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
448 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
449 Tree *child;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
450
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
451 #ifdef INTF
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
452 if (TreeShowSteps) {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
453 HiliteNode(tree, New);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
454 tree->on_path = TRUE;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
455 StatusMsg("Unzip: follow parent links up to root");
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
456 Pause();
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
457 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
458 #endif
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
459
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
460 if (tree->parent)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
461 Unzip(tree->parent);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
462
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
463 if (tree->child) {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
464
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
465 #ifdef INTF
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
466 /* draw entire contour; do it only for root, because the last
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
467 * frame drawn in this function will have already drawn the
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
468 * contour for the most recently split subtree.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
469 */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
470 if (TreeShowSteps) {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
471 if (tree->parent == NULL) {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
472 BeginFrame();
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
473 DrawTreeContour(tree, New, CONTOUR_COLOR, FALSE, FALSE, FALSE);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
474 DrawTree(TheTree, New);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
475 EndFrame();
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
476 StatusMsg("Unzip: disassemble entire contour");
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
477 Pause();
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
478 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
479 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
480 #endif
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
481
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
482 #ifdef INTF
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
483 /* draw contour as it would appear after DetachParent() */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
484 if (TreeShowSteps) {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
485 BeginFrame();
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
486 DrawTreeContour(tree, New, CONTOUR_COLOR, TRUE,
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
487 FALSE, FALSE, FALSE);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
488 DrawTree(TheTree, New);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
489 EndFrame();
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
490 StatusMsg("Unzip: detach parent");
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
491 Pause();
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
492 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
493 #endif
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
494
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
495 DetachParent(tree);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
496 Split(tree);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
497
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
498 #ifdef INTF
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
499 if (TreeShowSteps) {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
500 BeginFrame();
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
501 /* mark other subtree contours as split, and */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
502 /* draw only the contour on path in full */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
503 FOREACH_CHILD(child, tree) {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
504 if (!child->on_path)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
505 child->split = TRUE;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
506 else
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
507 DrawTreeContour(child, New, CONTOUR_COLOR,
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
508 FALSE, FALSE, FALSE);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
509 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
510 DrawTree(TheTree, New);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
511 EndFrame();
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
512 StatusMsg("Unzip: split tree");
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
513 Pause();
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
514 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
515 #endif
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
516
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
517 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
518 else
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
519 RuboutLeaf(tree); /* leaf node */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
520 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
521
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
522 /* ------------------------------------------------------------------------- */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
523
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
524 void
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
525 Zip(tree)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
526 Tree *tree;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
527 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
528 if (tree->child)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
529 AttachParent(tree, Join(tree));
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
530 else
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
531 LayoutLeaf(tree);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
532
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
533 if (tree->parent)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
534 Zip(tree->parent);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
535 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
536
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
537 /* ----------------------------------------------------------------------------
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
538 *
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
539 * Insert() adds the specified child to parent, just after the specified
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
540 * sibling. If 'sibling' is Null, the child is added as the first child.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
541 *
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
542 * ----------------------------------------------------------------------------
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
543 */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
544
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
545 void
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
546 Insert(parent, child, sibling)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
547 Tree *parent, *child, *sibling;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
548 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
549 Unzip(parent);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
550 child->parent = parent;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
551 if (sibling) {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
552 child->sibling = sibling->sibling;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
553 sibling->sibling = child;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
554 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
555 else {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
556 child->sibling = parent->child;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
557 parent->child = child;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
558 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
559 Zip(parent);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
560 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
561
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
562
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
563
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
564
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
565 /* ----------------------------------------------------------------------------
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
566 *
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
567 * Delete() traverses the specified tree and frees all storage
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
568 * allocated to the subtree, including contours and bridges.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
569 * If the tree had a preceding sibling, the preceding sibling is
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
570 * modified to point to the tree's succeeding sibling, if any.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
571 *
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
572 * ----------------------------------------------------------------------------
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
573 */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
574
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
575 Delete(tree)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
576 Tree *tree;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
577 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
578 Tree *sibling = NULL;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
579 Tree *parent, *child;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
580
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
581 /* find sibling */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
582 parent = tree->parent;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
583 if (parent) {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
584 FOREACH_CHILD(child, parent)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
585 if (child->sibling == tree) {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
586 sibling = child;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
587 break;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
588 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
589 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
590 if (sibling)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
591 sibling->sibling = tree->sibling;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
592 else if (parent)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
593 parent->child = tree->sibling;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
594
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
595 DeleteTree(tree, FALSE);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
596 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
597
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
598
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
599 /* ----------------------------------------------------------------------------
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
600 *
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
601 * DeleteTree() is the recursive function that supports Delete().
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
602 * If 'contour' is True, then only the contours are recursively deleted.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
603 * This flag should be True when you are regenerating a tree's layout
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
604 * and still want to preserve the nodes. Since contours would be deleted
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
605 * only due to a change in sibling or level distance, each node's border
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
606 * value is updated with the current value of TreeBorderSize;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
607 *
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
608 * ----------------------------------------------------------------------------
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
609 */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
610
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
611 DeleteTree(tree, contour)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
612 Tree *tree;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
613 int contour;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
614 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
615 Tree *child;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
616
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
617 if (tree->elision) {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
618 RuboutLeaf(tree);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
619 tree->contour = tree->old_contour;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
620 tree->old_contour.upper.head = NULL; /* flag to note 'NULL' contour */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
621 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
622
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
623 if (!IS_LEAF(tree)) {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
624 DetachParent(tree);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
625 Split(tree);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
626
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
627 FOREACH_CHILD(child,tree)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
628 DeleteTree(child, contour);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
629 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
630 else
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
631 RuboutLeaf(tree);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
632
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
633 if (contour)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
634 tree->border = TreeBorderSize;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
635 else {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
636 free(tree->label.text);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
637 free(tree);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
638 NumNodes--;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
639 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
640 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
641
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
642
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
643 /* ----------------------------------------------------------------------------
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
644 *
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
645 * ComputeTreeSize()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
646 * This function should be called after tree layout.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
647 *
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
648 * ----------------------------------------------------------------------------
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
649 */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
650
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
651 void
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
652 ComputeTreeSize(tree, width, height, x_offset, y_offset)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
653 Tree *tree;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
654 int *width, *height;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
655 int *x_offset, *y_offset;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
656 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
657 Polyline *contour, *tail;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
658 int upper_min_y = 0, lower_max_y = 0;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
659 int upper_abs_y = 0, lower_abs_y = 0;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
660 int x = 0;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
661
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
662 /* do upper contour */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
663 contour = tree->contour.upper.head;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
664 tail = tree->contour.upper.tail;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
665 while (contour) {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
666 if ((contour->dy + upper_abs_y) < upper_min_y)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
667 upper_min_y = contour->dy + upper_abs_y;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
668 upper_abs_y += contour->dy;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
669 if (contour == tail)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
670 contour = NULL;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
671 else
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
672 contour = contour->link;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
673 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
674
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
675 /* do lower contour */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
676 contour = tree->contour.lower.head;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
677 tail = tree->contour.lower.tail;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
678 while (contour) {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
679 if ((contour->dy + lower_abs_y) > lower_max_y)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
680 lower_max_y = contour->dy + lower_abs_y;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
681 lower_abs_y += contour->dy;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
682 x += contour->dx;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
683 if (contour == tail)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
684 contour = NULL;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
685 else
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
686 contour = contour->link;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
687 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
688
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
689 *width = x + 1;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
690 *height = lower_max_y - upper_min_y +
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
691 (tree->height + (2 * tree->border)) + 1;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
692 if (x_offset)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
693 *x_offset = tree->border;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
694 if (y_offset)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
695 *y_offset = - upper_min_y + tree->border;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
696 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
697
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
698 /* ----------------------------------------------------------------------------
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
699 *
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
700 * PetrifyTree()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
701 *
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
702 * ----------------------------------------------------------------------------
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
703 */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
704
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
705 void
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
706 PetrifyTree(tree, x, y)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
707 Tree *tree;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
708 int x, y;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
709 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
710 int width, height;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
711 int x_offset, y_offset;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
712
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
713 tree->old_pos = tree->pos; /* used by AnimateTree */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
714
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
715 /* fix position of each node */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
716 tree->pos.x = x + tree->offset.x;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
717 tree->pos.y = y + tree->offset.y;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
718
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
719 if (tree->child) {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
720 PetrifyTree(tree->child, tree->pos.x, tree->pos.y);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
721 ComputeSubTreeExtent(tree); /* for benefit of interface picking */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
722 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
723 if (tree->sibling)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
724 PetrifyTree(tree->sibling, tree->pos.x, tree->pos.y);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents:
diff changeset
725 }