Graphviz 16.1.3~dev.20261128.0221
Loading...
Searching...
No Matches
splines.c
Go to the documentation of this file.
1
4/*************************************************************************
5 * Copyright (c) 2011 AT&T Intellectual Property
6 * All rights reserved. This program and the accompanying materials
7 * are made available under the terms of the Eclipse Public License v2.0
8 * which accompanies this distribution, and is available at
9 * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
10 *
11 * Contributors: Details at https://graphviz.org
12 *************************************************************************/
13
14/* Functions related to creating a spline and attaching it to
15 * an edge, starting from a list of control points.
16 */
17
18#include "config.h"
19
20#include <common/geomprocs.h>
21#include <common/render.h>
22#include <math.h>
23#include <stdbool.h>
24#include <stddef.h>
25#include <stdint.h>
26#include <util/agxbuf.h>
27#include <util/alloc.h>
28#include <util/gv_math.h>
29#include <util/streq.h>
30#include <util/unreachable.h>
31
32#ifdef DEBUG
33static int debugleveln(edge_t *e, int i) {
34 return GD_showboxes(agraphof(aghead(e))) == i ||
35 GD_showboxes(agraphof(agtail(e))) == i || ED_showboxes(e) == i ||
36 ND_showboxes(aghead(e)) == i || ND_showboxes(agtail(e)) == i;
37}
38
39static void showPoints(pointf ps[], int pn) {
40 int bi;
41
42 LIST_APPEND(&Show_boxes, gv_strdup("%% self list"));
43 LIST_APPEND(&Show_boxes, gv_strdup("dbgstart"));
44 for (bi = 0; bi < pn; bi++) {
45 agxbuf buf = {0};
46 agxbprint(&buf, "%.5g %.5g point", ps[bi].x, ps[bi].y);
48 }
49 LIST_APPEND(&Show_boxes, gv_strdup("grestore"));
50}
51#endif
52
53/* Clip arrow to node boundary.
54 * The real work is done elsewhere. Here we get the real edge,
55 * check that the edge has arrowheads, and that an endpoint
56 * isn't a merge point where several parts of an edge meet.
57 * (e.g., with edge concentrators).
58 */
59static void arrow_clip(edge_t *fe, node_t *hn, pointf *ps, size_t *startp,
60 size_t *endp, bezier *spl, splineInfo *info) {
61 edge_t *e;
62 bool j;
63
64 for (e = fe; ED_to_orig(e); e = ED_to_orig(e))
65 ;
66
67 if (info->ignoreSwap)
68 j = false;
69 else
70 j = info->swapEnds(e);
71 uint32_t sflag, eflag;
72 arrow_flags(e, &sflag, &eflag);
73 if (info->splineMerge(hn))
74 eflag = ARR_NONE;
75 if (info->splineMerge(agtail(fe)))
76 sflag = ARR_NONE;
77 /* swap the two ends */
78 if (j) {
79 SWAP(&sflag, &eflag);
80 }
81 if (info->isOrtho) {
82 if (eflag || sflag)
83 arrowOrthoClip(e, ps, *startp, *endp, spl, sflag, eflag);
84 } else {
85 if (sflag)
86 *startp = arrowStartClip(e, ps, *startp, *endp, spl, sflag);
87 if (eflag)
88 *endp = arrowEndClip(e, ps, *startp, *endp, spl, eflag);
89 }
90}
91
92/* Clip Bézier to shape using binary search.
93 * The details of the shape are passed in the inside_context;
94 * The function providing the inside test is passed as a parameter.
95 * left_inside specifies that sp[0] is inside the node,
96 * else sp[3] is taken as inside.
97 * The points p are in node coordinates.
98 */
99void bezier_clip(inside_t *inside_context,
100 bool (*inside)(inside_t *inside_context, pointf p), pointf *sp,
101 bool left_inside) {
102 pointf seg[4], best[4], pt, opt, *left, *right;
103 double low, high, t, *idir, *odir;
104 bool found;
105 int i;
106
107 if (left_inside) {
108 left = NULL;
109 right = seg;
110 pt = sp[0];
111 idir = &low;
112 odir = &high;
113 } else {
114 left = seg;
115 right = NULL;
116 pt = sp[3];
117 idir = &high;
118 odir = &low;
119 }
120 found = false;
121 low = 0.0;
122 high = 1.0;
123 do {
124 opt = pt;
125 t = (high + low) / 2.0;
126 pt = Bezier(sp, t, left, right);
127 if (inside(inside_context, pt)) {
128 *idir = t;
129 for (i = 0; i < 4; i++)
130 best[i] = seg[i];
131 found = true;
132 } else {
133 *odir = t;
134 }
135 } while (fabs(opt.x - pt.x) > .5 || fabs(opt.y - pt.y) > .5);
136 if (found)
137 for (i = 0; i < 4; i++)
138 sp[i] = best[i];
139 else
140 for (i = 0; i < 4; i++)
141 sp[i] = seg[i];
142}
143
144/* Clip Bézier to node shape using binary search.
145 * left_inside specifies that curve[0] is inside the node, else
146 * curve[3] is taken as inside.
147 * Assumes ND_shape(n) and ND_shape(n)->fns->insidefn are non-NULL.
148 * See note on shape_clip.
149 */
150static void shape_clip0(inside_t *inside_context, node_t *n, pointf curve[4],
151 bool left_inside) {
152 int i;
153 double save_real_size;
154 pointf c[4];
155
156 save_real_size = ND_rw(n);
157 for (i = 0; i < 4; i++) {
158 c[i].x = curve[i].x - ND_coord(n).x;
159 c[i].y = curve[i].y - ND_coord(n).y;
160 }
161
162 bezier_clip(inside_context, ND_shape(n)->fns->insidefn, c, left_inside);
163
164 for (i = 0; i < 4; i++) {
165 curve[i].x = c[i].x + ND_coord(n).x;
166 curve[i].y = c[i].y + ND_coord(n).y;
167 }
168 ND_rw(n) = save_real_size;
169}
170
171/* Clip Bézier to node shape
172 * Uses curve[0] to determine which which side is inside the node.
173 * NOTE: This test is bad. It is possible for previous call to
174 * shape_clip to produce a Bézier with curve[0] moved to the boundary
175 * for which insidefn(curve[0]) is true. Thus, if the new Bézier is
176 * fed back to shape_clip, it will again assume left_inside is true.
177 * To be safe, shape_clip0 should guarantee that the computed boundary
178 * point fails insidefn.
179 * The edge e is used to provide a port box. If NULL, the spline is
180 * clipped to the node shape.
181 */
182void shape_clip(node_t *n, pointf curve[4]) {
183 double save_real_size;
184 bool left_inside;
185 pointf c;
186
187 if (ND_shape(n) == NULL || ND_shape(n)->fns->insidefn == NULL)
188 return;
189
190 inside_t inside_context = {.s = {.n = n}};
191 save_real_size = ND_rw(n);
192 c.x = curve[0].x - ND_coord(n).x;
193 c.y = curve[0].y - ND_coord(n).y;
194 left_inside = ND_shape(n)->fns->insidefn(&inside_context, c);
195 ND_rw(n) = save_real_size;
196 shape_clip0(&inside_context, n, curve, left_inside);
197}
198
200bezier *new_spline(edge_t *e, size_t sz) {
201 bezier *rv;
202 while (ED_to_orig(e) != NULL && ED_edge_type(e) != NORMAL)
203 e = ED_to_orig(e);
204 if (ED_spl(e) == NULL)
205 ED_spl(e) = gv_alloc(sizeof(splines));
206 ED_spl(e)->list = gv_recalloc(ED_spl(e)->list, ED_spl(e)->size,
207 ED_spl(e)->size + 1, sizeof(bezier));
208 rv = &(ED_spl(e)->list[ED_spl(e)->size++]);
209 rv->list = gv_calloc(sz, sizeof(pointf));
210 rv->size = sz;
211 rv->sflag = rv->eflag = 0;
212 rv->sp.x = rv->sp.y = rv->ep.x = rv->ep.y = 0;
213 return rv;
214}
215
216/* Given a raw spline (pn control points in ps), representing
217 * a path from edge agtail(fe) ending in node hn, clip the ends to
218 * the node boundaries and attach the resulting spline to the
219 * edge.
220 */
221void clip_and_install(edge_t *fe, node_t *hn, pointf *ps, size_t pn,
222 splineInfo *info) {
223 int clipTail, clipHead;
224 size_t start, end;
225 edge_t *orig;
226 boxf *tbox, *hbox;
227
228 node_t *tn = agtail(fe);
229 graph_t *const g = agraphof(tn);
230 bezier *const newspl = new_spline(fe, pn);
231
232 for (orig = fe; ED_to_orig(orig) != NULL && ED_edge_type(orig) != NORMAL;
233 orig = ED_to_orig(orig))
234 ;
235
236 /* may be a reversed flat edge */
237 if (!info->ignoreSwap && ND_rank(tn) == ND_rank(hn) &&
238 ND_order(tn) > ND_order(hn)) {
239 SWAP(&hn, &tn);
240 }
241 if (tn == agtail(orig)) {
242 clipTail = ED_tail_port(orig).clip;
243 clipHead = ED_head_port(orig).clip;
244 tbox = ED_tail_port(orig).bp;
245 hbox = ED_head_port(orig).bp;
246 } else { /* fe and orig are reversed */
247 clipTail = ED_head_port(orig).clip;
248 clipHead = ED_tail_port(orig).clip;
249 hbox = ED_tail_port(orig).bp;
250 tbox = ED_head_port(orig).bp;
251 }
252
253 /* spline may be interior to node */
254 if (clipTail && ND_shape(tn) && ND_shape(tn)->fns->insidefn) {
255 inside_t inside_context = {.s = {.n = tn, .bp = tbox}};
256 for (start = 0; start < pn - 4; start += 3) {
257 const pointf p2 = {.x = ps[start + 3].x - ND_coord(tn).x,
258 .y = ps[start + 3].y - ND_coord(tn).y};
259 if (!ND_shape(tn)->fns->insidefn(&inside_context, p2))
260 break;
261 }
262 shape_clip0(&inside_context, tn, &ps[start], true);
263 } else
264 start = 0;
265 if (clipHead && ND_shape(hn) && ND_shape(hn)->fns->insidefn) {
266 inside_t inside_context = {.s = {.n = hn, .bp = hbox}};
267 for (end = pn - 4; end > 0; end -= 3) {
268 const pointf p2 = {.x = ps[end].x - ND_coord(hn).x,
269 .y = ps[end].y - ND_coord(hn).y};
270 if (!ND_shape(hn)->fns->insidefn(&inside_context, p2))
271 break;
272 }
273 shape_clip0(&inside_context, hn, &ps[end], false);
274 } else
275 end = pn - 4;
276 for (; start < pn - 4; start += 3)
277 if (!APPROXEQPT(ps[start], ps[start + 3], MILLIPOINT))
278 break;
279 for (; end > 0; end -= 3)
280 if (!APPROXEQPT(ps[end], ps[end + 3], MILLIPOINT))
281 break;
282 arrow_clip(fe, hn, ps, &start, &end, newspl, info);
283 for (size_t i = start, j = 0; i < end + 4;) {
284 const pointf *const cp = &ps[i];
285 newspl->list[j++] = ps[i++];
286 if (i >= end + 4)
287 break;
288 newspl->list[j++] = ps[i++];
289 newspl->list[j++] = ps[i++];
290 update_bb_bz(&GD_bb(g), cp);
291 }
292 newspl->size = end - start + 4;
293}
294
295static double conc_slope(node_t *n) {
296 double s_in, s_out, m_in, m_out;
297 int cnt_in, cnt_out;
298 edge_t *e;
299
300 s_in = s_out = 0.0;
301 for (cnt_in = 0; (e = ND_in(n).list[cnt_in]); cnt_in++)
302 s_in += ND_coord(agtail(e)).x;
303 for (cnt_out = 0; (e = ND_out(n).list[cnt_out]); cnt_out++)
304 s_out += ND_coord(aghead(e)).x;
305 if (cnt_in > 0) {
306 const double x1 = ND_coord(n).x - s_in / cnt_in;
307 const double y1 = ND_coord(n).y - ND_coord(agtail(ND_in(n).list[0])).y;
308 m_in = atan2(y1, x1);
309 } else {
310 m_in = atan2(ND_coord(n).y, ND_coord(n).x);
311 }
312 if (cnt_out > 0) {
313 const double x2 = s_out / cnt_out - ND_coord(n).x;
314 const double y2 = ND_coord(aghead(ND_out(n).list[0])).y - ND_coord(n).y;
315 m_out = atan2(y2, x2);
316 } else {
317 m_out = atan2(-ND_coord(n).y, -ND_coord(n).x);
318 }
319 return (m_in + m_out) / 2.0;
320}
321
322void add_box(path *P, boxf b) {
323 if (b.LL.x < b.UR.x && b.LL.y < b.UR.y)
324 P->boxes[P->nbox++] = b;
325}
326
327/* Set up boxes near the tail node.
328 * For regular nodes, the result should be a list of contiguous rectangles
329 * such that the last one has the smallest LL.y and its LL.y is above
330 * the bottom of the rank (rank.ht1).
331 *
332 * For flat edges, we assume endp->sidemask has been set. For regular
333 * edges, we set this, but it doesn't appear to be needed any more.
334 *
335 * In many cases, we tweak the x or y coordinate of P->start.p by 1.
336 * This is because of a problem in the path routing code. If the starting
337 * point actually lies on the polygon, in some cases, the router gets
338 * confused and routes the path outside the polygon. So, the offset ensures
339 * the starting point is in the polygon.
340 *
341 * FIX: Creating the initial boxes only really works for rankdir=TB and
342 * rankdir=LR. For the others, we rely on compassPort flipping the side
343 * and then assume that the node shape has top-bottom symmetry. Since we
344 * at present only put compass points on the bounding box, this works.
345 * If we attempt to implement compass points on actual node perimeters,
346 * something major will probably be necessary. Doing the coordinate
347 * flip (postprocess) before spline routing will be too disruptive. The
348 * correct solution is probably to have beginpath/endpath create the
349 * boxes assuming an inverted node. Note that compassPort already does
350 * some flipping. Even better would be to allow the *_path function
351 * to provide a polygon.
352 *
353 * The extra space provided by FUDGE-2 prevents the edge from getting
354 * too close the side of the node.
355 *
356 */
357#define FUDGE 2
358#define HT2(n) (ND_ht(n) / 2)
359
360void beginpath(path *P, edge_t *e, bool is_flat_edge, pathend_t *endp,
361 bool merge) {
362 int side, mask;
363 node_t *n;
364 int (*pboxfn)(node_t *, port *, int, boxf *, int *);
365
366 n = agtail(e);
367
368 if (ED_tail_port(e).dyna)
370 if (ND_shape(n))
371 pboxfn = ND_shape(n)->fns->pboxfn;
372 else
373 pboxfn = NULL;
374 P->start.p = add_pointf(ND_coord(n), ED_tail_port(e).p);
375 if (merge) {
376 /*P->start.theta = - M_PI / 2; */
377 P->start.theta = conc_slope(agtail(e));
378 P->start.constrained = true;
379 } else {
380 if (ED_tail_port(e).constrained) {
381 P->start.theta = ED_tail_port(e).theta;
382 P->start.constrained = true;
383 } else
384 P->start.constrained = false;
385 }
386 P->nbox = 0;
387 P->data = e;
388 endp->np = P->start.p;
389 if (!is_flat_edge && ND_node_type(n) == NORMAL &&
390 (side = ED_tail_port(e).side)) {
391 edge_t *orig;
392 boxf b0, b = endp->nb;
393 if (side & TOP) {
394 endp->sidemask = TOP;
395 if (P->start.p.x < ND_coord(n).x) { /* go left */
396 b0.LL.x = b.LL.x - 1;
397 /* b0.LL.y = ND_coord(n).y + HT2(n); */
398 b0.LL.y = P->start.p.y;
399 b0.UR.x = b.UR.x;
400 b0.UR.y = ND_coord(n).y + HT2(n) + GD_ranksep(agraphof(n)) / 2;
401 b.UR.x = ND_coord(n).x - ND_lw(n) - (FUDGE - 2);
402 b.UR.y = b0.LL.y;
403 b.LL.y = ND_coord(n).y - HT2(n);
404 --b.LL.x;
405 endp->boxes[0] = b0;
406 endp->boxes[1] = b;
407 } else {
408 b0.LL.x = b.LL.x;
409 b0.LL.y = P->start.p.y;
410 /* b0.LL.y = ND_coord(n).y + HT2(n); */
411 b0.UR.x = b.UR.x + 1;
412 b0.UR.y = ND_coord(n).y + HT2(n) + GD_ranksep(agraphof(n)) / 2;
413 b.LL.x = ND_coord(n).x + ND_rw(n) + (FUDGE - 2);
414 b.UR.y = b0.LL.y;
415 b.LL.y = ND_coord(n).y - HT2(n);
416 ++b.UR.x;
417 endp->boxes[0] = b0;
418 endp->boxes[1] = b;
419 }
420 ++P->start.p.y;
421 endp->boxn = 2;
422 } else if (side & BOTTOM) {
423 endp->sidemask = BOTTOM;
424 b.UR.y = MAX(b.UR.y, P->start.p.y);
425 endp->boxes[0] = b;
426 endp->boxn = 1;
427 --P->start.p.y;
428 } else if (side & LEFT) {
429 endp->sidemask = LEFT;
430 b.UR.x = P->start.p.x;
431 b.LL.y = ND_coord(n).y - HT2(n);
432 b.UR.y = P->start.p.y;
433 endp->boxes[0] = b;
434 endp->boxn = 1;
435 --P->start.p.x;
436 } else {
437 endp->sidemask = RIGHT;
438 b.LL.x = P->start.p.x;
439 b.LL.y = ND_coord(n).y - HT2(n);
440 b.UR.y = P->start.p.y;
441 endp->boxes[0] = b;
442 endp->boxn = 1;
443 ++P->start.p.x;
444 }
445 for (orig = e; ED_to_orig(orig) != NULL && ED_edge_type(orig) != NORMAL;
446 orig = ED_to_orig(orig))
447 ;
448 if (n == agtail(orig))
449 ED_tail_port(orig).clip = false;
450 else
451 ED_head_port(orig).clip = false;
452 return;
453 }
454 if (is_flat_edge && (side = ED_tail_port(e).side)) {
455 boxf b0, b = endp->nb;
456 edge_t *orig;
457 if (side & TOP) {
458 b.LL.y = MIN(b.LL.y, P->start.p.y);
459 endp->boxes[0] = b;
460 endp->boxn = 1;
461 ++P->start.p.y;
462 } else if (side & BOTTOM) {
463 if (endp->sidemask == TOP) {
464 b0.UR.y = ND_coord(n).y - HT2(n);
465 b0.UR.x = b.UR.x + 1;
466 b0.LL.x = P->start.p.x;
467 b0.LL.y = b0.UR.y - GD_ranksep(agraphof(n)) / 2;
468 b.LL.x = ND_coord(n).x + ND_rw(n) + (FUDGE - 2);
469 b.LL.y = b0.UR.y;
470 b.UR.y = ND_coord(n).y + HT2(n);
471 ++b.UR.x;
472 endp->boxes[0] = b0;
473 endp->boxes[1] = b;
474 endp->boxn = 2;
475 } else {
476 b.UR.y = MAX(b.UR.y, P->start.p.y);
477 endp->boxes[0] = b;
478 endp->boxn = 1;
479 }
480 --P->start.p.y;
481 } else if (side & LEFT) {
482 b.UR.x = P->start.p.x + 1;
483 if (endp->sidemask == TOP) {
484 b.UR.y = ND_coord(n).y + HT2(n);
485 b.LL.y = P->start.p.y - 1;
486 } else {
487 b.LL.y = ND_coord(n).y - HT2(n);
488 b.UR.y = P->start.p.y + 1;
489 }
490 endp->boxes[0] = b;
491 endp->boxn = 1;
492 --P->start.p.x;
493 } else {
494 b.LL.x = P->start.p.x;
495 if (endp->sidemask == TOP) {
496 b.UR.y = ND_coord(n).y + HT2(n);
497 b.LL.y = P->start.p.y;
498 } else {
499 b.LL.y = ND_coord(n).y - HT2(n);
500 b.UR.y = P->start.p.y + 1;
501 }
502 endp->boxes[0] = b;
503 endp->boxn = 1;
504 ++P->start.p.x;
505 }
506 for (orig = e; ED_to_orig(orig) != NULL && ED_edge_type(orig) != NORMAL;
507 orig = ED_to_orig(orig))
508 ;
509 if (n == agtail(orig))
510 ED_tail_port(orig).clip = false;
511 else
512 ED_head_port(orig).clip = false;
513 endp->sidemask = side;
514 return;
515 }
516
517 if (!is_flat_edge)
518 side = BOTTOM;
519 else
520 side = endp->sidemask; /* for flat edges */
521 if (pboxfn &&
522 (mask = pboxfn(n, &ED_tail_port(e), side, &endp->boxes[0], &endp->boxn)))
523 endp->sidemask = mask;
524 else {
525 endp->boxes[0] = endp->nb;
526 endp->boxn = 1;
527
528 if (is_flat_edge) {
529 if (endp->sidemask == TOP)
530 endp->boxes[0].LL.y = P->start.p.y;
531 else
532 endp->boxes[0].UR.y = P->start.p.y;
533 } else {
534 endp->boxes[0].UR.y = P->start.p.y;
535 endp->sidemask = BOTTOM;
536 --P->start.p.y;
537 }
538 }
539}
540
541void endpath(path *P, edge_t *e, bool is_flat_edge, pathend_t *endp,
542 bool merge) {
543 int side, mask;
544 node_t *n;
545 int (*pboxfn)(node_t *n, port *, int, boxf *, int *);
546
547 n = aghead(e);
548
549 if (ED_head_port(e).dyna)
551 if (ND_shape(n))
552 pboxfn = ND_shape(n)->fns->pboxfn;
553 else
554 pboxfn = NULL;
555 P->end.p = add_pointf(ND_coord(n), ED_head_port(e).p);
556 if (merge) {
557 /*P->end.theta = M_PI / 2; */
558 P->end.theta = conc_slope(aghead(e)) + M_PI;
559 assert(P->end.theta < 2 * M_PI);
560 P->end.constrained = true;
561 } else {
562 if (ED_head_port(e).constrained) {
563 P->end.theta = ED_head_port(e).theta;
564 P->end.constrained = true;
565 } else
566 P->end.constrained = false;
567 }
568 endp->np = P->end.p;
569 if (!is_flat_edge && ND_node_type(n) == NORMAL &&
570 (side = ED_head_port(e).side)) {
571 edge_t *orig;
572 boxf b0, b = endp->nb;
573 if (side & TOP) {
574 endp->sidemask = TOP;
575 b.LL.y = MIN(b.LL.y, P->end.p.y);
576 endp->boxes[0] = b;
577 endp->boxn = 1;
578 ++P->end.p.y;
579 } else if (side & BOTTOM) {
580 endp->sidemask = BOTTOM;
581 if (P->end.p.x < ND_coord(n).x) { /* go left */
582 b0.LL.x = b.LL.x - 1;
583 /* b0.UR.y = ND_coord(n).y - HT2(n); */
584 b0.UR.y = P->end.p.y;
585 b0.UR.x = b.UR.x;
586 b0.LL.y = ND_coord(n).y - HT2(n) - GD_ranksep(agraphof(n)) / 2;
587 b.UR.x = ND_coord(n).x - ND_lw(n) - (FUDGE - 2);
588 b.LL.y = b0.UR.y;
589 b.UR.y = ND_coord(n).y + HT2(n);
590 --b.LL.x;
591 endp->boxes[0] = b0;
592 endp->boxes[1] = b;
593 } else {
594 b0.LL.x = b.LL.x;
595 b0.UR.y = P->end.p.y;
596 /* b0.UR.y = ND_coord(n).y - HT2(n); */
597 b0.UR.x = b.UR.x + 1;
598 b0.LL.y = ND_coord(n).y - HT2(n) - GD_ranksep(agraphof(n)) / 2;
599 b.LL.x = ND_coord(n).x + ND_rw(n) + (FUDGE - 2);
600 b.LL.y = b0.UR.y;
601 b.UR.y = ND_coord(n).y + HT2(n);
602 ++b.UR.x;
603 endp->boxes[0] = b0;
604 endp->boxes[1] = b;
605 }
606 endp->boxn = 2;
607 --P->end.p.y;
608 } else if (side & LEFT) {
609 endp->sidemask = LEFT;
610 b.UR.x = P->end.p.x;
611 b.UR.y = ND_coord(n).y + HT2(n);
612 b.LL.y = P->end.p.y;
613 endp->boxes[0] = b;
614 endp->boxn = 1;
615 --P->end.p.x;
616 } else {
617 endp->sidemask = RIGHT;
618 b.LL.x = P->end.p.x;
619 b.UR.y = ND_coord(n).y + HT2(n);
620 b.LL.y = P->end.p.y;
621 endp->boxes[0] = b;
622 endp->boxn = 1;
623 ++P->end.p.x;
624 }
625 for (orig = e; ED_to_orig(orig) != NULL && ED_edge_type(orig) != NORMAL;
626 orig = ED_to_orig(orig))
627 ;
628 if (n == aghead(orig))
629 ED_head_port(orig).clip = false;
630 else
631 ED_tail_port(orig).clip = false;
632 endp->sidemask = side;
633 return;
634 }
635
636 if (is_flat_edge && (side = ED_head_port(e).side)) {
637 boxf b0, b = endp->nb;
638 edge_t *orig;
639 if (side & TOP) {
640 b.LL.y = MIN(b.LL.y, P->end.p.y);
641 endp->boxes[0] = b;
642 endp->boxn = 1;
643 ++P->end.p.y;
644 } else if (side & BOTTOM) {
645 if (endp->sidemask == TOP) {
646 b0.LL.x = b.LL.x - 1;
647 b0.UR.y = ND_coord(n).y - HT2(n);
648 b0.UR.x = P->end.p.x;
649 b0.LL.y = b0.UR.y - GD_ranksep(agraphof(n)) / 2;
650 b.UR.x = ND_coord(n).x - ND_lw(n) - 2;
651 b.LL.y = b0.UR.y;
652 b.UR.y = ND_coord(n).y + HT2(n);
653 --b.LL.x;
654 endp->boxes[0] = b0;
655 endp->boxes[1] = b;
656 endp->boxn = 2;
657 } else {
658 b.UR.y = MAX(b.UR.y, P->start.p.y);
659 endp->boxes[0] = b;
660 endp->boxn = 1;
661 }
662 --P->end.p.y;
663 } else if (side & LEFT) {
664 b.UR.x = P->end.p.x + 1;
665 if (endp->sidemask == TOP) {
666 b.UR.y = ND_coord(n).y + HT2(n);
667 b.LL.y = P->end.p.y - 1;
668 } else {
669 b.LL.y = ND_coord(n).y - HT2(n);
670 b.UR.y = P->end.p.y + 1;
671 }
672 endp->boxes[0] = b;
673 endp->boxn = 1;
674 --P->end.p.x;
675 } else {
676 b.LL.x = P->end.p.x - 1;
677 if (endp->sidemask == TOP) {
678 b.UR.y = ND_coord(n).y + HT2(n);
679 b.LL.y = P->end.p.y - 1;
680 } else {
681 b.LL.y = ND_coord(n).y - HT2(n);
682 b.UR.y = P->end.p.y;
683 }
684 endp->boxes[0] = b;
685 endp->boxn = 1;
686 ++P->end.p.x;
687 }
688 for (orig = e; ED_to_orig(orig) != NULL && ED_edge_type(orig) != NORMAL;
689 orig = ED_to_orig(orig))
690 ;
691 if (n == aghead(orig))
692 ED_head_port(orig).clip = false;
693 else
694 ED_tail_port(orig).clip = false;
695 endp->sidemask = side;
696 return;
697 }
698
699 if (!is_flat_edge)
700 side = TOP;
701 else
702 side = endp->sidemask; /* for flat edges */
703 if (pboxfn &&
704 (mask = pboxfn(n, &ED_head_port(e), side, &endp->boxes[0], &endp->boxn)))
705 endp->sidemask = mask;
706 else {
707 endp->boxes[0] = endp->nb;
708 endp->boxn = 1;
709
710 if (is_flat_edge) {
711 if (endp->sidemask == TOP)
712 endp->boxes[0].LL.y = P->end.p.y;
713 else
714 endp->boxes[0].UR.y = P->end.p.y;
715 } else {
716 endp->boxes[0].LL.y = P->end.p.y;
717 endp->sidemask = TOP;
718 ++P->end.p.y;
719 }
720 }
721}
722
723static int convert_sides_to_points(int tail_side, int head_side) {
724 int vertices[] = {12, 4, 6, 2, 3,
725 1, 9, 8}; // the cumulative side value of each node point
726 int i, tail_i, head_i;
727 int pair_a[8][8] = {
728 // array of possible node point pairs
729 {11, 12, 13, 14, 15, 16, 17, 18}, {21, 22, 23, 24, 25, 26, 27, 28},
730 {31, 32, 33, 34, 35, 36, 37, 38}, {41, 42, 43, 44, 45, 46, 47, 48},
731 {51, 52, 53, 54, 55, 56, 57, 58}, {61, 62, 63, 64, 65, 66, 67, 68},
732 {71, 72, 73, 74, 75, 76, 77, 78}, {81, 82, 83, 84, 85, 86, 87, 88}};
733
734 tail_i = head_i = -1;
735 for (i = 0; i < 8; i++) {
736 if (head_side == vertices[i]) {
737 head_i = i;
738 break;
739 }
740 }
741 for (i = 0; i < 8; i++) {
742 if (tail_side == vertices[i]) {
743 tail_i = i;
744 break;
745 }
746 }
747
748 if (tail_i < 0 || head_i < 0)
749 return 0;
750 else
751 return pair_a[tail_i][head_i];
752}
753
754static void selfBottom(edge_t *edges[], size_t cnt, double sizex, double stepy,
755 splineInfo *sinfo) {
756 pointf tp, hp, np;
757 node_t *n;
758 edge_t *e;
759 int sgn, point_pair;
760 double hy, ty, stepx, dx, dy, height;
761
762 e = *edges;
763 n = agtail(e);
764
765 stepx = fmax(sizex / 2.0 / (double)cnt, 2.0);
766 np = ND_coord(n);
767 tp = ED_tail_port(e).p;
768 tp.x += np.x;
769 tp.y += np.y;
770 hp = ED_head_port(e).p;
771 hp.x += np.x;
772 hp.y += np.y;
773 if (tp.x >= hp.x)
774 sgn = 1;
775 else
776 sgn = -1;
777 dy = ND_ht(n) / 2.0;
778 dx = 0.0;
779 // certain adjustments are required for some point_pairs in order to improve
780 // the display of the edge path between them
781 point_pair =
783 switch (point_pair) {
784 case 67:
785 sgn = -sgn;
786 break;
787 default:
788 break;
789 }
790 ty = fmin(dy, 3 * (tp.y + dy - np.y));
791 hy = fmin(dy, 3 * (hp.y + dy - np.y));
792 for (size_t i = 0; i < cnt; i++) {
793 e = edges[i];
794 dy += stepy;
795 ty += stepy;
796 hy += stepy;
797 dx += sgn * stepx;
798 pointf points[] = {tp,
799 {tp.x + dx, tp.y - ty / 3},
800 {tp.x + dx, np.y - dy},
801 {(tp.x + hp.x) / 2, np.y - dy},
802 {hp.x - dx, np.y - dy},
803 {hp.x - dx, hp.y - hy / 3},
804 hp};
805 if (ED_label(e)) {
806 if (GD_flip(agraphof(agtail(e)))) {
807 height = ED_label(e)->dimen.x;
808 } else {
809 height = ED_label(e)->dimen.y;
810 }
811 ED_label(e)->pos.y = ND_coord(n).y - dy - height / 2.0;
812 ED_label(e)->pos.x = ND_coord(n).x;
813 ED_label(e)->set = true;
814 if (height > stepy)
815 dy += height - stepy;
816 }
817 const size_t pointn = sizeof(points) / sizeof(points[0]);
818 clip_and_install(e, aghead(e), points, pointn, sinfo);
819#ifdef DEBUG
820 if (debugleveln(e, 1))
821 showPoints(points, pointn);
822#endif
823 }
824}
825
826static void selfTop(edge_t *edges[], size_t cnt, double sizex, double stepy,
827 splineInfo *sinfo) {
828 int sgn, point_pair;
829 double hy, ty, stepx, dx, dy, height;
830 pointf tp, hp, np;
831 node_t *n;
832 edge_t *e;
833
834 e = *edges;
835 n = agtail(e);
836
837 stepx = fmax(sizex / 2.0 / (double)cnt, 2.0);
838 np = ND_coord(n);
839 tp = ED_tail_port(e).p;
840 tp.x += np.x;
841 tp.y += np.y;
842 hp = ED_head_port(e).p;
843 hp.x += np.x;
844 hp.y += np.y;
845 if (tp.x >= hp.x)
846 sgn = 1;
847 else
848 sgn = -1;
849 dy = ND_ht(n) / 2., dx = 0.;
850 // certain adjustments are required for some point_pairs in order to improve
851 // the display of the edge path between them
852 point_pair =
854 switch (point_pair) {
855 case 15:
856 dx = sgn * (ND_rw(n) - (hp.x - np.x) + stepx);
857 break;
858
859 case 38:
860 dx = sgn * (ND_lw(n) - (np.x - hp.x) + stepx);
861 break;
862 case 41:
863 dx = sgn * (ND_rw(n) - (tp.x - np.x) + stepx);
864 break;
865 case 48:
866 dx = sgn * (ND_rw(n) - (tp.x - np.x) + stepx);
867 break;
868
869 case 14:
870 case 37:
871 case 47:
872 case 51:
873 case 57:
874 case 58:
875 dx = sgn * ((ND_lw(n) - (np.x - tp.x) + (ND_rw(n) - (hp.x - np.x))) / 3.0);
876 break;
877 case 73:
878 dx = sgn * (ND_lw(n) - (np.x - tp.x) + stepx);
879 break;
880 case 83:
881 dx = sgn * (ND_lw(n) - (np.x - tp.x));
882 break;
883 case 84:
884 dx = sgn * ((ND_lw(n) - (np.x - tp.x) + (ND_rw(n) - (hp.x - np.x))) / 2.0 +
885 stepx);
886 break;
887 case 74:
888 case 75:
889 case 85:
890 dx = sgn * ((ND_lw(n) - (np.x - tp.x) + (ND_rw(n) - (hp.x - np.x))) / 2.0 +
891 2 * stepx);
892 break;
893 default:
894 break;
895 }
896 ty = fmin(dy, 3 * (np.y + dy - tp.y));
897 hy = fmin(dy, 3 * (np.y + dy - hp.y));
898 for (size_t i = 0; i < cnt; i++) {
899 e = edges[i];
900 dy += stepy;
901 ty += stepy;
902 hy += stepy;
903 dx += sgn * stepx;
904 pointf points[] = {
905 tp,
906 {tp.x + dx, tp.y + ty / 3},
907 {tp.x + dx, np.y + dy},
908 {(tp.x + hp.x) / 2, np.y + dy},
909 {hp.x - dx, np.y + dy},
910 {hp.x - dx, hp.y + hy / 3},
911 hp,
912 };
913 if (ED_label(e)) {
914 if (GD_flip(agraphof(agtail(e)))) {
915 height = ED_label(e)->dimen.x;
916 } else {
917 height = ED_label(e)->dimen.y;
918 }
919 ED_label(e)->pos.y = ND_coord(n).y + dy + height / 2.0;
920 ED_label(e)->pos.x = ND_coord(n).x;
921 ED_label(e)->set = true;
922 if (height > stepy)
923 dy += height - stepy;
924 }
925 const size_t pointn = sizeof(points) / sizeof(points[0]);
926 clip_and_install(e, aghead(e), points, pointn, sinfo);
927#ifdef DEBUG
928 if (debugleveln(e, 1))
929 showPoints(points, pointn);
930#endif
931 }
932}
933
934static void selfRight(edge_t *edges[], size_t cnt, double stepx, double sizey,
935 splineInfo *sinfo) {
936 int sgn, point_pair;
937 double hx, tx, stepy, dx, dy, width;
938 pointf tp, hp, np;
939 node_t *n;
940 edge_t *e;
941
942 e = *edges;
943 n = agtail(e);
944
945 stepy = fmax(sizey / 2.0 / (double)cnt, 2.0);
946 np = ND_coord(n);
947 tp = ED_tail_port(e).p;
948 tp.x += np.x;
949 tp.y += np.y;
950 hp = ED_head_port(e).p;
951 hp.x += np.x;
952 hp.y += np.y;
953 if (tp.y >= hp.y)
954 sgn = 1;
955 else
956 sgn = -1;
957 dx = ND_rw(n), dy = 0;
958 // certain adjustments are required for some point_pairs in order to improve
959 // the display of the edge path between them
960 point_pair =
962 switch (point_pair) {
963 case 32:
964 case 65:
965 if (tp.y == hp.y)
966 sgn = -sgn;
967 break;
968 default:
969 break;
970 }
971 tx = fmin(dx, 3 * (np.x + dx - tp.x));
972 hx = fmin(dx, 3 * (np.x + dx - hp.x));
973 for (size_t i = 0; i < cnt; i++) {
974 e = edges[i];
975 dx += stepx;
976 tx += stepx;
977 hx += stepx;
978 dy += sgn * stepy;
979 pointf points[] = {
980 tp,
981 {tp.x + tx / 3, tp.y + dy},
982 {np.x + dx, tp.y + dy},
983 {np.x + dx, (tp.y + hp.y) / 2},
984 {np.x + dx, hp.y - dy},
985 {hp.x + hx / 3, hp.y - dy},
986 hp,
987 };
988 if (ED_label(e)) {
989 if (GD_flip(agraphof(agtail(e)))) {
990 width = ED_label(e)->dimen.y;
991 } else {
992 width = ED_label(e)->dimen.x;
993 }
994 ED_label(e)->pos.x = ND_coord(n).x + dx + width / 2.0;
995 ED_label(e)->pos.y = ND_coord(n).y;
996 ED_label(e)->set = true;
997 if (width > stepx)
998 dx += width - stepx;
999 }
1000 const size_t pointn = sizeof(points) / sizeof(points[0]);
1001 clip_and_install(e, aghead(e), points, pointn, sinfo);
1002#ifdef DEBUG
1003 if (debugleveln(e, 1))
1004 showPoints(points, pointn);
1005#endif
1006 }
1007}
1008
1009static void selfLeft(edge_t *edges[], size_t cnt, double stepx, double sizey,
1010 splineInfo *sinfo) {
1011 int sgn, point_pair;
1012 double hx, tx, stepy, dx, dy, width;
1013 pointf tp, hp, np;
1014 node_t *n;
1015 edge_t *e;
1016
1017 e = *edges;
1018 n = agtail(e);
1019
1020 stepy = fmax(sizey / 2.0 / (double)cnt, 2.0);
1021 np = ND_coord(n);
1022 tp = ED_tail_port(e).p;
1023 tp.x += np.x;
1024 tp.y += np.y;
1025 hp = ED_head_port(e).p;
1026 hp.x += np.x;
1027 hp.y += np.y;
1028
1029 if (tp.y >= hp.y)
1030 sgn = 1;
1031 else
1032 sgn = -1;
1033 dx = ND_lw(n), dy = 0.;
1034 // certain adjustments are required for some point_pairs in order to improve
1035 // the display of the edge path between them
1036 point_pair =
1038 switch (point_pair) {
1039 case 12:
1040 case 67:
1041 if (tp.y == hp.y)
1042 sgn = -sgn;
1043 break;
1044 default:
1045 break;
1046 }
1047 tx = fmin(dx, 3 * (tp.x + dx - np.x));
1048 hx = fmin(dx, 3 * (hp.x + dx - np.x));
1049 for (size_t i = 0; i < cnt; i++) {
1050 e = edges[i];
1051 dx += stepx;
1052 tx += stepx;
1053 hx += stepx;
1054 dy += sgn * stepy;
1055 pointf points[] = {
1056 tp,
1057 {tp.x - tx / 3, tp.y + dy},
1058 {np.x - dx, tp.y + dy},
1059 {np.x - dx, (tp.y + hp.y) / 2},
1060 {np.x - dx, hp.y - dy},
1061 {hp.x - hx / 3, hp.y - dy},
1062 hp,
1063 };
1064 if (ED_label(e)) {
1065 if (GD_flip(agraphof(agtail(e)))) {
1066 width = ED_label(e)->dimen.y;
1067 } else {
1068 width = ED_label(e)->dimen.x;
1069 }
1070 ED_label(e)->pos.x = ND_coord(n).x - dx - width / 2.0;
1071 ED_label(e)->pos.y = ND_coord(n).y;
1072 ED_label(e)->set = true;
1073 if (width > stepx)
1074 dx += width - stepx;
1075 }
1076
1077 const size_t pointn = sizeof(points) / sizeof(points[0]);
1078 clip_and_install(e, aghead(e), points, pointn, sinfo);
1079#ifdef DEBUG
1080 if (debugleveln(e, 1))
1081 showPoints(points, pointn);
1082#endif
1083 }
1084}
1085
1086/* Assume e is self-edge.
1087 * Return extra space necessary on the right for this edge.
1088 * If the edge does not go on the right, return 0.
1089 * NOTE: the actual space is determined dynamically by GD_nodesep,
1090 * so using the constant SELF_EDGE_SIZE is going to be wrong.
1091 * Fortunately, the default nodesep is the same as SELF_EDGE_SIZE.
1092 */
1094 double sw;
1095 double label_width;
1096 textlabel_t *l = ED_label(e);
1097
1098 if ((!ED_tail_port(e).defined && !ED_head_port(e).defined) ||
1099 (!(ED_tail_port(e).side & LEFT) && !(ED_head_port(e).side & LEFT) &&
1100 (ED_tail_port(e).side != ED_head_port(e).side ||
1101 !(ED_tail_port(e).side & (TOP | BOTTOM))))) {
1102 sw = SELF_EDGE_SIZE;
1103 if (l) {
1104 label_width = GD_flip(agraphof(aghead(e))) ? l->dimen.y : l->dimen.x;
1105 sw += label_width;
1106 }
1107 } else
1108 sw = 0;
1109 return sw;
1110}
1111
1112/* The routing is biased towards the right side because this is what
1113 * dot supports, and leaves room for.
1114 * FIX: With this bias, labels tend to be placed on top of each other.
1115 * Perhaps for self-edges, the label should be centered.
1116 */
1117void makeSelfEdge(edge_t *edges[], size_t cnt, double sizex, double sizey,
1118 splineInfo *sinfo) {
1119 edge_t *e = *edges;
1120
1121 /* self edge without ports or
1122 * self edge with all ports inside, on the right, or at most 1 on top
1123 * and at most 1 on bottom
1124 */
1125
1126 if ((!ED_tail_port(e).defined && !ED_head_port(e).defined) ||
1127 (!(ED_tail_port(e).side & LEFT) && !(ED_head_port(e).side & LEFT) &&
1128 (ED_tail_port(e).side != ED_head_port(e).side ||
1129 !(ED_tail_port(e).side & (TOP | BOTTOM))))) {
1130 selfRight(edges, cnt, sizex, sizey, sinfo);
1131 }
1132
1133 /* self edge with port on left side */
1134 else if ((ED_tail_port(e).side & LEFT) || (ED_head_port(e).side & LEFT)) {
1135
1136 /* handle L-R specially */
1137 if ((ED_tail_port(e).side & RIGHT) || (ED_head_port(e).side & RIGHT)) {
1138 selfTop(edges, cnt, sizex, sizey, sinfo);
1139 } else {
1140 selfLeft(edges, cnt, sizex, sizey, sinfo);
1141 }
1142 }
1143
1144 /* self edge with both ports on top side */
1145 else if (ED_tail_port(e).side & TOP) {
1146 selfTop(edges, cnt, sizex, sizey, sinfo);
1147 } else if (ED_tail_port(e).side & BOTTOM) {
1148 selfBottom(edges, cnt, sizex, sizey, sinfo);
1149 }
1150
1151 else
1152 assert(0);
1153}
1154
1157 /* Only use this if labelangle or labeldistance is set for the edge;
1158 * otherwise, handle with external labels.
1159 */
1161 return;
1162
1163 if (ED_head_label(e) && !ED_head_label(e)->set) {
1164 if (place_portlabel(e, true))
1166 }
1167 if (ED_tail_label(e) && !ED_tail_label(e)->set) {
1168 if (place_portlabel(e, false))
1170 }
1171}
1172
1174static void endPoints(splines *spl, pointf *p, pointf *q) {
1175 bezier bz;
1176
1177 bz = spl->list[0];
1178 if (bz.sflag) {
1179 *p = bz.sp;
1180 } else {
1181 *p = bz.list[0];
1182 }
1183 bz = spl->list[spl->size - 1];
1184 if (bz.eflag) {
1185 *q = bz.ep;
1186 } else {
1187 *q = bz.list[bz.size - 1];
1188 }
1189}
1190
1191/* Find midpoint of polyline.
1192 * pp and pq are set to the endpoints of the line segment containing it.
1193 */
1195 bezier bz;
1196 double d, dist = 0;
1197 pointf pf, qf, mf;
1198
1199 for (size_t i = 0; i < spl->size; i++) {
1200 bz = spl->list[i];
1201 for (size_t j = 0, k = 3; k < bz.size; j += 3, k += 3) {
1202 pf = bz.list[j];
1203 qf = bz.list[k];
1204 dist += DIST(pf, qf);
1205 }
1206 }
1207 dist /= 2;
1208 for (size_t i = 0; i < spl->size; i++) {
1209 bz = spl->list[i];
1210 for (size_t j = 0, k = 3; k < bz.size; j += 3, k += 3) {
1211 pf = bz.list[j];
1212 qf = bz.list[k];
1213 d = DIST(pf, qf);
1214 if (d >= dist) {
1215 *pp = pf;
1216 *pq = qf;
1217 mf.x = (qf.x * dist + pf.x * (d - dist)) / d;
1218 mf.y = (qf.y * dist + pf.y * (d - dist)) / d;
1219 return mf;
1220 } else
1221 dist -= d;
1222 }
1223 }
1224 UNREACHABLE();
1225}
1226
1228 int et = EDGE_TYPE(g);
1229 pointf spf, p, q;
1230
1231 endPoints(ED_spl(e), &p, &q);
1232 if (APPROXEQPT(p, q, MILLIPOINT)) { /* degenerate spline */
1233 spf = p;
1234 } else if (et == EDGETYPE_SPLINE || et == EDGETYPE_CURVED) {
1235 const pointf d = mid_pointf(p, q);
1236 spf = dotneato_closest(ED_spl(e), d);
1237 } else { /* EDGETYPE_PLINE, EDGETYPE_ORTHO or EDGETYPE_LINE */
1238 spf = polylineMidpoint(ED_spl(e), &p, &q);
1239 }
1240
1241 return spf;
1242}
1243
1244/* Adds label, headlabel and taillabel.
1245 * Updates bounding box.
1246 * We use the endpoints of the spline.
1247 */
1249
1250/* place the {head,tail}label (depending on HEAD_P) of edge E
1251 * N.B. Assume edges are normalized, so tail is at spl->list[0].list[0]
1252 * and head is at spl->list[spl->size-l].list[bez->size-1]
1253 * Return 1 on success
1254 */
1255int place_portlabel(edge_t *e, bool head_p) {
1256 splines *spl;
1257 pointf pe, pf;
1258
1259 if (ED_edge_type(e) == IGNORED)
1260 return 0;
1261 /* add label here only if labelangle or labeldistance is defined; else, use
1262 * external label */
1263 if ((!E_labelangle || streq(agxget(e, E_labelangle), "")) &&
1265 return 0;
1266 }
1267
1268 textlabel_t *const l = head_p ? ED_head_label(e) : ED_tail_label(e);
1269 if ((spl = getsplinepoints(e)) == NULL)
1270 return 0;
1271 if (!head_p) {
1272 const bezier *const bez = &spl->list[0];
1273 if (bez->sflag) {
1274 pe = bez->sp;
1275 pf = bez->list[0];
1276 } else {
1277 pe = bez->list[0];
1278 const pointf *const c = bez->list; // slice of the first 4 points
1279 pf = Bezier(c, 0.1, NULL, NULL);
1280 }
1281 } else {
1282 const bezier *const bez = &spl->list[spl->size - 1];
1283 if (bez->eflag) {
1284 pe = bez->ep;
1285 pf = bez->list[bez->size - 1];
1286 } else {
1287 pe = bez->list[bez->size - 1];
1288 // slice of the last 4 points
1289 const pointf *const c = &bez->list[bez->size - 4];
1290 pf = Bezier(c, 0.9, NULL, NULL);
1291 }
1292 }
1293 const double angle =
1294 atan2(pf.y - pe.y, pf.x - pe.x) +
1296 const double dist =
1298 l->pos.x = pe.x + dist * cos(angle);
1299 l->pos.y = pe.y + dist * sin(angle);
1300 l->set = true;
1301 return 1;
1302}
1303
1305 edge_t *le;
1306 splines *sp;
1307
1308 for (le = e; !(sp = ED_spl(le)) && ED_edge_type(le) != NORMAL;
1309 le = ED_to_orig(le))
1310 ;
1311 if (sp == NULL)
1312 agerrorf("getsplinepoints: no spline points available for edge (%s,%s)\n",
1313 agnameof(agtail(e)), agnameof(aghead(e)));
1314 return sp;
1315}
Dynamically expanding string buffers.
static int agxbprint(agxbuf *xb, const char *fmt,...)
Printf-style output to an agxbuf.
Definition agxbuf.h:252
static char * agxbdisown(agxbuf *xb)
Definition agxbuf.h:345
Memory allocation wrappers that exit on failure.
static void * gv_recalloc(void *ptr, size_t old_nmemb, size_t new_nmemb, size_t size)
Definition alloc.h:73
static char * gv_strdup(const char *original)
Definition alloc.h:101
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 MIN(a, b)
Definition arith.h:28
#define RADIANS(deg)
Definition arith.h:49
#define M_PI
Definition arith.h:41
#define MAX(a, b)
Definition arith.h:33
size_t arrowStartClip(edge_t *e, pointf *ps, size_t startp, size_t endp, bezier *spl, uint32_t sflag)
Definition arrows.c:313
size_t arrowEndClip(edge_t *e, pointf *ps, size_t startp, size_t endp, bezier *spl, uint32_t eflag)
Definition arrows.c:285
void arrowOrthoClip(edge_t *e, pointf *ps, size_t startp, size_t endp, bezier *spl, uint32_t sflag, uint32_t eflag)
Definition arrows.c:350
static bool inside(inside_t *inside_context, pointf p)
Definition arrows.c:280
void arrow_flags(Agedge_t *e, uint32_t *sflag, uint32_t *eflag)
Definition arrows.c:218
#define right(i)
Definition closest.c:74
pointf Bezier(const pointf *V, double t, pointf *Left, pointf *Right)
Definition utils.c:171
double late_double(void *obj, attrsym_t *attr, double defaultValue, double minimum)
Definition utils.c:54
pointf dotneato_closest(splines *spl, pointf pt)
Definition utils.c:323
void updateBB(graph_t *g, textlabel_t *lp)
Definition utils.c:575
#define NORMAL
Definition const.h:24
#define EDGETYPE_SPLINE
Definition const.h:239
#define LEFT
Definition const.h:120
#define IGNORED
Definition const.h:30
#define PORT_LABEL_DISTANCE
Definition const.h:101
#define EDGETYPE_CURVED
Definition const.h:236
#define RIGHT
Definition const.h:118
#define SELF_EDGE_SIZE
Definition const.h:98
#define ARR_NONE
Definition const.h:108
#define PORT_LABEL_ANGLE
Definition const.h:102
#define BOTTOM
Definition const.h:117
#define TOP
Definition const.h:119
static splineInfo sinfo
Definition dotsplines.c:125
static float dy
Definition draw.c:43
static float dx
Definition draw.c:42
#define left
Definition dthdr.h:12
#define le
Definition edges.h:29
void update_bb_bz(boxf *bb, const pointf *cp)
Definition emit.c:770
static double dist(int dim, double *x, double *y)
#define MILLIPOINT
Definition geom.h:74
#define APPROXEQPT(p, q, tol)
Definition geom.h:71
#define DIST(p, q)
Definition geom.h:56
geometric functions (e.g. on points and boxes)
static WUR pointf mid_pointf(pointf p, pointf q)
Definition geomprocs.h:104
static WUR pointf add_pointf(pointf p, pointf q)
Definition geomprocs.h:88
show_boxes_t Show_boxes
Definition globals.c:23
Agsym_t * E_labelangle
Definition globals.h:88
Agsym_t * E_labeldistance
Definition globals.h:88
node NULL
Definition grammar.y:181
static int cnt(Dict_t *d, Dtlink_t **set)
Definition graph.c:204
char * agxget(void *obj, Agsym_t *sym)
Definition attr.c:457
#define ED_to_orig(e)
Definition types.h:598
#define ED_showboxes(e)
Definition types.h:594
#define ED_head_label(e)
Definition types.h:587
#define ED_spl(e)
Definition types.h:595
#define agtail(e)
Definition cgraph.h:982
#define ED_edge_type(e)
Definition types.h:582
#define ED_tail_label(e)
Definition types.h:596
#define aghead(e)
Definition cgraph.h:983
#define ED_head_port(e)
Definition types.h:588
#define ED_label(e)
Definition types.h:589
#define ED_tail_port(e)
Definition types.h:597
void agerrorf(const char *fmt,...)
Definition agerror.c:167
#define GD_bb(g)
Definition types.h:354
#define GD_showboxes(g)
Definition types.h:401
#define GD_flip(g)
Definition types.h:378
#define GD_ranksep(g)
Definition types.h:397
#define ND_rank(n)
Definition types.h:523
#define ND_ht(n)
Definition types.h:500
#define ND_showboxes(n)
Definition types.h:530
#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_order(n)
Definition types.h:513
#define ND_coord(n)
Definition types.h:490
#define ND_in(n)
Definition types.h:501
#define ND_shape(n)
Definition types.h:528
#define ND_out(n)
Definition types.h:515
Agraph_t * agraphof(void *obj)
Definition obj.c:187
char * agnameof(void *)
returns a string descriptor for the object.
Definition id.c:145
Arithmetic helper functions.
#define SWAP(a, b)
Definition gv_math.h:133
static gdPoint * points
#define LIST_APPEND(list,...)
Definition list.h:151
#define EDGE_TYPE(g)
Definition macros.h:25
static int sgn(int x)
sgn, as defined in Graphics Gems I, §11.8, pp. 99
Definition pack.c:118
static void merge(edge_t *e, int minlen, int weight)
Definition rank.c:705
port resolvePort(node_t *n, node_t *other, port *oldport)
Definition shapes.c:4322
bezier * new_spline(edge_t *e, size_t sz)
create and attach a new Bézier of size sz to the edge d
Definition splines.c:200
void makePortLabels(edge_t *e)
add head and tail labels if necessary and update bounding box
Definition splines.c:1156
splines * getsplinepoints(edge_t *e)
Definition splines.c:1304
static double conc_slope(node_t *n)
Definition splines.c:295
void clip_and_install(edge_t *fe, node_t *hn, pointf *ps, size_t pn, splineInfo *info)
Definition splines.c:221
static void selfLeft(edge_t *edges[], size_t cnt, double stepx, double sizey, splineInfo *sinfo)
Definition splines.c:1009
double selfRightSpace(edge_t *e)
Definition splines.c:1093
static void arrow_clip(edge_t *fe, node_t *hn, pointf *ps, size_t *startp, size_t *endp, bezier *spl, splineInfo *info)
Definition splines.c:59
static void selfRight(edge_t *edges[], size_t cnt, double stepx, double sizey, splineInfo *sinfo)
Definition splines.c:934
void shape_clip(node_t *n, pointf curve[4])
Definition splines.c:182
static int convert_sides_to_points(int tail_side, int head_side)
Definition splines.c:723
static void shape_clip0(inside_t *inside_context, node_t *n, pointf curve[4], bool left_inside)
Definition splines.c:150
static void selfBottom(edge_t *edges[], size_t cnt, double sizex, double stepy, splineInfo *sinfo)
Definition splines.c:754
#define HT2(n)
Definition splines.c:358
void beginpath(path *P, edge_t *e, bool is_flat_edge, pathend_t *endp, bool merge)
Definition splines.c:360
void addEdgeLabels(edge_t *e)
Definition splines.c:1248
static void selfTop(edge_t *edges[], size_t cnt, double sizex, double stepy, splineInfo *sinfo)
Definition splines.c:826
pointf edgeMidpoint(graph_t *g, edge_t *e)
Definition splines.c:1227
#define FUDGE
Definition splines.c:357
void makeSelfEdge(edge_t *edges[], size_t cnt, double sizex, double sizey, splineInfo *sinfo)
Definition splines.c:1117
static pointf polylineMidpoint(splines *spl, pointf *pp, pointf *pq)
Definition splines.c:1194
void add_box(path *P, boxf b)
Definition splines.c:322
static void endPoints(splines *spl, pointf *p, pointf *q)
extract the actual end points of the spline, where they touch the node
Definition splines.c:1174
void bezier_clip(inside_t *inside_context, bool(*inside)(inside_t *inside_context, pointf p), pointf *sp, bool left_inside)
Definition splines.c:99
int place_portlabel(edge_t *e, bool head_p)
Definition splines.c:1255
void endpath(path *P, edge_t *e, bool is_flat_edge, pathend_t *endp, bool merge)
Definition splines.c:541
static bool streq(const char *a, const char *b)
are a and b equal?
Definition streq.h:11
graph or subgraph
Definition cgraph.h:424
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 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
void * data
Definition types.h:86
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
pointf np
Definition types.h:75
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
Definition heap.c:20
bezier * list
Definition types.h:99
size_t size
Definition types.h:100
pointf pos
Definition types.h:114
bool set
Definition types.h:123
pointf dimen
Definition types.h:110
struct inside_t::@57 s
node_t * n
Definition types.h:160
#define UNREACHABLE()
Definition unreachable.h:30
int(* pf)(void *, char *,...)
Definition xdot.c:392