Graphviz 13.0.0~dev.20250121.0651
Loading...
Searching...
No Matches
dotsplines.c
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (c) 2011 AT&T Intellectual Property
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * https://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors: Details at https://graphviz.org
9 *************************************************************************/
10
11/*
12 * set edge splines.
13 */
14
15#include <assert.h>
16#include <common/boxes.h>
17#include <dotgen/dot.h>
18#include <math.h>
19#include <stdatomic.h>
20#include <stdbool.h>
21#include <stdint.h>
22#include <stdlib.h>
23#include <string.h>
24#include <util/agxbuf.h>
25#include <util/alloc.h>
26#include <util/list.h>
27
28#ifdef ORTHO
29#include <ortho/ortho.h>
30#endif
31
32#define NSUB 9 /* number of subdivisions, re-aiming splines */
33#define CHUNK 128 /* in building list of edges */
34
35#define MINW 16 /* minimum width of a box in the edge path */
36#define HALFMINW 8
37
38#define FWDEDGE 16
39#define BWDEDGE 32
40
41#define MAINGRAPH 64
42#define AUXGRAPH 128
43#define GRAPHTYPEMASK 192 /* the OR of the above */
44
45#define MAKEFWDEDGE(new, old) \
46 { \
47 edge_t *newp; \
48 Agedgeinfo_t *info; \
49 newp = new; \
50 info = (Agedgeinfo_t *)newp->base.data; \
51 *info = *(Agedgeinfo_t *)old->base.data; \
52 *newp = *old; \
53 newp->base.data = (Agrec_t *)info; \
54 AGTAIL(newp) = AGHEAD(old); \
55 AGHEAD(newp) = AGTAIL(old); \
56 ED_tail_port(newp) = ED_head_port(old); \
57 ED_head_port(newp) = ED_tail_port(old); \
58 ED_edge_type(newp) = VIRTUAL; \
59 ED_to_orig(newp) = old; \
60 }
61
62typedef struct {
63 double LeftBound;
64 double RightBound;
65 double Splinesep;
66 double Multisep;
69
71
72static void adjustregularpath(path *, size_t, size_t);
73static Agedge_t *bot_bound(Agedge_t *, int);
74static bool pathscross(Agnode_t *, Agnode_t *, Agedge_t *, Agedge_t *);
76static bool cl_vninside(Agraph_t *, Agnode_t *);
78 pathend_t *, const boxes_t *);
79static int edgecmp(const void *, const void *);
80static void make_flat_edge(graph_t *, spline_info_t *, path *, Agedge_t **,
81 unsigned, unsigned, int);
82static void make_regular_edge(graph_t *g, spline_info_t *, path *, Agedge_t **,
83 unsigned, unsigned, int);
84static boxf makeregularend(boxf, int, double);
86 Agedge_t *);
87static Agnode_t *neighbor(graph_t *, Agnode_t *, Agedge_t *, Agedge_t *, int);
88static void place_vnlabel(Agnode_t *);
89static boxf rank_box(spline_info_t *sp, Agraph_t *, int);
90static void recover_slack(Agedge_t *, path *);
91static void resize_vn(Agnode_t *, double, double, double);
92static void setflags(Agedge_t *, int, int, int);
93static int straight_len(Agnode_t *);
94static Agedge_t *straight_path(Agedge_t *, int, points_t *);
95static Agedge_t *top_bound(Agedge_t *, int);
96
97#define GROWEDGES \
98 do { \
99 edges = gv_recalloc(edges, n_edges, n_edges + CHUNK, sizeof(edge_t *)); \
100 } while (0)
101
103 edge_t *le = e;
104 while (ED_to_virt(le))
105 le = ED_to_virt(le);
106 while (ED_to_orig(le))
107 le = ED_to_orig(le);
108 return le;
109}
110
111static bool spline_merge(node_t *n) {
112 return ND_node_type(n) == VIRTUAL &&
113 (ND_in(n).size > 1 || ND_out(n).size > 1);
114}
115
116static bool swap_ends_p(edge_t *e) {
117 while (ED_to_orig(e))
118 e = ED_to_orig(e);
119 if (ND_rank(aghead(e)) > ND_rank(agtail(e)))
120 return false;
121 if (ND_rank(aghead(e)) < ND_rank(agtail(e)))
122 return true;
123 if (ND_order(aghead(e)) >= ND_order(agtail(e)))
124 return false;
125 return true;
126}
127
129 .splineMerge = spline_merge};
130
131int portcmp(port p0, port p1) {
132 if (!p1.defined)
133 return p0.defined ? 1 : 0;
134 if (!p0.defined)
135 return -1;
136 if (p0.p.x < p1.p.x)
137 return -1;
138 if (p0.p.x > p1.p.x)
139 return 1;
140 if (p0.p.y < p1.p.y)
141 return -1;
142 if (p0.p.y > p1.p.y)
143 return 1;
144 return 0;
145}
146
147static void swap_bezier(bezier *b) {
148 const size_t sz = b->size;
149 for (size_t i = 0; i < sz / 2; ++i) { // reverse list of points
150 pointf tmp = b->list[i];
151 b->list[i] = b->list[sz - 1 - i];
152 b->list[sz - 1 - i] = tmp;
153 }
154
155 {
156 uint32_t tmp = b->sflag;
157 b->sflag = b->eflag;
158 b->eflag = tmp;
159 }
160 {
161 pointf tmp = b->sp;
162 b->sp = b->ep;
163 b->ep = tmp;
164 }
165}
166
167static void swap_spline(splines *s) {
168 const size_t sz = s->size;
169
170 // reverse list
171 for (size_t i = 0; i < sz / 2; ++i) {
172 bezier tmp = s->list[i];
173 s->list[i] = s->list[sz - 1 - i];
174 s->list[sz - 1 - i] = tmp;
175 }
176
177 // swap beziers
178 for (size_t i = 0; i < sz; ++i) {
179 swap_bezier(&s->list[i]);
180 }
181}
182
183/* edge_normalize:
184 * Some back edges are reversed during layout and the reversed edge
185 * is used to compute the spline. We would like to guarantee that
186 * the order of control points always goes from tail to head, so
187 * we reverse them if necessary.
188 */
189static void edge_normalize(graph_t *g) {
190 edge_t *e;
191 node_t *n;
192
193 for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
194 for (e = agfstout(g, n); e; e = agnxtout(g, e)) {
195 if (sinfo.swapEnds(e) && ED_spl(e))
197 }
198 }
199}
200
201/* resetRW:
202 * In position, each node has its rw stored in mval and,
203 * if a node is part of a loop, rw may be increased to
204 * reflect the loops and associated labels. We restore
205 * the original value here.
206 */
207static void resetRW(graph_t *g) {
208 node_t *n;
209
210 for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
211 if (ND_other(n).list) {
212 double tmp = ND_rw(n);
213 ND_rw(n) = ND_mval(n);
214 ND_mval(n) = tmp;
215 }
216 }
217}
218
219/* setEdgeLabelPos:
220 * Set edge label position information for regular and non-adjacent flat edges.
221 * Dot has allocated space and position for these labels. This info will be
222 * used when routing orthogonal edges.
223 */
224static void setEdgeLabelPos(graph_t *g) {
225 node_t *n;
226 textlabel_t *l;
227
228 /* place regular edge labels */
229 for (n = GD_nlist(g); n; n = ND_next(n)) {
230 if (ND_node_type(n) == VIRTUAL) {
231 if (ND_alg(n)) { // label of non-adjacent flat edge
232 edge_t *fe = ND_alg(n);
233 l = ED_label(fe);
234 assert(l);
235 l->pos = ND_coord(n);
236 l->set = true;
237 } else if ((l = ND_label(n))) { // label of regular edge
238 place_vnlabel(n);
239 }
240 if (l)
241 updateBB(g, l);
242 }
243 }
244}
245
252static void dot_splines_(graph_t *g, int normalize) {
253 int i, j, k, n_nodes;
254 node_t *n;
255 Agedgeinfo_t fwdedgeai, fwdedgebi;
256 Agedgepair_t fwdedgea, fwdedgeb;
257 edge_t *e, *e0, *e1, *ea, *eb, *le0, *le1, **edges = NULL;
258 path P = {0};
259 int et = EDGE_TYPE(g);
260 fwdedgea.out.base.data = (Agrec_t *)&fwdedgeai;
261 fwdedgeb.out.base.data = (Agrec_t *)&fwdedgebi;
262
263 if (et == EDGETYPE_NONE)
264 return;
265 if (et == EDGETYPE_CURVED) {
266 resetRW(g);
267 if (GD_has_labels(g->root) & EDGE_LABEL) {
268 agwarningf("edge labels with splines=curved not supported in dot - use "
269 "xlabels\n");
270 }
271 }
272#ifdef ORTHO
273 if (et == EDGETYPE_ORTHO) {
274 resetRW(g);
275 if (GD_has_labels(g->root) & EDGE_LABEL) {
277 orthoEdges(g, true);
278 } else
279 orthoEdges(g, false);
280 goto finish;
281 }
282#else
283 (void)setEdgeLabelPos;
284#endif
285
287 if (routesplinesinit())
288 return;
289 spline_info_t sd = {.Splinesep = GD_nodesep(g) / 4,
290 .Multisep = GD_nodesep(g)};
291 edges = gv_calloc(CHUNK, sizeof(edge_t *));
292
293 /* compute boundaries and list of splines */
294 unsigned n_edges = 0;
295 n_nodes = 0;
296 for (i = GD_minrank(g); i <= GD_maxrank(g); i++) {
297 n_nodes += GD_rank(g)[i].n;
298 if ((n = GD_rank(g)[i].v[0]))
299 sd.LeftBound = MIN(sd.LeftBound, (ND_coord(n).x - ND_lw(n)));
300 if (GD_rank(g)[i].n && (n = GD_rank(g)[i].v[GD_rank(g)[i].n - 1]))
301 sd.RightBound = MAX(sd.RightBound, (ND_coord(n).x + ND_rw(n)));
302 sd.LeftBound -= MINW;
303 sd.RightBound += MINW;
304
305 for (j = 0; j < GD_rank(g)[i].n; j++) {
306 n = GD_rank(g)[i].v[j];
307 /* if n is the label of a flat edge, copy its position to
308 * the label.
309 */
310 if (ND_alg(n)) {
311 edge_t *fe = ND_alg(n);
312 assert(ED_label(fe));
313 ED_label(fe)->pos = ND_coord(n);
314 ED_label(fe)->set = true;
315 }
316 if (ND_node_type(n) != NORMAL && !sinfo.splineMerge(n))
317 continue;
318 for (k = 0; (e = ND_out(n).list[k]); k++) {
319 if (ED_edge_type(e) == FLATORDER || ED_edge_type(e) == IGNORED)
320 continue;
322 edges[n_edges++] = e;
323 if (n_edges % CHUNK == 0)
324 GROWEDGES;
325 }
326 if (ND_flat_out(n).list)
327 for (k = 0; (e = ND_flat_out(n).list[k]); k++) {
328 setflags(e, FLATEDGE, 0, AUXGRAPH);
329 edges[n_edges++] = e;
330 if (n_edges % CHUNK == 0)
331 GROWEDGES;
332 }
333 if (ND_other(n).list) {
334 /* In position, each node has its rw stored in mval and,
335 * if a node is part of a loop, rw may be increased to
336 * reflect the loops and associated labels. We restore
337 * the original value here.
338 */
339 if (ND_node_type(n) == NORMAL) {
340 double tmp = ND_rw(n);
341 ND_rw(n) = ND_mval(n);
342 ND_mval(n) = tmp;
343 }
344 for (k = 0; (e = ND_other(n).list[k]); k++) {
345 setflags(e, 0, 0, AUXGRAPH);
346 edges[n_edges++] = e;
347 if (n_edges % CHUNK == 0)
348 GROWEDGES;
349 }
350 }
351 }
352 }
353
354 /* Sort so that equivalent edges are contiguous.
355 * Equivalence should basically mean that 2 edges have the
356 * same set {(tailnode,tailport),(headnode,headport)}, or
357 * alternatively, the edges would be routed identically if
358 * routed separately.
359 */
360 qsort(edges, n_edges, sizeof(edges[0]), edgecmp);
361
362 /* FIXME: just how many boxes can there be? */
363 P.boxes = gv_calloc(n_nodes + 20 * 2 * NSUB, sizeof(boxf));
364 sd.Rank_box = gv_calloc(i, sizeof(boxf));
365
366 if (et == EDGETYPE_LINE) {
367 /* place regular edge labels */
368 for (n = GD_nlist(g); n; n = ND_next(n)) {
369 if (ND_node_type(n) == VIRTUAL && ND_label(n)) {
370 place_vnlabel(n);
371 }
372 }
373 }
374
375 for (unsigned l = 0; l < n_edges;) {
376 const unsigned ind = l;
377 le0 = getmainedge((e0 = edges[l++]));
378 if (ED_tail_port(e0).defined || ED_head_port(e0).defined) {
379 ea = e0;
380 } else {
381 ea = le0;
382 }
383 if (ED_tree_index(ea) & BWDEDGE) {
384 MAKEFWDEDGE(&fwdedgea.out, ea);
385 ea = &fwdedgea.out;
386 }
387 unsigned cnt;
388 for (cnt = 1; l < n_edges; cnt++, l++) {
389 if (le0 != (le1 = getmainedge((e1 = edges[l]))))
390 break;
391 if (ED_adjacent(e0))
392 continue; /* all flat adjacent edges at once */
393 if (ED_tail_port(e1).defined || ED_head_port(e1).defined) {
394 eb = e1;
395 } else {
396 eb = le1;
397 }
398 if (ED_tree_index(eb) & BWDEDGE) {
399 MAKEFWDEDGE(&fwdedgeb.out, eb);
400 eb = &fwdedgeb.out;
401 }
402 if (portcmp(ED_tail_port(ea), ED_tail_port(eb)))
403 break;
404 if (portcmp(ED_head_port(ea), ED_head_port(eb)))
405 break;
406 if ((ED_tree_index(e0) & EDGETYPEMASK) == FLATEDGE &&
407 ED_label(e0) != ED_label(e1))
408 break;
409 if (ED_tree_index(edges[l]) & MAINGRAPH) /* Aha! -C is on */
410 break;
411 }
412
413 if (et == EDGETYPE_CURVED) {
414 edge_t **edgelist = gv_calloc(cnt, sizeof(edge_t *));
415 edgelist[0] = getmainedge((edges + ind)[0]);
416 for (unsigned ii = 1; ii < cnt; ii++)
417 edgelist[ii] = (edges + ind)[ii];
419 free(edgelist);
420 } else if (agtail(e0) == aghead(e0)) {
421 int r;
422 double sizey;
423 n = agtail(e0);
424 r = ND_rank(n);
425 if (r == GD_maxrank(g)) {
426 if (r > 0)
427 sizey = ND_coord(GD_rank(g)[r - 1].v[0]).y - ND_coord(n).y;
428 else
429 sizey = ND_ht(n);
430 } else if (r == GD_minrank(g)) {
431 sizey = ND_coord(n).y - ND_coord(GD_rank(g)[r + 1].v[0]).y;
432 } else {
433 double upy = ND_coord(GD_rank(g)[r - 1].v[0]).y - ND_coord(n).y;
434 double dwny = ND_coord(n).y - ND_coord(GD_rank(g)[r + 1].v[0]).y;
435 sizey = MIN(upy, dwny);
436 }
437 makeSelfEdge(edges, ind, cnt, sd.Multisep, sizey / 2, &sinfo);
438 for (unsigned b = 0; b < cnt; b++) {
439 e = edges[ind + b];
440 if (ED_label(e))
441 updateBB(g, ED_label(e));
442 }
443 } else if (ND_rank(agtail(e0)) == ND_rank(aghead(e0))) {
444 make_flat_edge(g, &sd, &P, edges, ind, cnt, et);
445 } else
446 make_regular_edge(g, &sd, &P, edges, ind, cnt, et);
447 }
448
449 /* place regular edge labels */
450 for (n = GD_nlist(g); n; n = ND_next(n)) {
451 if (ND_node_type(n) == VIRTUAL && ND_label(n)) {
452 place_vnlabel(n);
453 updateBB(g, ND_label(n));
454 }
455 }
456
457 /* normalize splines so they always go from tail to head */
458 /* place_portlabel relies on this being done first */
459 if (normalize)
461
462#ifdef ORTHO
463finish:
464#endif
465 /* place port labels */
466 /* FIX: head and tail labels are not part of cluster bbox */
468 for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
469 if (E_headlabel) {
470 for (e = agfstin(g, n); e; e = agnxtin(g, e))
471 if (ED_head_label(AGMKOUT(e))) {
472 place_portlabel(AGMKOUT(e), true);
474 }
475 }
476 if (E_taillabel) {
477 for (e = agfstout(g, n); e; e = agnxtout(g, e)) {
478 if (ED_tail_label(e)) {
479 if (place_portlabel(e, false))
480 updateBB(g, ED_tail_label(e));
481 }
482 }
483 }
484 }
485 }
486
487#ifdef ORTHO
488 if (et != EDGETYPE_ORTHO && et != EDGETYPE_CURVED) {
489#else
490 if (et != EDGETYPE_CURVED) {
491#endif
492 free(sd.Rank_box);
494 }
495 free(edges);
496 free(P.boxes);
498 EdgeLabelsDone = 1;
499}
500
501/* dot_splines:
502 * If the splines attribute is defined but equal to "", skip edge routing.
503 */
505
506/* place_vnlabel:
507 * assign position of an edge label from its virtual node
508 * This is for regular edges only.
509 */
510static void place_vnlabel(node_t *n) {
511 pointf dimen;
512 double width;
513 edge_t *e;
514 if (ND_in(n).size == 0)
515 return; /* skip flat edge labels here */
516 for (e = ND_out(n).list[0]; ED_edge_type(e) != NORMAL; e = ED_to_orig(e))
517 ;
518 dimen = ED_label(e)->dimen;
519 width = GD_flip(agraphof(n)) ? dimen.y : dimen.x;
520 ED_label(e)->pos.x = ND_coord(n).x + width / 2.0;
521 ED_label(e)->pos.y = ND_coord(n).y;
522 ED_label(e)->set = true;
523}
524
525static void setflags(edge_t *e, int hint1, int hint2, int f3) {
526 int f1, f2;
527 if (hint1 != 0)
528 f1 = hint1;
529 else {
530 if (agtail(e) == aghead(e))
531 if (ED_tail_port(e).defined || ED_head_port(e).defined)
532 f1 = SELFWPEDGE;
533 else
534 f1 = SELFNPEDGE;
535 else if (ND_rank(agtail(e)) == ND_rank(aghead(e)))
536 f1 = FLATEDGE;
537 else
538 f1 = REGULAREDGE;
539 }
540 if (hint2 != 0)
541 f2 = hint2;
542 else {
543 if (f1 == REGULAREDGE)
544 f2 = ND_rank(agtail(e)) < ND_rank(aghead(e)) ? FWDEDGE : BWDEDGE;
545 else if (f1 == FLATEDGE)
546 f2 = ND_order(agtail(e)) < ND_order(aghead(e)) ? FWDEDGE : BWDEDGE;
547 else /* f1 == SELF*EDGE */
548 f2 = FWDEDGE;
549 }
550 ED_tree_index(e) = (f1 | f2 | f3);
551}
552
553/* edgecmp:
554 * lexicographically order edges by
555 * - edge type
556 * - |rank difference of nodes|
557 * - |x difference of nodes|
558 * - id of witness edge for equivalence class
559 * - port comparison
560 * - graph type
561 * - labels if flat edges
562 * - edge id
563 */
564static int edgecmp(const void *x, const void *y) {
565// Suppress Clang/GCC -Wcast-qual warning. Casting away const here is acceptable
566// as the later usage is const. We need the cast because the macros use
567// non-const pointers for genericity.
568#ifdef __GNUC__
569#pragma GCC diagnostic push
570#pragma GCC diagnostic ignored "-Wcast-qual"
571#endif
572 edge_t **ptr0 = (edge_t **)x;
573 edge_t **ptr1 = (edge_t **)y;
574#ifdef __GNUC__
575#pragma GCC diagnostic pop
576#endif
577 Agedgeinfo_t fwdedgeai, fwdedgebi;
578 Agedgepair_t fwdedgea, fwdedgeb;
579 edge_t *e0, *e1, *ea, *eb, *le0, *le1;
580 int et0, et1, v0, v1, rv;
581 double t0, t1;
582
583 fwdedgea.out.base.data = (Agrec_t *)&fwdedgeai;
584 fwdedgeb.out.base.data = (Agrec_t *)&fwdedgebi;
585 e0 = *ptr0;
586 e1 = *ptr1;
587 et0 = ED_tree_index(e0) & EDGETYPEMASK;
588 et1 = ED_tree_index(e1) & EDGETYPEMASK;
589 if (et0 < et1) {
590 return 1;
591 }
592 if (et0 > et1) {
593 return -1;
594 }
595
596 le0 = getmainedge(e0);
597 le1 = getmainedge(e1);
598
599 t0 = ND_rank(agtail(le0)) - ND_rank(aghead(le0));
600 t1 = ND_rank(agtail(le1)) - ND_rank(aghead(le1));
601 v0 = abs((int)t0); /* ugly, but explicit as to how we avoid equality tests on
602 fp numbers */
603 v1 = abs((int)t1);
604 if (v0 < v1) {
605 return -1;
606 }
607 if (v0 > v1) {
608 return 1;
609 }
610
611 t0 = ND_coord(agtail(le0)).x - ND_coord(aghead(le0)).x;
612 t1 = ND_coord(agtail(le1)).x - ND_coord(aghead(le1)).x;
613 v0 = abs((int)t0);
614 v1 = abs((int)t1);
615 if (v0 < v1) {
616 return -1;
617 }
618 if (v0 > v1) {
619 return 1;
620 }
621
622 /* This provides a cheap test for edges having the same set of endpoints. */
623 if (AGSEQ(le0) < AGSEQ(le1)) {
624 return -1;
625 }
626 if (AGSEQ(le0) > AGSEQ(le1)) {
627 return 1;
628 }
629
630 ea = (ED_tail_port(e0).defined || ED_head_port(e0).defined) ? e0 : le0;
631 if (ED_tree_index(ea) & BWDEDGE) {
632 MAKEFWDEDGE(&fwdedgea.out, ea);
633 ea = &fwdedgea.out;
634 }
635 eb = (ED_tail_port(e1).defined || ED_head_port(e1).defined) ? e1 : le1;
636 if (ED_tree_index(eb) & BWDEDGE) {
637 MAKEFWDEDGE(&fwdedgeb.out, eb);
638 eb = &fwdedgeb.out;
639 }
640 if ((rv = portcmp(ED_tail_port(ea), ED_tail_port(eb))))
641 return rv;
642 if ((rv = portcmp(ED_head_port(ea), ED_head_port(eb))))
643 return rv;
644
645 et0 = ED_tree_index(e0) & GRAPHTYPEMASK;
646 et1 = ED_tree_index(e1) & GRAPHTYPEMASK;
647 if (et0 < et1) {
648 return -1;
649 }
650 if (et0 > et1) {
651 return 1;
652 }
653
654 if (et0 == FLATEDGE) {
655 if (ED_label(e0) < ED_label(e1)) {
656 return -1;
657 }
658 if (ED_label(e0) > ED_label(e1)) {
659 return 1;
660 }
661 }
662
663 if (AGSEQ(e0) < AGSEQ(e1)) {
664 return -1;
665 }
666 if (AGSEQ(e0) > AGSEQ(e1)) {
667 return 1;
668 }
669 return 0;
670}
671
716
717static void setState(graph_t *auxg, attr_state_t *attr_state) {
718 /* save state */
719 attr_state->E_constr = E_constr;
720 attr_state->E_dir = E_dir;
721 attr_state->E_samehead = E_samehead;
722 attr_state->E_sametail = E_sametail;
723 attr_state->E_weight = E_weight;
724 attr_state->E_minlen = E_minlen;
725 attr_state->E_fontcolor = E_fontcolor;
726 attr_state->E_fontname = E_fontname;
727 attr_state->E_fontsize = E_fontsize;
728 attr_state->E_headclip = E_headclip;
729 attr_state->E_headlabel = E_headlabel;
730 attr_state->E_label = E_label;
731 attr_state->E_label_float = E_label_float;
733 attr_state->E_labelfontname = E_labelfontname;
734 attr_state->E_labelfontsize = E_labelfontsize;
735 attr_state->E_tailclip = E_tailclip;
736 attr_state->E_taillabel = E_taillabel;
737 attr_state->E_xlabel = E_xlabel;
738 attr_state->N_height = N_height;
739 attr_state->N_width = N_width;
740 attr_state->N_shape = N_shape;
741 attr_state->N_style = N_style;
742 attr_state->N_fontsize = N_fontsize;
743 attr_state->N_fontname = N_fontname;
744 attr_state->N_fontcolor = N_fontcolor;
745 attr_state->N_label = N_label;
746 attr_state->N_xlabel = N_xlabel;
747 attr_state->N_showboxes = N_showboxes;
748 attr_state->N_ordering = N_ordering;
749 attr_state->N_sides = N_sides;
750 attr_state->N_peripheries = N_peripheries;
751 attr_state->N_skew = N_skew;
752 attr_state->N_orientation = N_orientation;
753 attr_state->N_distortion = N_distortion;
754 attr_state->N_fixed = N_fixed;
755 attr_state->N_nojustify = N_nojustify;
756 attr_state->N_group = N_group;
757 attr_state->State = State;
758 attr_state->G_ordering = G_ordering;
759
760 E_constr = NULL;
761 E_dir = agattr(auxg, AGEDGE, "dir", NULL);
762 E_samehead = agattr(auxg, AGEDGE, "samehead", NULL);
763 E_sametail = agattr(auxg, AGEDGE, "sametail", NULL);
764 E_weight = agattr(auxg, AGEDGE, "weight", NULL);
765 if (!E_weight)
766 E_weight = agattr(auxg, AGEDGE, "weight", "");
767 E_minlen = NULL;
769 E_fontname = agfindedgeattr(auxg, "fontname");
770 E_fontsize = agfindedgeattr(auxg, "fontsize");
771 E_headclip = agfindedgeattr(auxg, "headclip");
773 E_label = agfindedgeattr(auxg, "label");
774 E_label_float = agfindedgeattr(auxg, "label_float");
776 E_labelfontname = agfindedgeattr(auxg, "labelfontname");
777 E_labelfontsize = agfindedgeattr(auxg, "labelfontsize");
778 E_tailclip = agfindedgeattr(auxg, "tailclip");
780 E_xlabel = NULL;
781 N_height = agfindnodeattr(auxg, "height");
782 N_width = agfindnodeattr(auxg, "width");
783 N_shape = agfindnodeattr(auxg, "shape");
784 N_style = NULL;
785 N_fontsize = agfindnodeattr(auxg, "fontsize");
786 N_fontname = agfindnodeattr(auxg, "fontname");
788 N_label = agfindnodeattr(auxg, "label");
789 N_xlabel = NULL;
791 N_ordering = agfindnodeattr(auxg, "ordering");
792 N_sides = agfindnodeattr(auxg, "sides");
793 N_peripheries = agfindnodeattr(auxg, "peripheries");
794 N_skew = agfindnodeattr(auxg, "skew");
795 N_orientation = agfindnodeattr(auxg, "orientation");
796 N_distortion = agfindnodeattr(auxg, "distortion");
797 N_fixed = agfindnodeattr(auxg, "fixed");
799 N_group = NULL;
800 G_ordering = agfindgraphattr(auxg, "ordering");
801}
802
803/* cloneGraph:
804 * Create clone graph. It stores the global Agsyms, to be
805 * restored in cleanupCloneGraph. The graph uses the main
806 * graph's settings for certain geometry parameters, and
807 * declares all node and edge attributes used in the original
808 * graph.
809 */
810static graph_t *cloneGraph(graph_t *g, attr_state_t *attr_state) {
811 Agsym_t *sym;
812 graph_t *auxg;
813 if (agisdirected(g))
814 auxg = agopen("auxg", Agdirected, NULL);
815 else
816 auxg = agopen("auxg", Agundirected, NULL);
817 agbindrec(auxg, "Agraphinfo_t", sizeof(Agraphinfo_t), true);
818 agattr(auxg, AGRAPH, "rank", "");
819 GD_drawing(auxg) = gv_alloc(sizeof(layout_t));
820 GD_drawing(auxg)->quantum = GD_drawing(g)->quantum;
821 GD_drawing(auxg)->dpi = GD_drawing(g)->dpi;
822
823 GD_charset(auxg) = GD_charset(g);
824 if (GD_flip(g))
825 SET_RANKDIR(auxg, RANKDIR_TB);
826 else
827 SET_RANKDIR(auxg, RANKDIR_LR);
828 GD_nodesep(auxg) = GD_nodesep(g);
829 GD_ranksep(auxg) = GD_ranksep(g);
830
831 // copy node attrs to auxg
832 sym = agnxtattr(agroot(g), AGNODE, NULL); // get the first attr.
833 for (; sym; sym = agnxtattr(agroot(g), AGNODE, sym)) {
834 const bool is_html = aghtmlstr(sym->defval);
835 is_html ? agattr_html(auxg, AGNODE, sym->name, sym->defval)
836 : agattr(auxg, AGNODE, sym->name, sym->defval);
837 }
838
839 // copy edge attributes
840 sym = agnxtattr(agroot(g), AGEDGE, NULL); // get the first attr.
841 for (; sym; sym = agnxtattr(agroot(g), AGEDGE, sym)) {
842 const bool is_html = aghtmlstr(sym->defval);
843 is_html ? agattr_html(auxg, AGEDGE, sym->name, sym->defval)
844 : agattr(auxg, AGEDGE, sym->name, sym->defval);
845 }
846
847 if (!agattr(auxg, AGEDGE, "headport", NULL))
848 agattr(auxg, AGEDGE, "headport", "");
849 if (!agattr(auxg, AGEDGE, "tailport", NULL))
850 agattr(auxg, AGEDGE, "tailport", "");
851
852 setState(auxg, attr_state);
853
854 return auxg;
855}
856
857static void cleanupCloneGraph(graph_t *g, attr_state_t *attr_state) {
858 /* restore main graph syms */
859 E_constr = attr_state->E_constr;
860 E_dir = attr_state->E_dir;
861 E_samehead = attr_state->E_samehead;
862 E_sametail = attr_state->E_sametail;
863 E_weight = attr_state->E_weight;
864 E_minlen = attr_state->E_minlen;
865 E_fontcolor = attr_state->E_fontcolor;
866 E_fontname = attr_state->E_fontname;
867 E_fontsize = attr_state->E_fontsize;
868 E_headclip = attr_state->E_headclip;
869 E_headlabel = attr_state->E_headlabel;
870 E_label = attr_state->E_label;
871 E_label_float = attr_state->E_label_float;
873 E_labelfontname = attr_state->E_labelfontname;
874 E_labelfontsize = attr_state->E_labelfontsize;
875 E_tailclip = attr_state->E_tailclip;
876 E_taillabel = attr_state->E_taillabel;
877 E_xlabel = attr_state->E_xlabel;
878 N_height = attr_state->N_height;
879 N_width = attr_state->N_width;
880 N_shape = attr_state->N_shape;
881 N_style = attr_state->N_style;
882 N_fontsize = attr_state->N_fontsize;
883 N_fontname = attr_state->N_fontname;
884 N_fontcolor = attr_state->N_fontcolor;
885 N_label = attr_state->N_label;
886 N_xlabel = attr_state->N_xlabel;
887 N_showboxes = attr_state->N_showboxes;
888 N_ordering = attr_state->N_ordering;
889 N_sides = attr_state->N_sides;
890 N_peripheries = attr_state->N_peripheries;
891 N_skew = attr_state->N_skew;
892 N_orientation = attr_state->N_orientation;
893 N_distortion = attr_state->N_distortion;
894 N_fixed = attr_state->N_fixed;
895 N_nojustify = attr_state->N_nojustify;
896 N_group = attr_state->N_group;
897 G_ordering = attr_state->G_ordering;
898 State = attr_state->State;
899
900 dot_cleanup(g);
901 agclose(g);
902}
903
904/* cloneNode:
905 * If original graph has rankdir=LR or RL, records change shape,
906 * so we wrap a record node's label in "{...}" to prevent this.
907 */
908static node_t *cloneNode(graph_t *g, node_t *orign) {
909 node_t *n = agnode(g, agnameof(orign), 1);
910 agbindrec(n, "Agnodeinfo_t", sizeof(Agnodeinfo_t), true);
911 agcopyattr(orign, n);
912 if (shapeOf(orign) == SH_RECORD) {
913 agxbuf buf = {0};
914 agxbprint(&buf, "{%s}", ND_label(orign)->text);
915 agset(n, "label", agxbuse(&buf));
916 agxbfree(&buf);
917 }
918
919 return n;
920}
921
922static edge_t *cloneEdge(graph_t *g, node_t *tn, node_t *hn, edge_t *orig) {
923 edge_t *e = agedge(g, tn, hn, NULL, 1);
924 agbindrec(e, "Agedgeinfo_t", sizeof(Agedgeinfo_t), true);
925 agcopyattr(orig, e);
926
927 return e;
928}
929
930/* transformf:
931 * Rotate, if necessary, then translate points.
932 */
933static pointf transformf(pointf p, pointf del, int flip) {
934 if (flip) {
935 double i = p.x;
936 p.x = p.y;
937 p.y = -i;
938 }
939 return add_pointf(p, del);
940}
941
942/* edgelblcmpfn:
943 * lexicographically order edges by
944 * - has label
945 * - label is wider
946 * - label is higher
947 */
948static int edgelblcmpfn(const void *x, const void *y) {
949// Suppress Clang/GCC -Wcast-qual warning. Casting away const here is acceptable
950// as the later usage is const. We need the cast because the macros use
951// non-const pointers for genericity.
952#ifdef __GNUC__
953#pragma GCC diagnostic push
954#pragma GCC diagnostic ignored "-Wcast-qual"
955#endif
956 edge_t **ptr0 = (edge_t **)x;
957 edge_t **ptr1 = (edge_t **)y;
958#ifdef __GNUC__
959#pragma GCC diagnostic pop
960#endif
961 pointf sz0, sz1;
962
963 edge_t *e0 = *ptr0;
964 edge_t *e1 = *ptr1;
965
966 if (ED_label(e0)) {
967 if (ED_label(e1)) {
968 sz0 = ED_label(e0)->dimen;
969 sz1 = ED_label(e1)->dimen;
970 if (sz0.x > sz1.x)
971 return -1;
972 if (sz0.x < sz1.x)
973 return 1;
974 if (sz0.y > sz1.y)
975 return -1;
976 if (sz0.y < sz1.y)
977 return 1;
978 return 0;
979 }
980 return -1;
981 }
982 if (ED_label(e1)) {
983 return 1;
984 }
985 return 0;
986}
987
988#define LBL_SPACE 6 /* space between labels, in points */
989
990/* makeSimpleFlatLabels:
991 * This handles the second simplest case for flat edges between
992 * two adjacent nodes. We still invoke a dot on a rotated problem
993 * to handle edges with ports. This usually works, but fails for
994 * records because of their weird nature.
995 */
996static void makeSimpleFlatLabels(node_t *tn, node_t *hn, edge_t **edges,
997 unsigned ind, unsigned cnt, int et,
998 unsigned n_lbls) {
1000 edge_t *e = edges[ind];
1001 pointf points[10], tp, hp;
1002 double leftend, rightend, ctrx, ctry, miny, maxy;
1003 double uminx, umaxx;
1004 double lminx = 0.0, lmaxx = 0.0;
1005
1006 edge_t **earray = gv_calloc(cnt, sizeof(edge_t *));
1007
1008 for (unsigned i = 0; i < cnt; i++) {
1009 earray[i] = edges[ind + i];
1010 }
1011
1012 qsort(earray, cnt, sizeof(edge_t *), edgelblcmpfn);
1013
1014 tp = add_pointf(ND_coord(tn), ED_tail_port(e).p);
1015 hp = add_pointf(ND_coord(hn), ED_head_port(e).p);
1016
1017 leftend = tp.x + ND_rw(tn);
1018 rightend = hp.x - ND_lw(hn);
1019 ctrx = (leftend + rightend) / 2.0;
1020
1021 /* do first edge */
1022 e = earray[0];
1023 size_t pointn = 0;
1024 points[pointn++] = tp;
1025 points[pointn++] = tp;
1026 points[pointn++] = hp;
1027 points[pointn++] = hp;
1028 clip_and_install(e, aghead(e), points, pointn, &sinfo);
1029 ED_label(e)->pos.x = ctrx;
1030 ED_label(e)->pos.y = tp.y + (ED_label(e)->dimen.y + LBL_SPACE) / 2.0;
1031 ED_label(e)->set = true;
1032
1033 miny = tp.y + LBL_SPACE / 2.0;
1034 maxy = miny + ED_label(e)->dimen.y;
1035 uminx = ctrx - ED_label(e)->dimen.x / 2.0;
1036 umaxx = ctrx + ED_label(e)->dimen.x / 2.0;
1037
1038 unsigned i;
1039 for (i = 1; i < n_lbls; i++) {
1040 e = earray[i];
1041 if (i % 2) { /* down */
1042 if (i == 1) {
1043 lminx = ctrx - ED_label(e)->dimen.x / 2.0;
1044 lmaxx = ctrx + ED_label(e)->dimen.x / 2.0;
1045 }
1046 miny -= LBL_SPACE + ED_label(e)->dimen.y;
1047 points[0] = tp;
1048 points[1].x = tp.x;
1049 points[1].y = miny - LBL_SPACE;
1050 points[2].x = hp.x;
1051 points[2].y = points[1].y;
1052 points[3] = hp;
1053 points[4].x = lmaxx;
1054 points[4].y = hp.y;
1055 points[5].x = lmaxx;
1056 points[5].y = miny;
1057 points[6].x = lminx;
1058 points[6].y = miny;
1059 points[7].x = lminx;
1060 points[7].y = tp.y;
1061 ctry = miny + ED_label(e)->dimen.y / 2.0;
1062 } else { /* up */
1063 points[0] = tp;
1064 points[1].x = uminx;
1065 points[1].y = tp.y;
1066 points[2].x = uminx;
1067 points[2].y = maxy;
1068 points[3].x = umaxx;
1069 points[3].y = maxy;
1070 points[4].x = umaxx;
1071 points[4].y = hp.y;
1072 points[5].x = hp.x;
1073 points[5].y = hp.y;
1074 points[6].x = hp.x;
1075 points[6].y = maxy + LBL_SPACE;
1076 points[7].x = tp.x;
1077 points[7].y = maxy + LBL_SPACE;
1078 ctry = maxy + ED_label(e)->dimen.y / 2.0 + LBL_SPACE;
1079 maxy += ED_label(e)->dimen.y + LBL_SPACE;
1080 }
1081 poly.pn = 8;
1082 poly.ps = (Ppoint_t *)points;
1083 size_t pn;
1084 pointf *ps = simpleSplineRoute(tp, hp, poly, &pn, et == EDGETYPE_PLINE);
1085 if (ps == NULL || pn == 0) {
1086 free(ps);
1087 free(earray);
1088 return;
1089 }
1090 ED_label(e)->pos.x = ctrx;
1091 ED_label(e)->pos.y = ctry;
1092 ED_label(e)->set = true;
1093 clip_and_install(e, aghead(e), ps, pn, &sinfo);
1094 free(ps);
1095 }
1096
1097 /* edges with no labels */
1098 for (; i < cnt; i++) {
1099 e = earray[i];
1100 if (i % 2) { /* down */
1101 if (i == 1) {
1102 lminx = (2 * leftend + rightend) / 3.0;
1103 lmaxx = (leftend + 2 * rightend) / 3.0;
1104 }
1105 miny -= LBL_SPACE;
1106 points[0] = tp;
1107 points[1].x = tp.x;
1108 points[1].y = miny - LBL_SPACE;
1109 points[2].x = hp.x;
1110 points[2].y = points[1].y;
1111 points[3] = hp;
1112 points[4].x = lmaxx;
1113 points[4].y = hp.y;
1114 points[5].x = lmaxx;
1115 points[5].y = miny;
1116 points[6].x = lminx;
1117 points[6].y = miny;
1118 points[7].x = lminx;
1119 points[7].y = tp.y;
1120 } else { /* up */
1121 points[0] = tp;
1122 points[1].x = uminx;
1123 points[1].y = tp.y;
1124 points[2].x = uminx;
1125 points[2].y = maxy;
1126 points[3].x = umaxx;
1127 points[3].y = maxy;
1128 points[4].x = umaxx;
1129 points[4].y = hp.y;
1130 points[5].x = hp.x;
1131 points[5].y = hp.y;
1132 points[6].x = hp.x;
1133 points[6].y = maxy + LBL_SPACE;
1134 points[7].x = tp.x;
1135 points[7].y = maxy + LBL_SPACE;
1136 maxy += +LBL_SPACE;
1137 }
1138 poly.pn = 8;
1139 poly.ps = (Ppoint_t *)points;
1140 size_t pn;
1141 pointf *ps = simpleSplineRoute(tp, hp, poly, &pn, et == EDGETYPE_PLINE);
1142 if (ps == NULL || pn == 0) {
1143 free(ps);
1144 free(earray);
1145 return;
1146 }
1147 clip_and_install(e, aghead(e), ps, pn, &sinfo);
1148 free(ps);
1149 }
1150
1151 free(earray);
1152}
1153
1154static void makeSimpleFlat(node_t *tn, node_t *hn, edge_t **edges, unsigned ind,
1155 unsigned cnt, int et) {
1156 edge_t *e = edges[ind];
1157 pointf points[10], tp, hp;
1158 double stepy, dy;
1159
1160 tp = add_pointf(ND_coord(tn), ED_tail_port(e).p);
1161 hp = add_pointf(ND_coord(hn), ED_head_port(e).p);
1162
1163 stepy = cnt > 1 ? ND_ht(tn) / (double)(cnt - 1) : 0.;
1164 dy = tp.y - (cnt > 1 ? ND_ht(tn) / 2. : 0.);
1165
1166 for (unsigned i = 0; i < cnt; i++) {
1167 e = edges[ind + i];
1168 size_t pointn = 0;
1169 if (et == EDGETYPE_SPLINE || et == EDGETYPE_LINE) {
1170 points[pointn++] = tp;
1171 points[pointn++] = (pointf){(2 * tp.x + hp.x) / 3, dy};
1172 points[pointn++] = (pointf){(2 * hp.x + tp.x) / 3, dy};
1173 points[pointn++] = hp;
1174 } else { /* EDGETYPE_PLINE */
1175 points[pointn++] = tp;
1176 points[pointn++] = tp;
1177 points[pointn++] = (pointf){(2 * tp.x + hp.x) / 3, dy};
1178 points[pointn++] = (pointf){(2 * tp.x + hp.x) / 3, dy};
1179 points[pointn++] = (pointf){(2 * tp.x + hp.x) / 3, dy};
1180 points[pointn++] = (pointf){(2 * hp.x + tp.x) / 3, dy};
1181 points[pointn++] = (pointf){(2 * hp.x + tp.x) / 3, dy};
1182 points[pointn++] = (pointf){(2 * hp.x + tp.x) / 3, dy};
1183 points[pointn++] = hp;
1184 points[pointn++] = hp;
1185 }
1186 dy += stepy;
1187 clip_and_install(e, aghead(e), points, pointn, &sinfo);
1188 }
1189}
1190
1191/* make_flat_adj_edges:
1192 * In the simple case, with no labels or ports, this creates a simple
1193 * spindle of splines.
1194 * If there are only labels, cobble something together.
1195 * Otherwise, we run dot recursively on the 2 nodes and the edges,
1196 * essentially using rankdir=LR, to get the needed spline info.
1197 * This is probably to cute and fragile, and should be rewritten in a
1198 * more straightforward and laborious fashion.
1199 */
1200static void make_flat_adj_edges(graph_t *g, edge_t **edges, unsigned ind,
1201 unsigned cnt, edge_t *e0, int et) {
1202 node_t *n;
1203 node_t *tn, *hn;
1204 edge_t *e;
1205 graph_t *auxg;
1206 graph_t *subg;
1207 node_t *auxt, *auxh;
1208 edge_t *auxe;
1209 double midx, midy, leftx, rightx;
1210 pointf del;
1211 edge_t *hvye = NULL;
1212 static atomic_flag warned;
1213
1214 tn = agtail(e0), hn = aghead(e0);
1215 if (shapeOf(tn) == SH_RECORD || shapeOf(hn) == SH_RECORD) {
1216 if (!atomic_flag_test_and_set(&warned)) {
1217 agwarningf("flat edge between adjacent nodes one of which has a record "
1218 "shape - replace records with HTML-like labels\n");
1219 agerr(AGPREV, " Edge %s %s %s\n", agnameof(tn),
1220 agisdirected(g) ? "->" : "--", agnameof(hn));
1221 }
1222 return;
1223 }
1224 unsigned labels = 0;
1225 bool ports = false;
1226 for (unsigned i = 0; i < cnt; i++) {
1227 e = edges[ind + i];
1228 if (ED_label(e))
1229 labels++;
1230 if (ED_tail_port(e).defined || ED_head_port(e).defined)
1231 ports = true;
1232 }
1233
1234 if (!ports) {
1235 /* flat edges without ports and labels can go straight left to right */
1236 if (labels == 0) {
1237 makeSimpleFlat(tn, hn, edges, ind, cnt, et);
1238 }
1239 /* flat edges without ports but with labels take more work */
1240 else {
1241 makeSimpleFlatLabels(tn, hn, edges, ind, cnt, et, labels);
1242 }
1243 return;
1244 }
1245
1246 attr_state_t attrs = {0};
1247 auxg = cloneGraph(g, &attrs);
1248 subg = agsubg(auxg, "xxx", 1);
1249 agbindrec(subg, "Agraphinfo_t", sizeof(Agraphinfo_t), true);
1250 agset(subg, "rank", "source");
1251 rightx = ND_coord(hn).x;
1252 leftx = ND_coord(tn).x;
1253 if (GD_flip(g)) {
1254 node_t *tmp = tn;
1255 tn = hn;
1256 hn = tmp;
1257 }
1258 auxt = cloneNode(subg, tn);
1259 auxh = cloneNode(auxg, hn);
1260 for (unsigned i = 0; i < cnt; i++) {
1261 e = edges[ind + i];
1262 for (; ED_edge_type(e) != NORMAL; e = ED_to_orig(e))
1263 ;
1264 if (agtail(e) == tn)
1265 auxe = cloneEdge(auxg, auxt, auxh, e);
1266 else
1267 auxe = cloneEdge(auxg, auxh, auxt, e);
1268 ED_alg(e) = auxe;
1269 if (!hvye && !ED_tail_port(e).defined && !ED_head_port(e).defined) {
1270 hvye = auxe;
1271 ED_alg(hvye) = e;
1272 }
1273 }
1274 if (!hvye) {
1275 hvye = agedge(auxg, auxt, auxh, NULL, 1);
1276 }
1277 agxset(hvye, E_weight, "10000");
1278 GD_gvc(auxg) = GD_gvc(g);
1279 GD_dotroot(auxg) = auxg;
1280 setEdgeType(auxg, et);
1281 dot_init_node_edge(auxg);
1282
1283 dot_rank(auxg);
1284 dot_mincross(auxg);
1285 dot_position(auxg);
1286
1287 /* reposition */
1288 midx = (ND_coord(tn).x - ND_rw(tn) + ND_coord(hn).x + ND_lw(hn)) / 2;
1289 midy = (ND_coord(auxt).x + ND_coord(auxh).x) / 2;
1290 for (n = GD_nlist(auxg); n; n = ND_next(n)) {
1291 if (n == auxt) {
1292 ND_coord(n).y = rightx;
1293 ND_coord(n).x = midy;
1294 } else if (n == auxh) {
1295 ND_coord(n).y = leftx;
1296 ND_coord(n).x = midy;
1297 } else
1298 ND_coord(n).y = midx;
1299 }
1300 dot_sameports(auxg);
1301 dot_splines_(auxg, 0);
1303
1304 /* copy splines */
1305 if (GD_flip(g)) {
1306 del.x = ND_coord(tn).x - ND_coord(auxt).y;
1307 del.y = ND_coord(tn).y + ND_coord(auxt).x;
1308 } else {
1309 del.x = ND_coord(tn).x - ND_coord(auxt).x;
1310 del.y = ND_coord(tn).y - ND_coord(auxt).y;
1311 }
1312 for (unsigned i = 0; i < cnt; i++) {
1313 bezier *auxbz;
1314 bezier *bz;
1315
1316 e = edges[ind + i];
1317 for (; ED_edge_type(e) != NORMAL; e = ED_to_orig(e))
1318 ;
1319 auxe = ED_alg(e);
1320 if ((auxe == hvye) & !ED_alg(auxe))
1321 continue; /* pseudo-edge */
1322 auxbz = ED_spl(auxe)->list;
1323 bz = new_spline(e, auxbz->size);
1324 bz->sflag = auxbz->sflag;
1325 bz->sp = transformf(auxbz->sp, del, GD_flip(g));
1326 bz->eflag = auxbz->eflag;
1327 bz->ep = transformf(auxbz->ep, del, GD_flip(g));
1328 for (size_t j = 0; j < auxbz->size;) {
1329 pointf cp[4];
1330 cp[0] = bz->list[j] = transformf(auxbz->list[j], del, GD_flip(g));
1331 j++;
1332 if (j >= auxbz->size)
1333 break;
1334 cp[1] = bz->list[j] = transformf(auxbz->list[j], del, GD_flip(g));
1335 j++;
1336 cp[2] = bz->list[j] = transformf(auxbz->list[j], del, GD_flip(g));
1337 j++;
1338 cp[3] = transformf(auxbz->list[j], del, GD_flip(g));
1339 update_bb_bz(&GD_bb(g), cp);
1340 }
1341 if (ED_label(e)) {
1342 ED_label(e)->pos = transformf(ED_label(auxe)->pos, del, GD_flip(g));
1343 ED_label(e)->set = true;
1344 updateBB(g, ED_label(e));
1345 }
1346 }
1347
1348 cleanupCloneGraph(auxg, &attrs);
1349}
1350
1351static void makeFlatEnd(graph_t *g, spline_info_t *sp, path *P, node_t *n,
1352 edge_t *e, pathend_t *endp, bool isBegin) {
1353 boxf b;
1354
1355 b = endp->nb = maximal_bbox(g, sp, n, NULL, e);
1356 endp->sidemask = TOP;
1357 if (isBegin)
1358 beginpath(P, e, FLATEDGE, endp, false);
1359 else
1360 endpath(P, e, FLATEDGE, endp, false);
1361 b.UR.y = endp->boxes[endp->boxn - 1].UR.y;
1362 b.LL.y = endp->boxes[endp->boxn - 1].LL.y;
1363 b = makeregularend(b, TOP, ND_coord(n).y + GD_rank(g)[ND_rank(n)].ht2);
1364 if (b.LL.x < b.UR.x && b.LL.y < b.UR.y)
1365 endp->boxes[endp->boxn++] = b;
1366}
1367
1369 edge_t *e, pathend_t *endp, bool isBegin) {
1370 boxf b;
1371
1372 b = endp->nb = maximal_bbox(g, sp, n, NULL, e);
1373 endp->sidemask = BOTTOM;
1374 if (isBegin)
1375 beginpath(P, e, FLATEDGE, endp, false);
1376 else
1377 endpath(P, e, FLATEDGE, endp, false);
1378 b.UR.y = endp->boxes[endp->boxn - 1].UR.y;
1379 b.LL.y = endp->boxes[endp->boxn - 1].LL.y;
1380 b = makeregularend(b, BOTTOM, ND_coord(n).y - GD_rank(g)[ND_rank(n)].ht2);
1381 if (b.LL.x < b.UR.x && b.LL.y < b.UR.y)
1382 endp->boxes[endp->boxn++] = b;
1383}
1384
1386 edge_t *e, int et) {
1387 node_t *tn, *hn, *ln;
1388 pointf *ps;
1389 bool ps_needs_free = false;
1390 pathend_t tend, hend;
1391 boxf lb;
1392 int i;
1393 edge_t *f;
1394 pointf points[7];
1395
1396 tn = agtail(e);
1397 hn = aghead(e);
1398
1399 for (f = ED_to_virt(e); ED_to_virt(f); f = ED_to_virt(f))
1400 ;
1401 ln = agtail(f);
1402 ED_label(e)->pos = ND_coord(ln);
1403 ED_label(e)->set = true;
1404
1405 size_t pn;
1406 if (et == EDGETYPE_LINE) {
1407 pointf startp, endp, lp;
1408
1409 startp = add_pointf(ND_coord(tn), ED_tail_port(e).p);
1410 endp = add_pointf(ND_coord(hn), ED_head_port(e).p);
1411
1412 lp = ED_label(e)->pos;
1413 lp.y -= ED_label(e)->dimen.y / 2.0;
1414 points[1] = points[0] = startp;
1415 points[2] = points[3] = points[4] = lp;
1416 points[5] = points[6] = endp;
1417 ps = points;
1418 pn = 7;
1419 } else {
1420 lb.LL.x = ND_coord(ln).x - ND_lw(ln);
1421 lb.UR.x = ND_coord(ln).x + ND_rw(ln);
1422 lb.UR.y = ND_coord(ln).y + ND_ht(ln) / 2;
1423 double ydelta = ND_coord(ln).y - GD_rank(g)[ND_rank(tn)].ht1 -
1424 ND_coord(tn).y + GD_rank(g)[ND_rank(tn)].ht2;
1425 ydelta /= 6;
1426 lb.LL.y = lb.UR.y - MAX(5, ydelta);
1427
1428 makeFlatEnd(g, sp, P, tn, e, &tend, true);
1429 makeFlatEnd(g, sp, P, hn, e, &hend, false);
1430
1431 boxf boxes[] = {
1432 {
1433 .LL =
1434 {
1435 .x = tend.boxes[tend.boxn - 1].LL.x,
1436 .y = tend.boxes[tend.boxn - 1].UR.y,
1437 },
1438 .UR = lb.LL,
1439 },
1440 {
1441 .LL =
1442 {
1443 .x = tend.boxes[tend.boxn - 1].LL.x,
1444 .y = lb.LL.y,
1445 },
1446 .UR =
1447 {
1448 .x = hend.boxes[hend.boxn - 1].UR.x,
1449 .y = lb.UR.y,
1450 },
1451 },
1452 {
1453 .LL =
1454 {
1455 .x = lb.UR.x,
1456 .y = hend.boxes[hend.boxn - 1].UR.y,
1457 },
1458 .UR =
1459 {
1460 .x = hend.boxes[hend.boxn - 1].UR.x,
1461 .y = lb.LL.y,
1462 },
1463 },
1464 };
1465 const size_t boxn = sizeof(boxes) / sizeof(boxes[0]);
1466
1467 for (i = 0; i < tend.boxn; i++)
1468 add_box(P, tend.boxes[i]);
1469 for (size_t j = 0; j < boxn; j++)
1470 add_box(P, boxes[j]);
1471 for (i = hend.boxn - 1; i >= 0; i--)
1472 add_box(P, hend.boxes[i]);
1473
1474 ps_needs_free = true;
1475 if (et == EDGETYPE_SPLINE)
1476 ps = routesplines(P, &pn);
1477 else
1478 ps = routepolylines(P, &pn);
1479 if (pn == 0) {
1480 free(ps);
1481 return;
1482 }
1483 }
1484 clip_and_install(e, aghead(e), ps, pn, &sinfo);
1485 if (ps_needs_free)
1486 free(ps);
1487}
1488
1490 edge_t **edges, unsigned ind, unsigned cnt,
1491 edge_t *e, bool use_splines) {
1492 node_t *tn, *hn;
1493 int j, r;
1494 double stepx, stepy, vspace;
1495 rank_t *nextr;
1496 pathend_t tend, hend;
1497
1498 tn = agtail(e);
1499 hn = aghead(e);
1500 r = ND_rank(tn);
1501 if (r < GD_maxrank(g)) {
1502 nextr = GD_rank(g) + (r + 1);
1503 vspace = ND_coord(tn).y - GD_rank(g)[r].pht1 -
1504 (ND_coord(nextr->v[0]).y + nextr->pht2);
1505 } else {
1506 vspace = GD_ranksep(g);
1507 }
1508 stepx = sp->Multisep / (cnt + 1);
1509 stepy = vspace / (cnt + 1);
1510
1511 makeBottomFlatEnd(g, sp, P, tn, e, &tend, true);
1512 makeBottomFlatEnd(g, sp, P, hn, e, &hend, false);
1513
1514 for (unsigned i = 0; i < cnt; i++) {
1515 boxf b;
1516 e = edges[ind + i];
1517 size_t boxn = 0;
1518
1519 boxf boxes[3];
1520
1521 b = tend.boxes[tend.boxn - 1];
1522 boxes[boxn].LL.x = b.LL.x;
1523 boxes[boxn].UR.y = b.LL.y;
1524 boxes[boxn].UR.x = b.UR.x + (i + 1) * stepx;
1525 boxes[boxn].LL.y = b.LL.y - (i + 1) * stepy;
1526 boxn++;
1527 boxes[boxn].LL.x = tend.boxes[tend.boxn - 1].LL.x;
1528 boxes[boxn].UR.y = boxes[boxn - 1].LL.y;
1529 boxes[boxn].UR.x = hend.boxes[hend.boxn - 1].UR.x;
1530 boxes[boxn].LL.y = boxes[boxn].UR.y - stepy;
1531 boxn++;
1532 b = hend.boxes[hend.boxn - 1];
1533 boxes[boxn].UR.x = b.UR.x;
1534 boxes[boxn].UR.y = b.LL.y;
1535 boxes[boxn].LL.x = b.LL.x - (i + 1) * stepx;
1536 boxes[boxn].LL.y = boxes[boxn - 1].UR.y;
1537 boxn++;
1538 assert(boxn == sizeof(boxes) / sizeof(boxes[0]));
1539
1540 for (j = 0; j < tend.boxn; j++)
1541 add_box(P, tend.boxes[j]);
1542 for (size_t k = 0; k < boxn; k++)
1543 add_box(P, boxes[k]);
1544 for (j = hend.boxn - 1; j >= 0; j--)
1545 add_box(P, hend.boxes[j]);
1546
1547 pointf *ps = NULL;
1548 size_t pn = 0;
1549 if (use_splines)
1550 ps = routesplines(P, &pn);
1551 else
1552 ps = routepolylines(P, &pn);
1553 if (pn == 0) {
1554 free(ps);
1555 return;
1556 }
1557 clip_and_install(e, aghead(e), ps, pn, &sinfo);
1558 free(ps);
1559 P->nbox = 0;
1560 }
1561}
1562
1563/* make_flat_edge:
1564 * Construct flat edges edges[ind...ind+cnt-1]
1565 * There are 4 main cases:
1566 * - all edges between a and b where a and b are adjacent
1567 * - one labeled edge
1568 * - all non-labeled edges with identical ports between non-adjacent a and b
1569 * = connecting bottom to bottom/left/right - route along bottom
1570 * = the rest - route along top
1571 */
1573 edge_t **edges, unsigned ind, unsigned cnt, int et) {
1574 node_t *tn, *hn;
1575 Agedgeinfo_t fwdedgei;
1576 Agedgepair_t fwdedge;
1577 edge_t *e;
1578 int j, r;
1579 double stepx, stepy, vspace;
1580 int tside, hside;
1581 pathend_t tend, hend;
1582
1583 fwdedge.out.base.data = (Agrec_t *)&fwdedgei;
1584
1585 /* Get sample edge; normalize to go from left to right */
1586 e = edges[ind];
1587 bool isAdjacent = ED_adjacent(e) != 0;
1588 if (ED_tree_index(e) & BWDEDGE) {
1589 MAKEFWDEDGE(&fwdedge.out, e);
1590 e = &fwdedge.out;
1591 }
1592 for (unsigned i = 1; i < cnt; i++) {
1593 if (ED_adjacent(edges[ind + i])) {
1594 isAdjacent = true;
1595 break;
1596 }
1597 }
1598 /* The lead edge edges[ind] might not have been marked earlier as adjacent,
1599 * so check them all.
1600 */
1601 if (isAdjacent) {
1602 make_flat_adj_edges(g, edges, ind, cnt, e, et);
1603 return;
1604 }
1605 if (ED_label(e)) { /* edges with labels aren't multi-edges */
1606 make_flat_labeled_edge(g, sp, P, e, et);
1607 return;
1608 }
1609
1610 if (et == EDGETYPE_LINE) {
1611 makeSimpleFlat(agtail(e), aghead(e), edges, ind, cnt, et);
1612 return;
1613 }
1614
1615 tside = ED_tail_port(e).side;
1616 hside = ED_head_port(e).side;
1617 if ((tside == BOTTOM && hside != TOP) || (hside == BOTTOM && tside != TOP)) {
1618 make_flat_bottom_edges(g, sp, P, edges, ind, cnt, e, et == EDGETYPE_SPLINE);
1619 return;
1620 }
1621
1622 tn = agtail(e);
1623 hn = aghead(e);
1624 r = ND_rank(tn);
1625 if (r > 0) {
1626 rank_t *prevr;
1627 if (GD_has_labels(g->root) & EDGE_LABEL)
1628 prevr = GD_rank(g) + (r - 2);
1629 else
1630 prevr = GD_rank(g) + (r - 1);
1631 vspace = ND_coord(prevr->v[0]).y - prevr->ht1 - ND_coord(tn).y -
1632 GD_rank(g)[r].ht2;
1633 } else {
1634 vspace = GD_ranksep(g);
1635 }
1636 stepx = sp->Multisep / (cnt + 1);
1637 stepy = vspace / (cnt + 1);
1638
1639 makeFlatEnd(g, sp, P, tn, e, &tend, true);
1640 makeFlatEnd(g, sp, P, hn, e, &hend, false);
1641
1642 for (unsigned i = 0; i < cnt; i++) {
1643 boxf b;
1644 e = edges[ind + i];
1645 size_t boxn = 0;
1646
1647 boxf boxes[3];
1648
1649 b = tend.boxes[tend.boxn - 1];
1650 boxes[boxn].LL.x = b.LL.x;
1651 boxes[boxn].LL.y = b.UR.y;
1652 boxes[boxn].UR.x = b.UR.x + (i + 1) * stepx;
1653 boxes[boxn].UR.y = b.UR.y + (i + 1) * stepy;
1654 boxn++;
1655 boxes[boxn].LL.x = tend.boxes[tend.boxn - 1].LL.x;
1656 boxes[boxn].LL.y = boxes[boxn - 1].UR.y;
1657 boxes[boxn].UR.x = hend.boxes[hend.boxn - 1].UR.x;
1658 boxes[boxn].UR.y = boxes[boxn].LL.y + stepy;
1659 boxn++;
1660 b = hend.boxes[hend.boxn - 1];
1661 boxes[boxn].UR.x = b.UR.x;
1662 boxes[boxn].LL.y = b.UR.y;
1663 boxes[boxn].LL.x = b.LL.x - (i + 1) * stepx;
1664 boxes[boxn].UR.y = boxes[boxn - 1].LL.y;
1665 boxn++;
1666 assert(boxn == sizeof(boxes) / sizeof(boxes[0]));
1667
1668 for (j = 0; j < tend.boxn; j++)
1669 add_box(P, tend.boxes[j]);
1670 for (size_t k = 0; k < boxn; k++)
1671 add_box(P, boxes[k]);
1672 for (j = hend.boxn - 1; j >= 0; j--)
1673 add_box(P, hend.boxes[j]);
1674
1675 pointf *ps = NULL;
1676 size_t pn = 0;
1677 if (et == EDGETYPE_SPLINE)
1678 ps = routesplines(P, &pn);
1679 else
1680 ps = routepolylines(P, &pn);
1681 if (pn == 0) {
1682 free(ps);
1683 return;
1684 }
1685 clip_and_install(e, aghead(e), ps, pn, &sinfo);
1686 free(ps);
1687 P->nbox = 0;
1688 }
1689}
1690
1692static bool leftOf(pointf p1, pointf p2, pointf p3) {
1693 return (p1.y - p2.y) * (p3.x - p2.x) - (p3.y - p2.y) * (p1.x - p2.x) > 0;
1694}
1695
1696/* makeLineEdge:
1697 * Create an edge as line segment. We guarantee that the points
1698 * are always drawn downwards. This means that for flipped edges,
1699 * we draw from the head to the tail. The routine returns the
1700 * end node of the edge in *hp. The points are stored in the
1701 * given array of points, and the number of points is returned.
1702 *
1703 * If the edge has a label, the edge is draw as two segments, with
1704 * the bend near the label.
1705 *
1706 * If the endpoints are on adjacent ranks, revert to usual code by
1707 * returning 0.
1708 * This is done because the usual code handles the interaction of
1709 * multiple edges better.
1710 */
1711static int makeLineEdge(graph_t *g, edge_t *fe, points_t *points, node_t **hp) {
1712 int delr, pn;
1713 node_t *hn;
1714 node_t *tn;
1715 edge_t *e = fe;
1716 pointf startp, endp, lp;
1717 pointf dimen;
1718 double width, height;
1719
1720 while (ED_edge_type(e) != NORMAL)
1721 e = ED_to_orig(e);
1722 hn = aghead(e);
1723 tn = agtail(e);
1724 delr = abs(ND_rank(hn) - ND_rank(tn));
1725 if (delr == 1 || (delr == 2 && (GD_has_labels(g->root) & EDGE_LABEL)))
1726 return 0;
1727 if (agtail(fe) == agtail(e)) {
1728 *hp = hn;
1729 startp = add_pointf(ND_coord(tn), ED_tail_port(e).p);
1730 endp = add_pointf(ND_coord(hn), ED_head_port(e).p);
1731 } else {
1732 *hp = tn;
1733 startp = add_pointf(ND_coord(hn), ED_head_port(e).p);
1734 endp = add_pointf(ND_coord(tn), ED_tail_port(e).p);
1735 }
1736
1737 if (ED_label(e)) {
1738 dimen = ED_label(e)->dimen;
1739 if (GD_flip(agraphof(hn))) {
1740 width = dimen.y;
1741 height = dimen.x;
1742 } else {
1743 width = dimen.x;
1744 height = dimen.y;
1745 }
1746
1747 lp = ED_label(e)->pos;
1748 if (leftOf(endp, startp, lp)) {
1749 lp.x += width / 2.0;
1750 lp.y -= height / 2.0;
1751 } else {
1752 lp.x -= width / 2.0;
1753 lp.y += height / 2.0;
1754 }
1755
1756 points_append(points, startp);
1757 points_append(points, startp);
1758 points_append(points, lp);
1759 points_append(points, lp);
1760 points_append(points, lp);
1761 points_append(points, endp);
1762 points_append(points, endp);
1763 pn = 7;
1764 } else {
1765 points_append(points, startp);
1766 points_append(points, startp);
1767 points_append(points, endp);
1768 points_append(points, endp);
1769 pn = 4;
1770 }
1771
1772 return pn;
1773}
1774
1776 edge_t **edges, unsigned ind, unsigned cnt,
1777 int et) {
1778 node_t *tn, *hn;
1779 Agedgeinfo_t fwdedgeai, fwdedgebi, fwdedgei;
1780 Agedgepair_t fwdedgea, fwdedgeb, fwdedge;
1781 edge_t *e, *fe, *le, *segfirst;
1782 pathend_t tend, hend;
1783 boxf b;
1784 int sl, si;
1785 points_t pointfs = {0};
1786 points_t pointfs2 = {0};
1787
1788 fwdedgea.out.base.data = (Agrec_t *)&fwdedgeai;
1789 fwdedgeb.out.base.data = (Agrec_t *)&fwdedgebi;
1790 fwdedge.out.base.data = (Agrec_t *)&fwdedgei;
1791
1792 sl = 0;
1793 e = edges[ind];
1794 bool hackflag = false;
1795 if (abs(ND_rank(agtail(e)) - ND_rank(aghead(e))) > 1) {
1796 fwdedgeai = *(Agedgeinfo_t *)e->base.data;
1797 fwdedgea.out = *e;
1798 fwdedgea.in = *AGOUT2IN(e);
1799 fwdedgea.out.base.data = (Agrec_t *)&fwdedgeai;
1800 if (ED_tree_index(e) & BWDEDGE) {
1801 MAKEFWDEDGE(&fwdedgeb.out, e);
1802 agtail(&fwdedgea.out) = aghead(e);
1803 ED_tail_port(&fwdedgea.out) = ED_head_port(e);
1804 } else {
1805 fwdedgebi = *(Agedgeinfo_t *)e->base.data;
1806 fwdedgeb.out = *e;
1807 fwdedgeb.out.base.data = (Agrec_t *)&fwdedgebi;
1808 agtail(&fwdedgea.out) = agtail(e);
1809 fwdedgeb.in = *AGOUT2IN(e);
1810 }
1811 le = getmainedge(e);
1812 while (ED_to_virt(le))
1813 le = ED_to_virt(le);
1814 aghead(&fwdedgea.out) = aghead(le);
1815 ED_head_port(&fwdedgea.out).defined = false;
1816 ED_edge_type(&fwdedgea.out) = VIRTUAL;
1817 ED_head_port(&fwdedgea.out).p.x = ED_head_port(&fwdedgea.out).p.y = 0;
1818 ED_to_orig(&fwdedgea.out) = e;
1819 e = &fwdedgea.out;
1820 hackflag = true;
1821 } else {
1822 if (ED_tree_index(e) & BWDEDGE) {
1823 MAKEFWDEDGE(&fwdedgea.out, e);
1824 e = &fwdedgea.out;
1825 }
1826 }
1827 fe = e;
1828
1829 /* compute the spline points for the edge */
1830
1831 if (et == EDGETYPE_LINE && makeLineEdge(g, fe, &pointfs, &hn)) {
1832 } else {
1833 bool is_spline = et == EDGETYPE_SPLINE;
1834 boxes_t boxes = {0};
1835 segfirst = e;
1836 tn = agtail(e);
1837 hn = aghead(e);
1838 b = tend.nb = maximal_bbox(g, sp, tn, NULL, e);
1839 beginpath(P, e, REGULAREDGE, &tend, spline_merge(tn));
1840 b.UR.y = tend.boxes[tend.boxn - 1].UR.y;
1841 b.LL.y = tend.boxes[tend.boxn - 1].LL.y;
1842 b = makeregularend(b, BOTTOM, ND_coord(tn).y - GD_rank(g)[ND_rank(tn)].ht1);
1843 if (b.LL.x < b.UR.x && b.LL.y < b.UR.y)
1844 tend.boxes[tend.boxn++] = b;
1845 bool smode = false;
1846 si = -1;
1847 while (ND_node_type(hn) == VIRTUAL && !sinfo.splineMerge(hn)) {
1848 boxes_append(&boxes, rank_box(sp, g, ND_rank(tn)));
1849 if (!smode && ((sl = straight_len(hn)) >=
1850 ((GD_has_labels(g->root) & EDGE_LABEL) ? 4 + 1 : 2 + 1))) {
1851 smode = true;
1852 si = 1, sl -= 2;
1853 }
1854 if (!smode || si > 0) {
1855 si--;
1856 boxes_append(&boxes, maximal_bbox(g, sp, hn, e, ND_out(hn).list[0]));
1857 e = ND_out(hn).list[0];
1858 tn = agtail(e);
1859 hn = aghead(e);
1860 continue;
1861 }
1862 hend.nb = maximal_bbox(g, sp, hn, e, ND_out(hn).list[0]);
1863 endpath(P, e, REGULAREDGE, &hend, spline_merge(aghead(e)));
1864 b = makeregularend(hend.boxes[hend.boxn - 1], TOP,
1865 ND_coord(hn).y + GD_rank(g)[ND_rank(hn)].ht2);
1866 if (b.LL.x < b.UR.x && b.LL.y < b.UR.y)
1867 hend.boxes[hend.boxn++] = b;
1868 P->end.theta = M_PI / 2, P->end.constrained = true;
1869 completeregularpath(P, segfirst, e, &tend, &hend, &boxes);
1870 pointf *ps = NULL;
1871 size_t pn = 0;
1872 if (is_spline)
1873 ps = routesplines(P, &pn);
1874 else {
1875 ps = routepolylines(P, &pn);
1876 if (et == EDGETYPE_LINE && pn > 4) {
1877 ps[1] = ps[0];
1878 ps[3] = ps[2] = ps[pn - 1];
1879 pn = 4;
1880 }
1881 }
1882 if (pn == 0) {
1883 free(ps);
1884 boxes_free(&boxes);
1885 points_free(&pointfs);
1886 points_free(&pointfs2);
1887 return;
1888 }
1889
1890 for (size_t i = 0; i < pn; i++) {
1891 points_append(&pointfs, ps[i]);
1892 }
1893 free(ps);
1894 e = straight_path(ND_out(hn).list[0], sl, &pointfs);
1895 recover_slack(segfirst, P);
1896 segfirst = e;
1897 tn = agtail(e);
1898 hn = aghead(e);
1899 boxes_clear(&boxes);
1900 tend.nb = maximal_bbox(g, sp, tn, ND_in(tn).list[0], e);
1901 beginpath(P, e, REGULAREDGE, &tend, spline_merge(tn));
1902 b = makeregularend(tend.boxes[tend.boxn - 1], BOTTOM,
1903 ND_coord(tn).y - GD_rank(g)[ND_rank(tn)].ht1);
1904 if (b.LL.x < b.UR.x && b.LL.y < b.UR.y)
1905 tend.boxes[tend.boxn++] = b;
1906 P->start.theta = -M_PI / 2, P->start.constrained = true;
1907 smode = false;
1908 }
1909 boxes_append(&boxes, rank_box(sp, g, ND_rank(tn)));
1910 b = hend.nb = maximal_bbox(g, sp, hn, e, NULL);
1911 endpath(P, hackflag ? &fwdedgeb.out : e, REGULAREDGE, &hend,
1912 spline_merge(aghead(e)));
1913 b.UR.y = hend.boxes[hend.boxn - 1].UR.y;
1914 b.LL.y = hend.boxes[hend.boxn - 1].LL.y;
1915 b = makeregularend(b, TOP, ND_coord(hn).y + GD_rank(g)[ND_rank(hn)].ht2);
1916 if (b.LL.x < b.UR.x && b.LL.y < b.UR.y)
1917 hend.boxes[hend.boxn++] = b;
1918 completeregularpath(P, segfirst, e, &tend, &hend, &boxes);
1919 boxes_free(&boxes);
1920 pointf *ps = NULL;
1921 size_t pn = 0;
1922 if (is_spline)
1923 ps = routesplines(P, &pn);
1924 else
1925 ps = routepolylines(P, &pn);
1926 if (et == EDGETYPE_LINE && pn > 4) {
1927 /* Here we have used the polyline case to handle
1928 * an edge between two nodes on adjacent ranks. If the
1929 * results really is a polyline, straighten it.
1930 */
1931 ps[1] = ps[0];
1932 ps[3] = ps[2] = ps[pn - 1];
1933 pn = 4;
1934 }
1935 if (pn == 0) {
1936 free(ps);
1937 points_free(&pointfs);
1938 points_free(&pointfs2);
1939 return;
1940 }
1941 for (size_t i = 0; i < pn; i++) {
1942 points_append(&pointfs, ps[i]);
1943 }
1944 free(ps);
1945 recover_slack(segfirst, P);
1946 hn = hackflag ? aghead(&fwdedgeb.out) : aghead(e);
1947 }
1948
1949 /* make copies of the spline points, one per multi-edge */
1950
1951 if (cnt == 1) {
1952 points_sync(&pointfs);
1953 clip_and_install(fe, hn, points_front(&pointfs), points_size(&pointfs),
1954 &sinfo);
1955 points_free(&pointfs);
1956 points_free(&pointfs2);
1957 return;
1958 }
1959 const double dx = sp->Multisep * (cnt - 1) / 2;
1960 for (size_t k = 1; k + 1 < points_size(&pointfs); k++)
1961 points_at(&pointfs, k)->x -= dx;
1962
1963 for (size_t k = 0; k < points_size(&pointfs); k++)
1964 points_append(&pointfs2, points_get(&pointfs, k));
1965 points_sync(&pointfs2);
1966 clip_and_install(fe, hn, points_front(&pointfs2), points_size(&pointfs2),
1967 &sinfo);
1968 for (unsigned j = 1; j < cnt; j++) {
1969 e = edges[ind + j];
1970 if (ED_tree_index(e) & BWDEDGE) {
1971 MAKEFWDEDGE(&fwdedge.out, e);
1972 e = &fwdedge.out;
1973 }
1974 for (size_t k = 1; k + 1 < points_size(&pointfs); k++)
1975 points_at(&pointfs, k)->x += sp->Multisep;
1976 points_clear(&pointfs2);
1977 for (size_t k = 0; k < points_size(&pointfs); k++)
1978 points_append(&pointfs2, points_get(&pointfs, k));
1979 points_sync(&pointfs2);
1980 clip_and_install(e, aghead(e), points_front(&pointfs2),
1981 points_size(&pointfs2), &sinfo);
1982 }
1983 points_free(&pointfs);
1984 points_free(&pointfs2);
1985}
1986
1987/* regular edges */
1988
1989static void completeregularpath(path *P, edge_t *first, edge_t *last,
1990 pathend_t *tendp, pathend_t *hendp,
1991 const boxes_t *boxes) {
1992 edge_t *uleft, *uright, *lleft, *lright;
1993
1994 uleft = uright = NULL;
1995 uleft = top_bound(first, -1), uright = top_bound(first, 1);
1996 if (uleft) {
1997 if (getsplinepoints(uleft) == NULL)
1998 return;
1999 }
2000 if (uright) {
2001 if (getsplinepoints(uright) == NULL)
2002 return;
2003 }
2004 lleft = lright = NULL;
2005 lleft = bot_bound(last, -1), lright = bot_bound(last, 1);
2006 if (lleft) {
2007 if (getsplinepoints(lleft) == NULL)
2008 return;
2009 }
2010 if (lright) {
2011 if (getsplinepoints(lright) == NULL)
2012 return;
2013 }
2014 for (int i = 0; i < tendp->boxn; i++)
2015 add_box(P, tendp->boxes[i]);
2016 const size_t fb = P->nbox + 1;
2017 const size_t lb = fb + boxes_size(boxes) - 3;
2018 for (size_t i = 0; i < boxes_size(boxes); i++)
2019 add_box(P, boxes_get(boxes, i));
2020 for (int i = hendp->boxn - 1; i >= 0; i--)
2021 add_box(P, hendp->boxes[i]);
2022 adjustregularpath(P, fb, lb);
2023}
2024
2025/* makeregularend:
2026 * Add box to fill between node and interrank space. Needed because
2027 * nodes in a given rank can differ in height.
2028 * for now, regular edges always go from top to bottom
2029 */
2030static boxf makeregularend(boxf b, int side, double y) {
2031 assert(side == BOTTOM || side == TOP);
2032 if (side == BOTTOM) {
2033 return (boxf){{b.LL.x, y}, {b.UR.x, b.LL.y}};
2034 }
2035 return (boxf){{b.LL.x, b.UR.y}, {b.UR.x, y}};
2036}
2037
2038/* adjustregularpath:
2039 * make sure the path is wide enough.
2040 * the % 2 was so that in rank boxes would only be grown if
2041 * they were == 0 while inter-rank boxes could be stretched to a min
2042 * width.
2043 * The list of boxes has three parts: tail boxes, path boxes, and head
2044 * boxes. (Note that because of back edges, the tail boxes might actually
2045 * belong to the head node, and vice versa.) fb is the index of the
2046 * first interrank path box and lb is the last interrank path box.
2047 * If fb > lb, there are none.
2048 *
2049 * The second for loop was added by ek long ago, and apparently is intended
2050 * to guarantee an overlap between adjacent boxes of at least MINW.
2051 * It doesn't do this.
2052 */
2053static void adjustregularpath(path *P, size_t fb, size_t lb) {
2054 boxf *bp1, *bp2;
2055
2056 for (size_t i = fb - 1; i < lb + 1; i++) {
2057 bp1 = &P->boxes[i];
2058 if ((i - fb) % 2 == 0) {
2059 if (bp1->LL.x >= bp1->UR.x) {
2060 double x = (bp1->LL.x + bp1->UR.x) / 2;
2061 bp1->LL.x = x - HALFMINW;
2062 bp1->UR.x = x + HALFMINW;
2063 }
2064 } else {
2065 if (bp1->LL.x + MINW > bp1->UR.x) {
2066 double x = (bp1->LL.x + bp1->UR.x) / 2;
2067 bp1->LL.x = x - HALFMINW;
2068 bp1->UR.x = x + HALFMINW;
2069 }
2070 }
2071 }
2072 for (size_t i = 0; i + 1 < P->nbox; i++) {
2073 bp1 = &P->boxes[i], bp2 = &P->boxes[i + 1];
2074 if (i >= fb && i <= lb && (i - fb) % 2 == 0) {
2075 if (bp1->LL.x + MINW > bp2->UR.x)
2076 bp2->UR.x = bp1->LL.x + MINW;
2077 if (bp1->UR.x - MINW < bp2->LL.x)
2078 bp2->LL.x = bp1->UR.x - MINW;
2079 } else if (i + 1 >= fb && i < lb && (i + 1 - fb) % 2 == 0) {
2080 if (bp1->LL.x + MINW > bp2->UR.x)
2081 bp1->LL.x = bp2->UR.x - MINW;
2082 if (bp1->UR.x - MINW < bp2->LL.x)
2083 bp1->UR.x = bp2->LL.x + MINW;
2084 }
2085 }
2086}
2087
2088static boxf rank_box(spline_info_t *sp, graph_t *g, int r) {
2089 boxf b;
2090 node_t *left0, *left1;
2091
2092 b = sp->Rank_box[r];
2093 if (b.LL.x == b.UR.x) {
2094 left0 = GD_rank(g)[r].v[0];
2095 left1 = GD_rank(g)[r + 1].v[0];
2096 b.LL.x = sp->LeftBound;
2097 b.LL.y = ND_coord(left1).y + GD_rank(g)[r + 1].ht2;
2098 b.UR.x = sp->RightBound;
2099 b.UR.y = ND_coord(left0).y - GD_rank(g)[r].ht1;
2100 sp->Rank_box[r] = b;
2101 }
2102 return b;
2103}
2104
2105/* returns count of vertically aligned edges starting at n */
2106static int straight_len(node_t *n) {
2107 int cnt = 0;
2108 node_t *v;
2109
2110 v = n;
2111 while (1) {
2112 v = aghead(ND_out(v).list[0]);
2113 if (ND_node_type(v) != VIRTUAL)
2114 break;
2115 if (ND_out(v).size != 1 || ND_in(v).size != 1)
2116 break;
2117 if (ND_coord(v).x != ND_coord(n).x)
2118 break;
2119 cnt++;
2120 }
2121 return cnt;
2122}
2123
2124static edge_t *straight_path(edge_t *e, int cnt, points_t *plist) {
2125 edge_t *f = e;
2126
2127 while (cnt--)
2128 f = ND_out(aghead(f)).list[0];
2129 assert(!points_is_empty(plist));
2130 points_append(plist, points_get(plist, points_size(plist) - 1));
2131 points_append(plist, points_get(plist, points_size(plist) - 1));
2132
2133 return f;
2134}
2135
2136static void recover_slack(edge_t *e, path *p) {
2137 node_t *vn;
2138
2139 size_t b = 0; // skip first rank box
2140 for (vn = aghead(e); ND_node_type(vn) == VIRTUAL && !sinfo.splineMerge(vn);
2141 vn = aghead(ND_out(vn).list[0])) {
2142 while (b < p->nbox && p->boxes[b].LL.y > ND_coord(vn).y)
2143 b++;
2144 if (b >= p->nbox)
2145 break;
2146 if (p->boxes[b].UR.y < ND_coord(vn).y)
2147 continue;
2148 if (ND_label(vn))
2149 resize_vn(vn, p->boxes[b].LL.x, p->boxes[b].UR.x,
2150 p->boxes[b].UR.x + ND_rw(vn));
2151 else
2152 resize_vn(vn, p->boxes[b].LL.x, (p->boxes[b].LL.x + p->boxes[b].UR.x) / 2,
2153 p->boxes[b].UR.x);
2154 }
2155}
2156
2157static void resize_vn(node_t *vn, double lx, double cx, double rx) {
2158 ND_coord(vn).x = cx;
2159 ND_lw(vn) = cx - lx, ND_rw(vn) = rx - cx;
2160}
2161
2162/* side > 0 means right. side < 0 means left */
2163static edge_t *top_bound(edge_t *e, int side) {
2164 edge_t *f, *ans = NULL;
2165 int i;
2166
2167 for (i = 0; (f = ND_out(agtail(e)).list[i]); i++) {
2168 if (side * (ND_order(aghead(f)) - ND_order(aghead(e))) <= 0)
2169 continue;
2170 if (ED_spl(f) == NULL &&
2171 (ED_to_orig(f) == NULL || ED_spl(ED_to_orig(f)) == NULL))
2172 continue;
2173 if (ans == NULL || side * (ND_order(aghead(ans)) - ND_order(aghead(f))) > 0)
2174 ans = f;
2175 }
2176 return ans;
2177}
2178
2179static edge_t *bot_bound(edge_t *e, int side) {
2180 edge_t *f, *ans = NULL;
2181 int i;
2182
2183 for (i = 0; (f = ND_in(aghead(e)).list[i]); i++) {
2184 if (side * (ND_order(agtail(f)) - ND_order(agtail(e))) <= 0)
2185 continue;
2186 if (ED_spl(f) == NULL &&
2187 (ED_to_orig(f) == NULL || ED_spl(ED_to_orig(f)) == NULL))
2188 continue;
2189 if (ans == NULL || side * (ND_order(agtail(ans)) - ND_order(agtail(f))) > 0)
2190 ans = f;
2191 }
2192 return ans;
2193}
2194
2195/* common routines */
2196
2197static bool cl_vninside(graph_t *cl, node_t *n) {
2198 return BETWEEN(GD_bb(cl).LL.x, ND_coord(n).x, GD_bb(cl).UR.x) &&
2199 BETWEEN(GD_bb(cl).LL.y, ND_coord(n).y, GD_bb(cl).UR.y);
2200}
2201
2202/* All nodes belong to some cluster, which may be the root graph.
2203 * For the following, we only want a cluster if it is a real cluster
2204 * It is not clear this will handle all potential problems. It seems one
2205 * could have hcl and tcl contained in cl, which would also cause problems.
2206 */
2207#define REAL_CLUSTER(n) (ND_clust(n) == g ? NULL : ND_clust(n))
2208
2209/* returns the cluster of (adj) that interferes with n,
2210 */
2211static Agraph_t *cl_bound(graph_t *g, node_t *n, node_t *adj) {
2212 graph_t *rv, *cl, *tcl, *hcl;
2213 edge_t *orig;
2214
2215 rv = NULL;
2216 if (ND_node_type(n) == NORMAL)
2217 tcl = hcl = ND_clust(n);
2218 else {
2219 orig = ED_to_orig(ND_out(n).list[0]);
2220 tcl = ND_clust(agtail(orig));
2221 hcl = ND_clust(aghead(orig));
2222 }
2223 if (ND_node_type(adj) == NORMAL) {
2224 cl = REAL_CLUSTER(adj);
2225 if (cl && cl != tcl && cl != hcl)
2226 rv = cl;
2227 } else {
2228 orig = ED_to_orig(ND_out(adj).list[0]);
2229 cl = REAL_CLUSTER(agtail(orig));
2230 if (cl && cl != tcl && cl != hcl && cl_vninside(cl, adj))
2231 rv = cl;
2232 else {
2233 cl = REAL_CLUSTER(aghead(orig));
2234 if (cl && cl != tcl && cl != hcl && cl_vninside(cl, adj))
2235 rv = cl;
2236 }
2237 }
2238 return rv;
2239}
2240
2241/* maximal_bbox:
2242 * Return an initial bounding box to be used for building the
2243 * beginning or ending of the path of boxes.
2244 * Height reflects height of tallest node on rank.
2245 * The extra space provided by FUDGE allows begin/endpath to create a box
2246 * FUDGE-2 away from the node, so the routing can avoid the node and the
2247 * box is at least 2 wide.
2248 */
2249#define FUDGE 4
2250
2252 edge_t *oe) {
2253 double b, nb;
2254 graph_t *left_cl, *right_cl;
2255 node_t *left, *right;
2256 boxf rv;
2257
2258 left_cl = right_cl = NULL;
2259
2260 /* give this node all the available space up to its neighbors */
2261 b = (double)(ND_coord(vn).x - ND_lw(vn) - FUDGE);
2262 if ((left = neighbor(g, vn, ie, oe, -1))) {
2263 if ((left_cl = cl_bound(g, vn, left)))
2264 nb = GD_bb(left_cl).UR.x + sp->Splinesep;
2265 else {
2266 nb = (double)(ND_coord(left).x + ND_mval(left));
2267 if (ND_node_type(left) == NORMAL)
2268 nb += GD_nodesep(g) / 2.;
2269 else
2270 nb += sp->Splinesep;
2271 }
2272 if (nb < b)
2273 b = nb;
2274 rv.LL.x = round(b);
2275 } else
2276 rv.LL.x = fmin(round(b), sp->LeftBound);
2277
2278 /* we have to leave room for our own label! */
2279 if (ND_node_type(vn) == VIRTUAL && ND_label(vn))
2280 b = (double)(ND_coord(vn).x + 10);
2281 else
2282 b = (double)(ND_coord(vn).x + ND_rw(vn) + FUDGE);
2283 if ((right = neighbor(g, vn, ie, oe, 1))) {
2284 if ((right_cl = cl_bound(g, vn, right)))
2285 nb = GD_bb(right_cl).LL.x - sp->Splinesep;
2286 else {
2287 nb = ND_coord(right).x - ND_lw(right);
2288 if (ND_node_type(right) == NORMAL)
2289 nb -= GD_nodesep(g) / 2.;
2290 else
2291 nb -= sp->Splinesep;
2292 }
2293 if (nb > b)
2294 b = nb;
2295 rv.UR.x = round(b);
2296 } else
2297 rv.UR.x = fmax(round(b), sp->RightBound);
2298
2299 if (ND_node_type(vn) == VIRTUAL && ND_label(vn)) {
2300 rv.UR.x -= ND_rw(vn);
2301 if (rv.UR.x < rv.LL.x)
2302 rv.UR.x = ND_coord(vn).x;
2303 }
2304
2305 rv.LL.y = ND_coord(vn).y - GD_rank(g)[ND_rank(vn)].ht1;
2306 rv.UR.y = ND_coord(vn).y + GD_rank(g)[ND_rank(vn)].ht2;
2307 return rv;
2308}
2309
2310static node_t *neighbor(graph_t *g, node_t *vn, edge_t *ie, edge_t *oe,
2311 int dir) {
2312 int i;
2313 node_t *n, *rv = NULL;
2314 rank_t *rank = &(GD_rank(g)[ND_rank(vn)]);
2315
2316 for (i = ND_order(vn) + dir; i >= 0 && i < rank->n; i += dir) {
2317 n = rank->v[i];
2318 if (ND_node_type(n) == VIRTUAL && ND_label(n)) {
2319 rv = n;
2320 break;
2321 }
2322 if (ND_node_type(n) == NORMAL) {
2323 rv = n;
2324 break;
2325 }
2326 if (!pathscross(n, vn, ie, oe)) {
2327 rv = n;
2328 break;
2329 }
2330 }
2331 return rv;
2332}
2333
2334static bool pathscross(node_t *n0, node_t *n1, edge_t *ie1, edge_t *oe1) {
2335 edge_t *e0, *e1;
2336 node_t *na, *nb;
2337 int order, cnt;
2338
2339 order = ND_order(n0) > ND_order(n1);
2340 if (ND_out(n0).size != 1 && ND_out(n1).size != 1)
2341 return false;
2342 e1 = oe1;
2343 if (ND_out(n0).size == 1 && e1) {
2344 e0 = ND_out(n0).list[0];
2345 for (cnt = 0; cnt < 2; cnt++) {
2346 if ((na = aghead(e0)) == (nb = aghead(e1)))
2347 break;
2348 if (order != (ND_order(na) > ND_order(nb)))
2349 return true;
2350 if (ND_out(na).size != 1 || ND_node_type(na) == NORMAL)
2351 break;
2352 e0 = ND_out(na).list[0];
2353 if (ND_out(nb).size != 1 || ND_node_type(nb) == NORMAL)
2354 break;
2355 e1 = ND_out(nb).list[0];
2356 }
2357 }
2358 e1 = ie1;
2359 if (ND_in(n0).size == 1 && e1) {
2360 e0 = ND_in(n0).list[0];
2361 for (cnt = 0; cnt < 2; cnt++) {
2362 if ((na = agtail(e0)) == (nb = agtail(e1)))
2363 break;
2364 if (order != (ND_order(na) > ND_order(nb)))
2365 return true;
2366 if (ND_in(na).size != 1 || ND_node_type(na) == NORMAL)
2367 break;
2368 e0 = ND_in(na).list[0];
2369 if (ND_in(nb).size != 1 || ND_node_type(nb) == NORMAL)
2370 break;
2371 e1 = ND_in(nb).list[0];
2372 }
2373 }
2374 return false;
2375}
2376
2377#ifdef DEBUG
2378void showpath(path *p) {
2379 pointf LL, UR;
2380
2381 fprintf(stderr, "%%!PS\n");
2382 for (size_t i = 0; i < p->nbox; i++) {
2383 LL = p->boxes[i].LL;
2384 UR = p->boxes[i].UR;
2385 fprintf(stderr,
2386 "newpath %.04f %.04f moveto %.04f %.04f lineto %.04f %.04f lineto "
2387 "%.04f %.04f lineto closepath stroke\n",
2388 LL.x, LL.y, UR.x, LL.y, UR.x, UR.y, LL.x, UR.y);
2389 }
2390 fprintf(stderr, "showpage\n");
2391}
2392#endif
int normalize(graph_t *g)
Definition adjust.c:739
static agxbuf last
last message
Definition agerror.c:29
static void agxbfree(agxbuf *xb)
free any malloced resources
Definition agxbuf.h:78
static int agxbprint(agxbuf *xb, const char *fmt,...)
Printf-style output to an agxbuf.
Definition agxbuf.h:234
static WUR char * agxbuse(agxbuf *xb)
Definition agxbuf.h:307
Memory allocation wrappers that exit on failure.
static void * gv_calloc(size_t nmemb, size_t size)
Definition alloc.h:26
static void * gv_alloc(size_t size)
Definition alloc.h:47
#define BETWEEN(a, b, c)
Definition arith.h:38
#define MIN(a, b)
Definition arith.h:28
#define M_PI
Definition arith.h:41
#define right(i)
Definition closest.c:79
void setEdgeType(graph_t *g, int defaultValue)
Definition utils.c:1434
void updateBB(graph_t *g, textlabel_t *lp)
Definition utils.c:621
#define SELFWPEDGE
Definition const.h:161
#define NORMAL
Definition const.h:24
#define EDGETYPE_SPLINE
Definition const.h:253
#define FLATORDER
Definition const.h:28
#define REGULAREDGE
Definition const.h:159
#define EDGE_LABEL
Definition const.h:176
#define IGNORED
Definition const.h:30
#define RANKDIR_TB
Definition const.h:190
#define EDGETYPE_CURVED
Definition const.h:250
#define VIRTUAL
Definition const.h:25
#define RANKDIR_LR
Definition const.h:191
#define EDGETYPE_ORTHO
Definition const.h:252
#define EDGETYPE_PLINE
Definition const.h:251
#define EDGETYPE_LINE
Definition const.h:249
#define EDGETYPEMASK
Definition const.h:164
#define EDGETYPE_NONE
Definition const.h:248
#define GVSPLINES
Definition const.h:173
#define BOTTOM
Definition const.h:117
#define FLATEDGE
Definition const.h:160
#define TOP
Definition const.h:119
#define SELFNPEDGE
Definition const.h:162
void dot_init_node_edge(graph_t *g)
Definition dotinit.c:86
void dot_cleanup(graph_t *g)
Definition dotinit.c:178
void dot_mincross(Agraph_t *)
Definition mincross.c:351
void dot_sameports(Agraph_t *)
Definition sameport.c:39
void dot_rank(Agraph_t *)
Definition rank.c:449
void dot_position(Agraph_t *)
Definition position.c:125
static bool leftOf(pointf p1, pointf p2, pointf p3)
Return true if p3 is to left of ray p1->p2.
static boxf maximal_bbox(graph_t *g, spline_info_t *, Agnode_t *, Agedge_t *, Agedge_t *)
static void make_flat_bottom_edges(graph_t *g, spline_info_t *sp, path *P, edge_t **edges, unsigned ind, unsigned cnt, edge_t *e, bool use_splines)
#define HALFMINW
Definition dotsplines.c:36
static void swap_bezier(bezier *b)
Definition dotsplines.c:147
static void make_flat_edge(graph_t *, spline_info_t *, path *, Agedge_t **, unsigned, unsigned, int)
#define GROWEDGES
Definition dotsplines.c:97
#define CHUNK
Definition dotsplines.c:33
#define MINW
Definition dotsplines.c:35
#define FWDEDGE
Definition dotsplines.c:38
static int straight_len(Agnode_t *)
#define NSUB
Definition dotsplines.c:32
static bool pathscross(Agnode_t *, Agnode_t *, Agedge_t *, Agedge_t *)
static edge_t * cloneEdge(graph_t *g, node_t *tn, node_t *hn, edge_t *orig)
Definition dotsplines.c:922
static void setState(graph_t *auxg, attr_state_t *attr_state)
Definition dotsplines.c:717
static void edge_normalize(graph_t *g)
Definition dotsplines.c:189
static void makeSimpleFlatLabels(node_t *tn, node_t *hn, edge_t **edges, unsigned ind, unsigned cnt, int et, unsigned n_lbls)
Definition dotsplines.c:996
static int makeLineEdge(graph_t *g, edge_t *fe, points_t *points, node_t **hp)
#define BWDEDGE
Definition dotsplines.c:39
static Agedge_t * top_bound(Agedge_t *, int)
static bool swap_ends_p(edge_t *e)
Definition dotsplines.c:116
int portcmp(port p0, port p1)
Definition dotsplines.c:131
static void make_flat_labeled_edge(graph_t *g, spline_info_t *sp, path *P, edge_t *e, int et)
static bool spline_merge(node_t *n)
Definition dotsplines.c:111
#define AUXGRAPH
Definition dotsplines.c:42
static void setEdgeLabelPos(graph_t *g)
Definition dotsplines.c:224
#define MAINGRAPH
Definition dotsplines.c:41
static void make_flat_adj_edges(graph_t *g, edge_t **edges, unsigned ind, unsigned cnt, edge_t *e0, int et)
static bool cl_vninside(Agraph_t *, Agnode_t *)
static void place_vnlabel(Agnode_t *)
Definition dotsplines.c:510
static Agraph_t * cl_bound(graph_t *, Agnode_t *, Agnode_t *)
static void make_regular_edge(graph_t *g, spline_info_t *, path *, Agedge_t **, unsigned, unsigned, int)
static void adjustregularpath(path *, size_t, size_t)
static graph_t * cloneGraph(graph_t *g, attr_state_t *attr_state)
Definition dotsplines.c:810
#define LBL_SPACE
Definition dotsplines.c:988
#define MAKEFWDEDGE(new, old)
Definition dotsplines.c:45
static void dot_splines_(graph_t *g, int normalize)
Definition dotsplines.c:252
static boxf makeregularend(boxf, int, double)
static edge_t * getmainedge(edge_t *e)
Definition dotsplines.c:102
static boxf rank_box(spline_info_t *sp, Agraph_t *, int)
static void cleanupCloneGraph(graph_t *g, attr_state_t *attr_state)
Definition dotsplines.c:857
static void makeBottomFlatEnd(graph_t *g, spline_info_t *sp, path *P, node_t *n, edge_t *e, pathend_t *endp, bool isBegin)
static void recover_slack(Agedge_t *, path *)
static void makeFlatEnd(graph_t *g, spline_info_t *sp, path *P, node_t *n, edge_t *e, pathend_t *endp, bool isBegin)
static Agedge_t * straight_path(Agedge_t *, int, points_t *)
static int edgecmp(const void *, const void *)
Definition dotsplines.c:564
void dot_splines(graph_t *g)
Definition dotsplines.c:504
#define FUDGE
#define GRAPHTYPEMASK
Definition dotsplines.c:43
#define REAL_CLUSTER(n)
static splineInfo sinfo
Definition dotsplines.c:128
static int edgelblcmpfn(const void *x, const void *y)
Definition dotsplines.c:948
static void resize_vn(Agnode_t *, double, double, double)
static void resetRW(graph_t *g)
Definition dotsplines.c:207
static void makeSimpleFlat(node_t *tn, node_t *hn, edge_t **edges, unsigned ind, unsigned cnt, int et)
static void completeregularpath(path *, Agedge_t *, Agedge_t *, pathend_t *, pathend_t *, const boxes_t *)
static void setflags(Agedge_t *, int, int, int)
Definition dotsplines.c:525
static pointf transformf(pointf p, pointf del, int flip)
Definition dotsplines.c:933
static void swap_spline(splines *s)
Definition dotsplines.c:167
static Agedge_t * bot_bound(Agedge_t *, int)
static node_t * cloneNode(graph_t *g, node_t *orign)
Definition dotsplines.c:908
static float dy
Definition draw.c:38
static float dx
Definition draw.c:37
#define left
Definition dthdr.h:12
static void del(Dict_t *d, Dtlink_t **set, Agedge_t *e)
Definition edge.c:157
#define le
Definition edges.h:25
void update_bb_bz(boxf *bb, pointf *cp)
Definition emit.c:748
struct pointf_s pointf
static pointf add_pointf(pointf p, pointf q)
Definition geomprocs.h:88
Agsym_t * E_sametail
Definition globals.h:86
Agsym_t * N_fontsize
Definition globals.h:74
Agsym_t * E_labelfontsize
Definition globals.h:88
Agsym_t * E_fontcolor
Definition globals.h:82
Agsym_t * N_group
Definition globals.h:78
Agsym_t * N_width
Definition globals.h:73
Agsym_t * E_weight
Definition globals.h:81
int State
Definition globals.h:62
Agsym_t * N_orientation
Definition globals.h:76
Agsym_t * N_sides
Definition globals.h:76
Agsym_t * E_headclip
Definition globals.h:90
Agsym_t * G_ordering
Definition globals.h:70
Agsym_t * E_headlabel
Definition globals.h:87
Agsym_t * N_showboxes
Definition globals.h:75
Agsym_t * N_fontname
Definition globals.h:74
Agsym_t * E_fontname
Definition globals.h:82
Agsym_t * N_style
Definition globals.h:75
int EdgeLabelsDone
Definition globals.h:63
Agsym_t * E_dir
Definition globals.h:83
Agsym_t * E_label
Definition globals.h:83
Agsym_t * N_skew
Definition globals.h:77
Agsym_t * E_minlen
Definition globals.h:81
Agsym_t * N_shape
Definition globals.h:73
Agsym_t * N_xlabel
Definition globals.h:75
Agsym_t * E_label_float
Definition globals.h:85
Agsym_t * E_samehead
Definition globals.h:86
Agsym_t * N_nojustify
Definition globals.h:75
Agsym_t * E_taillabel
Definition globals.h:87
Agsym_t * N_label
Definition globals.h:75
Agsym_t * E_labelangle
Definition globals.h:89
Agsym_t * E_fontsize
Definition globals.h:82
Agsym_t * N_fixed
Definition globals.h:77
Agsym_t * N_peripheries
Definition globals.h:76
Agsym_t * E_labelfontname
Definition globals.h:88
Agsym_t * N_distortion
Definition globals.h:77
Agsym_t * E_xlabel
Definition globals.h:83
Agsym_t * E_constr
Definition globals.h:84
Agsym_t * N_fontcolor
Definition globals.h:74
Agsym_t * E_labelfontcolor
Definition globals.h:88
Agsym_t * E_tailclip
Definition globals.h:90
Agsym_t * E_labeldistance
Definition globals.h:89
Agsym_t * N_ordering
Definition globals.h:76
Agsym_t * N_height
Definition globals.h:73
void free(void *)
node NULL
Definition grammar.y:163
static int cnt(Dict_t *d, Dtlink_t **set)
Definition graph.c:206
Agsym_t * agattr(Agraph_t *g, int kind, char *name, const char *value)
creates or looks up attributes of a graph
Definition attr.c:371
int agset(void *obj, char *name, const char *value)
Definition attr.c:492
Agsym_t * agnxtattr(Agraph_t *g, int kind, Agsym_t *attr)
permits traversing the list of attributes of a given type
Definition attr.c:379
int agxset(void *obj, Agsym_t *sym, const char *value)
Definition attr.c:532
int agcopyattr(void *oldobj, void *newobj)
copies all of the attributes from one object to another
Definition attr.c:582
Agsym_t * agattr_html(Agraph_t *g, int kind, char *name, const char *value)
agattr, but creates HTML-like values
Definition attr.c:375
#define ED_to_orig(e)
Definition types.h:598
#define ED_tree_index(e)
Definition types.h:600
Agedge_t * agedge(Agraph_t *g, Agnode_t *t, Agnode_t *h, char *name, int createflag)
Definition edge.c:256
#define AGMKOUT(e)
Definition cgraph.h:882
Agedge_t * agnxtin(Agraph_t *g, Agedge_t *e)
Definition edge.c:69
#define ED_head_label(e)
Definition types.h:587
#define agfindedgeattr(g, a)
Definition types.h:617
Agedge_t * agfstout(Agraph_t *g, Agnode_t *n)
Definition edge.c:24
#define ED_spl(e)
Definition types.h:595
#define agtail(e)
Definition cgraph.h:888
#define ED_edge_type(e)
Definition types.h:582
#define ED_alg(e)
Definition types.h:578
#define ED_tail_label(e)
Definition types.h:596
#define ED_adjacent(e)
Definition types.h:584
#define aghead(e)
Definition cgraph.h:889
Agedge_t * agnxtout(Agraph_t *g, Agedge_t *e)
Definition edge.c:39
#define ED_head_port(e)
Definition types.h:588
Agedge_t * agfstin(Agraph_t *g, Agnode_t *n)
Definition edge.c:55
#define ED_label(e)
Definition types.h:589
#define ED_tail_port(e)
Definition types.h:597
#define ED_to_virt(e)
Definition types.h:599
#define AGOUT2IN(outedge)
Agedgepair_s.out -> Agedgepair_s.in/*#end#*‍/.
Definition cgraph.h:878
void agwarningf(const char *fmt,...)
Definition agerror.c:173
int agerr(agerrlevel_t level, const char *fmt,...)
Definition agerror.c:155
@ AGPREV
Definition cgraph.h:857
#define GD_minrank(g)
Definition types.h:384
#define agfindgraphattr(g, a)
Definition types.h:613
#define GD_maxrank(g)
Definition types.h:382
#define GD_drawing(g)
Definition types.h:353
Agdesc_t Agundirected
undirected
Definition graph.c:282
#define GD_has_labels(g)
Definition types.h:368
int agisdirected(Agraph_t *g)
Definition graph.c:186
int agclose(Agraph_t *g)
deletes a graph, freeing its associated storage
Definition graph.c:99
#define GD_rank(g)
Definition types.h:395
#define GD_bb(g)
Definition types.h:354
#define GD_nlist(g)
Definition types.h:393
Agraph_t * agopen(char *name, Agdesc_t desc, Agdisc_t *disc)
creates a new graph with the given name and kind
Definition graph.c:44
#define GD_dotroot(g)
Definition types.h:361
#define GD_nodesep(g)
Definition types.h:394
#define GD_charset(g)
Definition types.h:367
#define GD_gvc(g)
Definition types.h:355
#define GD_flip(g)
Definition types.h:378
#define GD_ranksep(g)
Definition types.h:397
Agdesc_t Agdirected
directed
Definition graph.c:280
Agnode_t * agnode(Agraph_t *g, char *name, int createflag)
Definition node.c:140
#define ND_rank(n)
Definition types.h:523
#define ND_ht(n)
Definition types.h:500
Agnode_t * agnxtnode(Agraph_t *g, Agnode_t *n)
Definition node.c:47
Agnode_t * agfstnode(Agraph_t *g)
Definition node.c:40
#define ND_next(n)
Definition types.h:510
#define ND_clust(n)
Definition types.h:489
#define ND_other(n)
Definition types.h:514
#define agfindnodeattr(g, a)
Definition types.h:615
#define ND_label(n)
Definition types.h:502
#define ND_alg(n)
Definition types.h:484
#define ND_flat_out(n)
Definition types.h:493
#define ND_rw(n)
Definition types.h:525
#define ND_node_type(n)
Definition types.h:511
#define ND_lw(n)
Definition types.h:506
#define ND_mval(n)
Definition types.h:508
#define ND_order(n)
Definition types.h:513
#define ND_coord(n)
Definition types.h:490
#define ND_in(n)
Definition types.h:501
#define ND_out(n)
Definition types.h:515
Agraph_t * agraphof(void *obj)
Definition obj.c:185
char * agnameof(void *)
returns a string descriptor for the object.
Definition id.c:143
Agraph_t * agroot(void *obj)
Definition obj.c:168
#define AGSEQ(obj)
Definition cgraph.h:225
@ AGEDGE
Definition cgraph.h:207
@ AGNODE
Definition cgraph.h:207
@ AGRAPH
Definition cgraph.h:207
void * agbindrec(void *obj, const char *name, unsigned int recsize, int move_to_front)
attaches a new record of the given size to the object
Definition rec.c:89
int aghtmlstr(const char *)
Definition refstr.c:401
Agraph_t * agsubg(Agraph_t *g, char *name, int cflag)
Definition subg.c:55
static gdPoint * points
void mark_lowclusters(Agraph_t *root)
Definition cluster.c:404
#define DEFINE_LIST(name, type)
Definition list.h:21
static int * ps
Definition lu.c:51
#define EDGE_TYPE(g)
Definition macros.h:25
#define neighbor(t, i, edim, elist)
Definition make_map.h:41
int rank(graph_t *g, int balance, int maxiter)
Definition ns.c:1001
void orthoEdges(Agraph_t *g, bool useLbls)
Definition ortho.c:1231
void dotneato_postprocess(Agraph_t *g)
Definition postproc.c:690
bezier * new_spline(edge_t *e, size_t sz)
Definition splines.c:215
splines * getsplinepoints(edge_t *e)
Definition splines.c:1392
void clip_and_install(edge_t *fe, node_t *hn, pointf *ps, size_t pn, splineInfo *info)
Definition splines.c:238
pointf * simpleSplineRoute(pointf, pointf, Ppoly_t, size_t *, int)
Given a simple (ccw) polygon, route an edge from tp to hp.
Definition routespl.c:173
int routesplinesinit(void)
Definition routespl.c:220
shape_kind shapeOf(node_t *)
Definition shapes.c:1906
void add_box(path *, boxf)
Definition splines.c:348
void beginpath(path *, Agedge_t *, int, pathend_t *, bool)
Definition splines.c:389
pointf * routesplines(path *, size_t *)
Definition routespl.c:566
void routesplinesterm(void)
Definition routespl.c:233
void makeSelfEdge(edge_t *edges[], size_t ind, size_t cnt, double sizex, double sizey, splineInfo *sinfo)
Definition splines.c:1174
void endpath(path *, Agedge_t *, int, pathend_t *, bool)
Definition splines.c:586
pointf * routepolylines(path *pp, size_t *npoints)
Definition routespl.c:570
int place_portlabel(edge_t *e, bool head_p)
Definition splines.c:1340
void makeStraightEdges(graph_t *g, edge_t **edges, size_t e_cnt, int et, splineInfo *sinfo)
Definition routespl.c:945
Agobj_t base
Definition cgraph.h:269
Agedge_t in
Definition cgraph.h:276
Agedge_t out
Definition cgraph.h:276
Agrec_t * data
stores programmer-defined data, access with AGDATA
Definition cgraph.h:212
graph or subgraph
Definition cgraph.h:424
Agraph_t * root
subgraphs - ancestors
Definition cgraph.h:438
implementation of Agrec_t
Definition cgraph.h:172
string attribute descriptor symbol in Agattr_s.dict
Definition cgraph.h:641
char * name
Definition cgraph.h:643
char * defval
Definition cgraph.h:644
attrsym_t * N_style
Definition dotsplines.c:696
attrsym_t * E_sametail
Definition dotsplines.c:676
attrsym_t * E_fontsize
Definition dotsplines.c:681
attrsym_t * N_shape
Definition dotsplines.c:695
attrsym_t * E_minlen
Definition dotsplines.c:678
attrsym_t * E_tailclip
Definition dotsplines.c:689
attrsym_t * E_taillabel
Definition dotsplines.c:690
attrsym_t * E_label
Definition dotsplines.c:684
attrsym_t * E_weight
Definition dotsplines.c:677
attrsym_t * N_nojustify
Definition dotsplines.c:710
attrsym_t * N_fontcolor
Definition dotsplines.c:699
attrsym_t * N_peripheries
Definition dotsplines.c:705
attrsym_t * E_xlabel
Definition dotsplines.c:691
attrsym_t * E_samehead
Definition dotsplines.c:675
attrsym_t * N_xlabel
Definition dotsplines.c:701
attrsym_t * E_label_float
Definition dotsplines.c:685
attrsym_t * N_fontname
Definition dotsplines.c:698
attrsym_t * E_headclip
Definition dotsplines.c:682
attrsym_t * N_sides
Definition dotsplines.c:704
attrsym_t * N_group
Definition dotsplines.c:711
attrsym_t * N_ordering
Definition dotsplines.c:703
attrsym_t * N_width
Definition dotsplines.c:694
attrsym_t * N_fixed
Definition dotsplines.c:709
attrsym_t * E_labelfontname
Definition dotsplines.c:687
attrsym_t * E_dir
Definition dotsplines.c:674
attrsym_t * E_labelfontcolor
Definition dotsplines.c:686
attrsym_t * N_height
Definition dotsplines.c:693
attrsym_t * G_ordering
Definition dotsplines.c:713
attrsym_t * E_constr
Definition dotsplines.c:673
attrsym_t * N_label
Definition dotsplines.c:700
attrsym_t * E_fontname
Definition dotsplines.c:680
attrsym_t * N_skew
Definition dotsplines.c:706
attrsym_t * N_distortion
Definition dotsplines.c:708
attrsym_t * E_fontcolor
Definition dotsplines.c:679
attrsym_t * E_headlabel
Definition dotsplines.c:683
attrsym_t * N_showboxes
Definition dotsplines.c:702
attrsym_t * N_orientation
Definition dotsplines.c:707
attrsym_t * N_fontsize
Definition dotsplines.c:697
attrsym_t * E_labelfontsize
Definition dotsplines.c:688
Definition types.h:89
size_t size
Definition types.h:91
pointf sp
Definition types.h:94
pointf * list
Definition types.h:90
uint32_t eflag
Definition types.h:93
pointf ep
Definition types.h:95
uint32_t sflag
Definition types.h:92
Definition geom.h:41
pointf UR
Definition geom.h:41
pointf LL
Definition geom.h:41
Definition cdt.h:100
Definition types.h:81
port start
Definition types.h:82
boxf * boxes
Definition types.h:85
port end
Definition types.h:83
size_t nbox
number of subdivisions
Definition types.h:84
boxf nb
Definition types.h:74
int boxn
Definition types.h:77
int sidemask
Definition types.h:76
boxf boxes[20]
Definition types.h:78
double x
Definition geom.h:29
double y
Definition geom.h:29
Definition types.h:48
pointf p
Definition types.h:49
double theta
Definition types.h:50
bool constrained
Definition types.h:55
bool defined
Definition types.h:54
double pht1
Definition types.h:207
node_t ** v
Definition types.h:202
double ht1
Definition types.h:205
double pht2
Definition types.h:208
bool(* swapEnds)(edge_t *e)
Definition types.h:67
bool(* splineMerge)(node_t *n)
Definition types.h:68
boxf * Rank_box
Definition dotsplines.c:67
double RightBound
Definition dotsplines.c:64
double LeftBound
Definition dotsplines.c:63
double Multisep
Definition dotsplines.c:66
double Splinesep
Definition dotsplines.c:65
pointf pos
Definition types.h:114
bool set
Definition types.h:123
struct poly_s poly
@ SH_RECORD
Definition types.h:187
#define SET_RANKDIR(g, rd)
Definition types.h:607
Definition grammar.c:93
struct item_s * list
Definition grammar.c:99
#define MAX(a, b)
Definition write.c:31