Graphviz 13.1.1~dev.20250718.1235
Loading...
Searching...
No Matches
routespl.c
Go to the documentation of this file.
1
3/*************************************************************************
4 * Copyright (c) 2011 AT&T Intellectual Property
5 * All rights reserved. This program and the accompanying materials
6 * are made available under the terms of the Eclipse Public License v1.0
7 * which accompanies this distribution, and is available at
8 * https://www.eclipse.org/legal/epl-v10.html
9 *
10 * Contributors: Details at https://graphviz.org
11 *************************************************************************/
12
13#include "config.h"
14#include <assert.h>
15#include <common/geomprocs.h>
16#include <common/render.h>
17#include <float.h>
18#include <limits.h>
19#include <math.h>
20#include <pathplan/pathplan.h>
21#include <stdbool.h>
22#include <stdint.h>
23#include <stdlib.h>
24#include <string.h>
25#include <util/agxbuf.h>
26#include <util/alloc.h>
27#include <util/debug.h>
28#include <util/gv_math.h>
29#include <util/list.h>
30#include <util/prisize_t.h>
31
32static int nedges;
33static size_t nboxes;
34
35static int routeinit;
36
37static int checkpath(size_t, boxf *, path *);
38static void printpath(path * pp);
39#ifdef DEBUG
40static void printboxes(size_t boxn, boxf *boxes) {
41 pointf ll, ur;
42
43 for (size_t bi = 0; bi < boxn; bi++) {
44 ll = boxes[bi].LL, ur = boxes[bi].UR;
45 agxbuf buf = {0};
46 agxbprint(&buf, "%.0f %.0f %.0f %.0f pathbox", ll.x, ll.y, ur.x, ur.y);
47 show_boxes_append(&Show_boxes, agxbdisown(&buf));
48 }
49}
50
51#if DEBUG > 1
52static void psprintpolypts(Ppoint_t * p, int sz)
53{
54 int i;
55
56 fprintf(stderr, "%%!\n");
57 fprintf(stderr, "%% constraint poly\n");
58 fprintf(stderr, "newpath\n");
59 for (i = 0; i < sz; i++)
60 fprintf(stderr, "%f %f %s\n", p[i].x, p[i].y, i == 0 ? "moveto" : "lineto");
61 fprintf(stderr, "closepath stroke\n");
62}
63static void psprintpoint(point p)
64{
65 fprintf(stderr, "gsave\n");
66 fprintf(stderr,
67 "newpath %d %d moveto %d %d 2 0 360 arc closepath fill stroke\n",
68 p.x, p.y, p.x, p.y);
69 fprintf(stderr, "/Times-Roman findfont 4 scalefont setfont\n");
70 fprintf(stderr, "%d %d moveto (\\(%d,%d\\)) show\n", p.x + 5, p.y + 5,
71 p.x, p.y);
72 fprintf(stderr, "grestore\n");
73}
74static void psprintpointf(pointf p)
75{
76 fprintf(stderr, "gsave\n");
77 fprintf(stderr,
78 "newpath %.5g %.5g moveto %.5g %.5g 2 0 360 arc closepath fill stroke\n",
79 p.x, p.y, p.x, p.y);
80 fprintf(stderr, "/Times-Roman findfont 4 scalefont setfont\n");
81 fprintf(stderr, "%.5g %.5g moveto (\\(%.5g,%.5g\\)) show\n", p.x + 5, p.y + 5,
82 p.x, p.y);
83 fprintf(stderr, "grestore\n");
84}
85#endif
86
87static void psprintspline(Ppolyline_t spl)
88{
89 show_boxes_append(&Show_boxes, gv_strdup("%%!"));
90 show_boxes_append(&Show_boxes, gv_strdup("%% spline"));
91 show_boxes_append(&Show_boxes, gv_strdup("gsave 1 0 0 setrgbcolor newpath"));
92 for (size_t i = 0; i < spl.pn; i++) {
93 agxbuf buf = {0};
94 agxbprint(&buf, "%f %f %s", spl.ps[i].x, spl.ps[i].y,
95 i == 0 ? "moveto" : (i % 3 == 0 ? "curveto" : ""));
96 show_boxes_append(&Show_boxes, agxbdisown(&buf));
97 }
98 show_boxes_append(&Show_boxes, gv_strdup("stroke grestore"));
99}
100
101static void psprintline(Ppolyline_t pl)
102{
103 show_boxes_append(&Show_boxes, gv_strdup("%%!"));
104 show_boxes_append(&Show_boxes, gv_strdup("%% line"));
105 show_boxes_append(&Show_boxes, gv_strdup("gsave 0 0 1 setrgbcolor newpath"));
106 for (size_t i = 0; i < pl.pn; i++) {
107 agxbuf buf = {0};
108 agxbprint(&buf, "%f %f %s", pl.ps[i].x, pl.ps[i].y,
109 i == 0 ? "moveto" : "lineto");
110 show_boxes_append(&Show_boxes, agxbdisown(&buf));
111 }
112 show_boxes_append(&Show_boxes, gv_strdup("stroke grestore"));
113}
114
115static void psprintpoly(Ppoly_t p)
116{
117 char* pfx;
118
119 show_boxes_append(&Show_boxes, gv_strdup("%% poly list"));
120 show_boxes_append(&Show_boxes, gv_strdup("gsave 0 1 0 setrgbcolor"));
121 for (size_t bi = 0; bi < p.pn; bi++) {
122 const pointf tail = p.ps[bi];
123 const pointf head = p.ps[(bi + 1) % p.pn];
124 if (fabs(tail.x - head.x) < 1 && fabs(tail.y - head.y) < 1) pfx = "%%";
125 else pfx ="";
126 agxbuf buf = {0};
127 agxbprint(&buf, "%s%.0f %.0f %.0f %.0f makevec", pfx, tail.x, tail.y, head.x,
128 head.y);
129 show_boxes_append(&Show_boxes, agxbdisown(&buf));
130 }
131 show_boxes_append(&Show_boxes, gv_strdup("grestore"));
132}
133
134static void psprintboxes(size_t boxn, boxf *boxes) {
135 pointf ll, ur;
136
137 show_boxes_append(&Show_boxes, gv_strdup("%% box list"));
138 show_boxes_append(&Show_boxes, gv_strdup("gsave 0 1 0 setrgbcolor"));
139 for (size_t bi = 0; bi < boxn; bi++) {
140 ll = boxes[bi].LL, ur = boxes[bi].UR;
141 agxbuf buf = {0};
142 agxbprint(&buf, "newpath\n%.0f %.0f moveto", ll.x, ll.y);
143 show_boxes_append(&Show_boxes, agxbdisown(&buf));
144 agxbprint(&buf, "%.0f %.0f lineto", ll.x, ur.y);
145 show_boxes_append(&Show_boxes, agxbdisown(&buf));
146 agxbprint(&buf, "%.0f %.0f lineto", ur.x, ur.y);
147 show_boxes_append(&Show_boxes, agxbdisown(&buf));
148 agxbprint(&buf, "%.0f %.0f lineto", ur.x, ll.y);
149 show_boxes_append(&Show_boxes, agxbdisown(&buf));
150 show_boxes_append(&Show_boxes, gv_strdup("closepath stroke"));
151 }
152 show_boxes_append(&Show_boxes, gv_strdup("grestore"));
153}
154
155static void psprintinit (int begin)
156{
157 if (begin)
158 show_boxes_append(&Show_boxes, gv_strdup("dbgstart"));
159 else
160 show_boxes_append(&Show_boxes, gv_strdup("grestore"));
161}
162
163static bool debugleveln(edge_t* realedge, int i)
164{
165 return GD_showboxes(agraphof(aghead(realedge))) == i ||
166 GD_showboxes(agraphof(agtail(realedge))) == i ||
167 ED_showboxes(realedge) == i ||
168 ND_showboxes(aghead(realedge)) == i ||
169 ND_showboxes(agtail(realedge)) == i;
170}
171#endif /* DEBUG */
172
174pointf *simpleSplineRoute(pointf tp, pointf hp, Ppoly_t poly, size_t *n_spl_pts,
175 int polyline) {
176 Ppolyline_t pl, spl;
177 Ppoint_t eps[2];
178 Pvector_t evs[2];
179
180 eps[0].x = tp.x;
181 eps[0].y = tp.y;
182 eps[1].x = hp.x;
183 eps[1].y = hp.y;
184 if (Pshortestpath(&poly, eps, &pl) < 0)
185 return NULL;
186
187 if (polyline)
188 make_polyline (pl, &spl);
189 else {
190 // polygon edges passed to Proutespline
191 Pedge_t *edges = gv_calloc(poly.pn, sizeof(Pedge_t));
192 for (size_t i = 0; i < poly.pn; i++) {
193 edges[i].a = poly.ps[i];
194 edges[i].b = poly.ps[(i + 1) % poly.pn];
195 }
196 evs[0].x = evs[0].y = 0;
197 evs[1].x = evs[1].y = 0;
198 if (Proutespline(edges, poly.pn, pl, evs, &spl) < 0) {
199 free(edges);
200 return NULL;
201 }
202 free(edges);
203 }
204
205 pointf *ps = calloc(spl.pn, sizeof(ps[0]));
206 if (ps == NULL) {
207 agerrorf("cannot allocate ps\n");
208 return NULL;
209 }
210 for (size_t i = 0; i < spl.pn; i++) {
211 ps[i] = spl.ps[i];
212 }
213 *n_spl_pts = spl.pn;
214 return ps;
215}
216
220int
222{
223 if (++routeinit > 1) return 0;
224#ifdef DEBUG
225 show_boxes_free(&Show_boxes);
226#endif
227 nedges = 0;
228 nboxes = 0;
229 if (Verbose)
230 start_timer();
231 return 0;
232}
233
235{
236 if (--routeinit > 0) return;
237 if (Verbose)
238 fprintf(stderr,
239 "routesplines: %d edges, %" PRISIZE_T " boxes %.2f sec\n",
241}
242
243static void limitBoxes(boxf *boxes, size_t boxn, const pointf *pps, size_t pn,
244 double delta) {
245 double t;
246 pointf sp[4];
247 const double num_div = delta * (double)boxn;
248
249 for (size_t splinepi = 0; splinepi + 3 < pn; splinepi += 3) {
250 for (double si = 0; si <= num_div; si++) {
251 t = si / num_div;
252 sp[0] = pps[splinepi];
253 sp[1] = pps[splinepi + 1];
254 sp[2] = pps[splinepi + 2];
255 sp[3] = pps[splinepi + 3];
256 sp[0].x += t * (sp[1].x - sp[0].x);
257 sp[0].y += t * (sp[1].y - sp[0].y);
258 sp[1].x += t * (sp[2].x - sp[1].x);
259 sp[1].y += t * (sp[2].y - sp[1].y);
260 sp[2].x += t * (sp[3].x - sp[2].x);
261 sp[2].y += t * (sp[3].y - sp[2].y);
262 sp[0].x += t * (sp[1].x - sp[0].x);
263 sp[0].y += t * (sp[1].y - sp[0].y);
264 sp[1].x += t * (sp[2].x - sp[1].x);
265 sp[1].y += t * (sp[2].y - sp[1].y);
266 sp[0].x += t * (sp[1].x - sp[0].x);
267 sp[0].y += t * (sp[1].y - sp[0].y);
268 for (size_t bi = 0; bi < boxn; bi++) {
269/* this tested ok on 64bit machines, but on 32bit we need this FUDGE
270 * or graphs/directed/records.gv fails */
271#define FUDGE .0001
272 if (sp[0].y <= boxes[bi].UR.y+FUDGE && sp[0].y >= boxes[bi].LL.y-FUDGE) {
273 boxes[bi].LL.x = fmin(boxes[bi].LL.x, sp[0].x);
274 boxes[bi].UR.x = fmax(boxes[bi].UR.x, sp[0].x);
275 }
276 }
277 }
278 }
279}
280
281#define INIT_DELTA 10
282#define LOOP_TRIES 15 /* number of times to try to limiting boxes to regain space, using smaller divisions */
283
299static pointf *routesplines_(path *pp, size_t *npoints, int polyline) {
301 Ppolyline_t pl, spl;
302 Ppoint_t eps[2];
303 Pvector_t evs[2];
304 int prev, next;
305 boxf *boxes;
306 edge_t* realedge;
307 bool flip;
308 int loopcnt;
309 bool unbounded;
310
311 *npoints = 0;
312 nedges++;
313 nboxes += pp->nbox;
314
315 for (realedge = pp->data;
316 realedge && ED_edge_type(realedge) != NORMAL;
317 realedge = ED_to_orig(realedge));
318 if (!realedge) {
319 agerrorf("in routesplines, cannot find NORMAL edge\n");
320 return NULL;
321 }
322
323 boxes = pp->boxes;
324 const size_t boxn = pp->nbox;
325
326 if (checkpath(boxn, boxes, pp))
327 return NULL;
328
329#ifdef DEBUG
330 if (debugleveln(realedge, 1))
331 printboxes(boxn, boxes);
332 if (debugleveln(realedge, 3)) {
333 psprintinit(1);
334 psprintboxes(boxn, boxes);
335 }
336#endif
337
338 // vertices of polygon defined by boxes
339 Ppoint_t *polypoints = gv_calloc(boxn * 8, sizeof(Ppoint_t));
340
341 if (boxn > 1 && boxes[0].LL.y > boxes[1].LL.y) {
342 flip = true;
343 for (size_t bi = 0; bi < boxn; bi++) {
344 double v = boxes[bi].UR.y;
345 boxes[bi].UR.y = -1*boxes[bi].LL.y;
346 boxes[bi].LL.y = -v;
347 }
348 }
349 else flip = false;
350
351 size_t pi;
352 if (agtail(realedge) != aghead(realedge)) {
353 /* I assume that the path goes either down only or
354 up - right - down */
355 size_t bi;
356 for (bi = 0, pi = 0; bi < boxn; bi++) {
357 next = prev = 0;
358 if (bi > 0)
359 prev = boxes[bi].LL.y > boxes[bi - 1].LL.y ? -1 : 1;
360 if (bi + 1 < boxn)
361 next = boxes[bi + 1].LL.y > boxes[bi].LL.y ? 1 : -1;
362 if (prev != next) {
363 if (next == -1 || prev == 1) {
364 polypoints[pi].x = boxes[bi].LL.x;
365 polypoints[pi++].y = boxes[bi].UR.y;
366 polypoints[pi].x = boxes[bi].LL.x;
367 polypoints[pi++].y = boxes[bi].LL.y;
368 } else {
369 polypoints[pi].x = boxes[bi].UR.x;
370 polypoints[pi++].y = boxes[bi].LL.y;
371 polypoints[pi].x = boxes[bi].UR.x;
372 polypoints[pi++].y = boxes[bi].UR.y;
373 }
374 }
375 else if (prev == 0) { /* single box */
376 polypoints[pi].x = boxes[bi].LL.x;
377 polypoints[pi++].y = boxes[bi].UR.y;
378 polypoints[pi].x = boxes[bi].LL.x;
379 polypoints[pi++].y = boxes[bi].LL.y;
380 }
381 else {
382 if (!(prev == -1 && next == -1)) {
383 free(polypoints);
384 agerrorf("in routesplines, illegal values of prev %d and next %d, line %d\n", prev, next, __LINE__);
385 return NULL;
386 }
387 }
388 }
389 for (bi = boxn - 1; bi != SIZE_MAX; bi--) {
390 next = prev = 0;
391 if (bi + 1 < boxn)
392 prev = boxes[bi].LL.y > boxes[bi + 1].LL.y ? -1 : 1;
393 if (bi > 0)
394 next = boxes[bi - 1].LL.y > boxes[bi].LL.y ? 1 : -1;
395 if (prev != next) {
396 if (next == -1 || prev == 1 ) {
397 polypoints[pi].x = boxes[bi].LL.x;
398 polypoints[pi++].y = boxes[bi].UR.y;
399 polypoints[pi].x = boxes[bi].LL.x;
400 polypoints[pi++].y = boxes[bi].LL.y;
401 } else {
402 polypoints[pi].x = boxes[bi].UR.x;
403 polypoints[pi++].y = boxes[bi].LL.y;
404 polypoints[pi].x = boxes[bi].UR.x;
405 polypoints[pi++].y = boxes[bi].UR.y;
406 }
407 }
408 else if (prev == 0) { /* single box */
409 polypoints[pi].x = boxes[bi].UR.x;
410 polypoints[pi++].y = boxes[bi].LL.y;
411 polypoints[pi].x = boxes[bi].UR.x;
412 polypoints[pi++].y = boxes[bi].UR.y;
413 }
414 else {
415 if (!(prev == -1 && next == -1)) {
416 /* it went badly, e.g. degenerate box in boxlist */
417 free(polypoints);
418 agerrorf("in routesplines, illegal values of prev %d and next %d, line %d\n", prev, next, __LINE__);
419 return NULL; /* for correctness sake, it's best to just stop */
420 }
421 polypoints[pi].x = boxes[bi].UR.x;
422 polypoints[pi++].y = boxes[bi].LL.y;
423 polypoints[pi].x = boxes[bi].UR.x;
424 polypoints[pi++].y = boxes[bi].UR.y;
425 polypoints[pi].x = boxes[bi].LL.x;
426 polypoints[pi++].y = boxes[bi].UR.y;
427 polypoints[pi].x = boxes[bi].LL.x;
428 polypoints[pi++].y = boxes[bi].LL.y;
429 }
430 }
431 }
432 else {
433 free(polypoints);
434 agerrorf("in routesplines, edge is a loop at %s\n", agnameof(aghead(realedge)));
435 return NULL;
436 }
437
438 if (flip) {
439 for (size_t bi = 0; bi < boxn; bi++) {
440 double v = boxes[bi].UR.y;
441 boxes[bi].UR.y = -1*boxes[bi].LL.y;
442 boxes[bi].LL.y = -v;
443 }
444 for (size_t i = 0; i < pi; i++)
445 polypoints[i].y *= -1;
446 }
447
448 static const double INITIAL_LLX = DBL_MAX;
449 static const double INITIAL_URX = -DBL_MAX;
450 for (size_t bi = 0; bi < boxn; bi++) {
451 boxes[bi].LL.x = INITIAL_LLX;
452 boxes[bi].UR.x = INITIAL_URX;
453 }
454 poly.ps = polypoints, poly.pn = pi;
455 eps[0].x = pp->start.p.x, eps[0].y = pp->start.p.y;
456 eps[1].x = pp->end.p.x, eps[1].y = pp->end.p.y;
457 if (Pshortestpath(&poly, eps, &pl) < 0) {
458 free(polypoints);
459 agerrorf("in routesplines, Pshortestpath failed\n");
460 return NULL;
461 }
462#ifdef DEBUG
463 if (debugleveln(realedge, 3)) {
464 psprintpoly(poly);
465 psprintline(pl);
466 }
467#endif
468
469 if (polyline) {
470 make_polyline (pl, &spl);
471 }
472 else {
473 Pedge_t *edges = gv_calloc(poly.pn, sizeof(Pedge_t));
474 for (size_t edgei = 0; edgei < poly.pn; edgei++) {
475 edges[edgei].a = polypoints[edgei];
476 edges[edgei].b = polypoints[(edgei + 1) % poly.pn];
477 }
478 if (pp->start.constrained) {
479 evs[0].x = cos(pp->start.theta);
480 evs[0].y = sin(pp->start.theta);
481 } else
482 evs[0].x = evs[0].y = 0;
483 if (pp->end.constrained) {
484 evs[1].x = -cos(pp->end.theta);
485 evs[1].y = -sin(pp->end.theta);
486 } else
487 evs[1].x = evs[1].y = 0;
488
489 if (Proutespline(edges, poly.pn, pl, evs, &spl) < 0) {
490 free(edges);
491 free(polypoints);
492 agerrorf("in routesplines, Proutespline failed\n");
493 return NULL;
494 }
495 free(edges);
496#ifdef DEBUG
497 if (debugleveln(realedge, 3)) {
498 psprintspline(spl);
499 psprintinit(0);
500 }
501#endif
502 }
503 pointf *ps = calloc(spl.pn, sizeof(ps[0]));
504 if (ps == NULL) {
505 free(polypoints);
506 agerrorf("cannot allocate ps\n");
507 return NULL; /* Bailout if no memory left */
508 }
509
510 unbounded = true;
511 for (size_t splinepi = 0; splinepi < spl.pn; splinepi++) {
512 ps[splinepi] = spl.ps[splinepi];
513 }
514
515 {
516 // does the spline go straight left/right?
517 bool is_horizontal = spl.pn > 0;
518 for (size_t i = 0; i < spl.pn; ++i) {
519 if (fabs(ps[0].y - ps[i].y) > FUDGE) {
520 is_horizontal = false;
521 break;
522 }
523 }
524 if (is_horizontal) {
525 GV_INFO("spline [%.03f, %.03f] -- [%.03f, %.03f] is horizontal;"
526 " will be trivially bounded", ps[0].x, ps[0].y, ps[spl.pn - 1].x,
527 ps[spl.pn - 1].y);
528 }
529
530 // does the spline go straight up/down?
531 bool is_vertical = spl.pn > 0;
532 for (size_t i = 0; i < spl.pn; ++i) {
533 if (fabs(ps[0].x - ps[i].x) > FUDGE) {
534 is_vertical = false;
535 break;
536 }
537 }
538 if (is_vertical) {
539 GV_INFO("spline [%.03f, %.03f] -- [%.03f, %.03f] is vertical;"
540 " will be trivially bounded", ps[0].x, ps[0].y, ps[spl.pn - 1].x,
541 ps[spl.pn - 1].y);
542 }
543
544 // if the spline is horizontal or vertical, the `limitBoxes` loop will not
545 // converge, but we know the expected outcome trivially
546 if (is_horizontal || is_vertical) {
547 for (size_t i = 0; i < boxn; ++i) {
548 boxes[i].LL.x = ps[0].x;
549 boxes[i].UR.x = ps[0].x;
550 }
551 unbounded = false;
552 }
553 }
554
555 double delta = INIT_DELTA;
556
557 for (loopcnt = 0; unbounded && loopcnt < LOOP_TRIES; loopcnt++) {
558 limitBoxes(boxes, boxn, ps, spl.pn, delta);
559
560 /* The following check is necessary because if a box is not very
561 * high, it is possible that the sampling above might miss it.
562 * Therefore, we make the sample finer until all boxes have
563 * valid values. cf. bug 456.
564 */
565 size_t bi;
566 for (bi = 0; bi < boxn; bi++) {
567 /* these fp equality tests are used only to detect if the
568 * values have been changed since initialization - ok */
569 if (is_exactly_equal(boxes[bi].LL.x, INITIAL_LLX) ||
570 is_exactly_equal(boxes[bi].UR.x, INITIAL_URX)) {
571 delta *= 2; /* try again with a finer interval */
572 break;
573 }
574 }
575 if (bi == boxn)
576 unbounded = false;
577 }
578 if (unbounded) {
579 /* Either an extremely short, even degenerate, box, or some failure with the path
580 * planner causing the spline to miss some boxes. In any case, use the shortest path
581 * to bound the boxes. This will probably mean a bad edge, but we avoid an infinite
582 * loop and we can see the bad edge, and even use the showboxes scaffolding.
583 */
584 Ppolyline_t polyspl;
585 agwarningf("Unable to reclaim box space in spline routing for edge \"%s\" -> \"%s\". Something is probably seriously wrong.\n", agnameof(agtail(realedge)), agnameof(aghead(realedge)));
586 make_polyline (pl, &polyspl);
587 limitBoxes(boxes, boxn, polyspl.ps, polyspl.pn, INIT_DELTA);
588 }
589
590 *npoints = spl.pn;
591
592#ifdef DEBUG
593 if (GD_showboxes(agraphof(aghead(realedge))) == 2 ||
594 GD_showboxes(agraphof(agtail(realedge))) == 2 ||
595 ED_showboxes(realedge) == 2 ||
596 ND_showboxes(aghead(realedge)) == 2 ||
597 ND_showboxes(agtail(realedge)) == 2)
598 printboxes(boxn, boxes);
599#endif
600
601 free(polypoints);
602 return ps;
603}
604
605pointf *routesplines(path *pp, size_t *npoints) {
606 return routesplines_(pp, npoints, 0);
607}
608
609pointf *routepolylines(path *pp, size_t *npoints) {
610 return routesplines_(pp, npoints, 1);
611}
612
613static double overlap(double i0, double i1, double j0, double j1) {
614 if (i1 <= j0)
615 return 0;
616 if (i0 >= j1)
617 return 0;
618
619 // does the first interval subsume the second?
620 if (i0 <= j0 && i1 >= j1)
621 return i1 - i0;
622 // does the second interval subsume the first?
623 if (j0 <= i0 && j1 >= i1)
624 return j1 - j0;
625
626 if (j0 <= i0 && i0 <= j1)
627 return j1 - i0;
628 assert(j0 <= i1 && i1 <= j1);
629 return i1 - j0;
630}
631
632
633/*
634 * repairs minor errors in the boxpath, such as boxes not joining
635 * or slightly intersecting. it's sort of the equivalent of the
636 * audit process in the 5E control program - if you've given up on
637 * fixing all the bugs, at least try to engineer around them!
638 * in postmodern CS, we could call this "self-healing code."
639 *
640 * Return 1 on failure; 0 on success.
641 */
642static int checkpath(size_t boxn, boxf *boxes, path *thepath) {
643 boxf *ba, *bb;
644 int errs, l, r, d, u;
645
646 /* remove degenerate boxes. */
647 size_t i = 0;
648 for (size_t bi = 0; bi < boxn; bi++) {
649 if (fabs(boxes[bi].LL.y - boxes[bi].UR.y) < .01)
650 continue;
651 if (fabs(boxes[bi].LL.x - boxes[bi].UR.x) < .01)
652 continue;
653 boxes[i] = boxes[bi];
654 i++;
655 }
656 boxn = i;
657
658 ba = &boxes[0];
659 if (ba->LL.x > ba->UR.x || ba->LL.y > ba->UR.y) {
660 agerrorf("in checkpath, box 0 has LL coord > UR coord\n");
661 printpath(thepath);
662 return 1;
663 }
664 for (size_t bi = 0; bi + 1 < boxn; bi++) {
665 ba = &boxes[bi], bb = &boxes[bi + 1];
666 if (bb->LL.x > bb->UR.x || bb->LL.y > bb->UR.y) {
667 agerrorf("in checkpath, box %" PRISIZE_T " has LL coord > UR coord\n",
668 bi + 1);
669 printpath(thepath);
670 return 1;
671 }
672 l = ba->UR.x < bb->LL.x ? 1 : 0;
673 r = ba->LL.x > bb->UR.x ? 1 : 0;
674 d = ba->UR.y < bb->LL.y ? 1 : 0;
675 u = ba->LL.y > bb->UR.y ? 1 : 0;
676 errs = l + r + d + u;
677 if (errs > 0 && Verbose) {
678 fprintf(stderr, "in checkpath, boxes %" PRISIZE_T " and %" PRISIZE_T
679 " don't touch\n", bi, bi + 1);
680 printpath(thepath);
681 }
682 if (errs > 0) {
683 double xy;
684
685 if (l == 1)
686 xy = ba->UR.x, ba->UR.x = bb->LL.x, bb->LL.x = xy, l = 0;
687 else if (r == 1)
688 xy = ba->LL.x, ba->LL.x = bb->UR.x, bb->UR.x = xy, r = 0;
689 else if (d == 1)
690 xy = ba->UR.y, ba->UR.y = bb->LL.y, bb->LL.y = xy, d = 0;
691 else if (u == 1)
692 xy = ba->LL.y, ba->LL.y = bb->UR.y, bb->UR.y = xy, u = 0;
693 for (int j = 0; j < errs - 1; j++) {
694 if (l == 1)
695 xy = (ba->UR.x + bb->LL.x) / 2.0 + 0.5, ba->UR.x =
696 bb->LL.x = xy, l = 0;
697 else if (r == 1)
698 xy = (ba->LL.x + bb->UR.x) / 2.0 + 0.5, ba->LL.x =
699 bb->UR.x = xy, r = 0;
700 else if (d == 1)
701 xy = (ba->UR.y + bb->LL.y) / 2.0 + 0.5, ba->UR.y =
702 bb->LL.y = xy, d = 0;
703 else if (u == 1)
704 xy = (ba->LL.y + bb->UR.y) / 2.0 + 0.5, ba->LL.y =
705 bb->UR.y = xy, u = 0;
706 }
707 }
708 /* check for overlapping boxes */
709 double xoverlap = overlap(ba->LL.x, ba->UR.x, bb->LL.x, bb->UR.x);
710 double yoverlap = overlap(ba->LL.y, ba->UR.y, bb->LL.y, bb->UR.y);
711 if (xoverlap > 0 && yoverlap > 0) {
712 if (xoverlap < yoverlap) {
713 if (ba->UR.x - ba->LL.x > bb->UR.x - bb->LL.x) {
714 /* take space from ba */
715 if (ba->UR.x < bb->UR.x)
716 ba->UR.x = bb->LL.x;
717 else
718 ba->LL.x = bb->UR.x;
719 } else {
720 /* take space from bb */
721 if (ba->UR.x < bb->UR.x)
722 bb->LL.x = ba->UR.x;
723 else
724 bb->UR.x = ba->LL.x;
725 }
726 } else { /* symmetric for y coords */
727 if (ba->UR.y - ba->LL.y > bb->UR.y - bb->LL.y) {
728 /* take space from ba */
729 if (ba->UR.y < bb->UR.y)
730 ba->UR.y = bb->LL.y;
731 else
732 ba->LL.y = bb->UR.y;
733 } else {
734 /* take space from bb */
735 if (ba->UR.y < bb->UR.y)
736 bb->LL.y = ba->UR.y;
737 else
738 bb->UR.y = ba->LL.y;
739 }
740 }
741 }
742 }
743
744 if (thepath->start.p.x < boxes[0].LL.x
745 || thepath->start.p.x > boxes[0].UR.x
746 || thepath->start.p.y < boxes[0].LL.y
747 || thepath->start.p.y > boxes[0].UR.y) {
748 thepath->start.p.x = fmax(thepath->start.p.x, boxes[0].LL.x);
749 thepath->start.p.x = fmin(thepath->start.p.x, boxes[0].UR.x);
750 thepath->start.p.y = fmax(thepath->start.p.y, boxes[0].LL.y);
751 thepath->start.p.y = fmin(thepath->start.p.y, boxes[0].UR.y);
752 }
753 if (thepath->end.p.x < boxes[boxn - 1].LL.x
754 || thepath->end.p.x > boxes[boxn - 1].UR.x
755 || thepath->end.p.y < boxes[boxn - 1].LL.y
756 || thepath->end.p.y > boxes[boxn - 1].UR.y) {
757 thepath->end.p.x = fmax(thepath->end.p.x, boxes[boxn - 1].LL.x);
758 thepath->end.p.x = fmin(thepath->end.p.x, boxes[boxn - 1].UR.x);
759 thepath->end.p.y = fmax(thepath->end.p.y, boxes[boxn - 1].LL.y);
760 thepath->end.p.y = fmin(thepath->end.p.y, boxes[boxn - 1].UR.y);
761 }
762 return 0;
763}
764
765static void printpath(path * pp)
766{
767 fprintf(stderr, "%" PRISIZE_T " boxes:\n", pp->nbox);
768 for (size_t bi = 0; bi < pp->nbox; bi++)
769 fprintf(stderr, "%" PRISIZE_T " (%.5g, %.5g), (%.5g, %.5g)\n", bi,
770 pp->boxes[bi].LL.x, pp->boxes[bi].LL.y,
771 pp->boxes[bi].UR.x, pp->boxes[bi].UR.y);
772 fprintf(stderr, "start port: (%.5g, %.5g), tangent angle: %.5g, %s\n",
773 pp->start.p.x, pp->start.p.y, pp->start.theta,
774 pp->start.constrained ? "constrained" : "not constrained");
775 fprintf(stderr, "end port: (%.5g, %.5g), tangent angle: %.5g, %s\n",
776 pp->end.p.x, pp->end.p.y, pp->end.theta,
777 pp->end.constrained ? "constrained" : "not constrained");
778}
779
781{
782 pointf sum = {0.0, 0.0};
783
784 sum.x = (GD_bb(g).LL.x + GD_bb(g).UR.x) / 2.0;
785 sum.y = (GD_bb(g).LL.y + GD_bb(g).UR.y) / 2.0;
786 return sum;
787}
788
789DEFINE_LIST(nodes, node_t *)
790
791static void nodes_delete(nodes_t *pvec) {
792 if (pvec != NULL) {
793 nodes_free(pvec);
794 }
795 free(pvec);
796}
797
798DEFINE_LIST_WITH_DTOR(cycles, nodes_t *, nodes_delete)
799
800static bool cycle_contains_edge(nodes_t *cycle, edge_t *edge) {
801 node_t* start = agtail(edge);
802 node_t* end = aghead(edge);
803
804 const size_t cycle_len = nodes_size(cycle);
805
806 for (size_t i=0; i < cycle_len; ++i) {
807 const node_t *c_start = nodes_get(cycle, i == 0 ? cycle_len - 1 : i - 1);
808 const node_t *c_end = nodes_get(cycle, i);
809
810 if (c_start == start && c_end == end)
811 return true;
812 }
813
814
815 return false;
816}
817
818static bool eq(const node_t *a, const node_t *b) { return a == b; }
819
820static bool is_cycle_unique(cycles_t *cycles, nodes_t *cycle) {
821 const size_t cycle_len = nodes_size(cycle);
822 size_t i; //node counter
823
824 bool all_items_match;
825
826 for (size_t c = 0; c < cycles_size(cycles); ++c) {
827 nodes_t *cur_cycle = cycles_get(cycles, c);
828 const size_t cur_cycle_len = nodes_size(cur_cycle);
829
830 //if all the items match in equal length cycles then we're not unique
831 if (cur_cycle_len == cycle_len) {
832 all_items_match = true;
833 for (i=0; i < cur_cycle_len; ++i) {
834 node_t *cur_cycle_item = nodes_get(cur_cycle, i);
835 if (!nodes_contains(cycle, cur_cycle_item, eq)) {
836 all_items_match = false;
837 break;
838 }
839 }
840 if (all_items_match)
841 return false;
842 }
843 }
844
845 return true;
846}
847
848static void dfs(graph_t *g, node_t *search, nodes_t *visited, node_t *end,
849 cycles_t *cycles) {
850 edge_t* e;
851 node_t* n;
852
853 if (nodes_contains(visited, search, eq)) {
854 if (search == end) {
855 if (is_cycle_unique(cycles, visited)) {
856 nodes_t *cycle = gv_alloc(sizeof(nodes_t));
857 *cycle = nodes_copy(visited);
858 cycles_append(cycles, cycle);
859 }
860 }
861 } else {
862 nodes_append(visited, search);
863 for (e = agfstout(g, search); e; e = agnxtout(g, e)) {
864 n = aghead(e);
865 dfs(g, n, visited, end, cycles);
866 }
867 if (!nodes_is_empty(visited)) {
868 (void)nodes_pop_back(visited);
869 }
870 }
871}
872
873// Returns a vec of vec of nodes (aka a vector of cycles)
874static cycles_t find_all_cycles(graph_t *g) {
875 node_t *n;
876
877 // vector of vectors of nodes -- AKA cycles to delete
878 cycles_t alloced_cycles = {0};
879 cycles_t cycles = {0}; // vector of vectors of nodes AKA a vector of cycles
880
881 for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
882 nodes_t *cycle = gv_alloc(sizeof(nodes_t));
883 // keep track of all items we allocate to clean up at the end of this function
884 cycles_append(&alloced_cycles, cycle);
885
886 dfs(g, n, cycle, n, &cycles);
887 }
888
889 cycles_free(&alloced_cycles); // cycles contains copied vecs
890 return cycles;
891}
892
893static nodes_t *find_shortest_cycle_with_edge(cycles_t *cycles, edge_t *edge,
894 size_t min_size) {
895 nodes_t *shortest = NULL;
896
897 for (size_t c = 0; c < cycles_size(cycles); ++c) {
898 nodes_t *cycle = cycles_get(cycles, c);
899 size_t cycle_len = nodes_size(cycle);
900
901 if (cycle_len < min_size)
902 continue;
903
904 if (shortest == NULL || nodes_size(shortest) > cycle_len) {
905 if (cycle_contains_edge(cycle, edge)) {
906 shortest = cycle;
907 }
908 }
909 }
910 return shortest;
911}
912
914{
915 cycles_t cycles = find_all_cycles(g);
916
917 //find the center of the shortest cycle containing this edge
918 //cycles of length 2 do their own thing, we want 3 or
919 nodes_t *cycle = find_shortest_cycle_with_edge(&cycles, edge, 3);
920 pointf sum = {0.0, 0.0};
921
922 if (cycle == NULL) {
923 cycles_free(&cycles);
924 return get_centroid(g);
925 }
926
927 double cnt = 0;
928 for (size_t idx = 0; idx < nodes_size(cycle); ++idx) {
929 node_t *n = nodes_get(cycle, idx);
930 sum.x += ND_coord(n).x;
931 sum.y += ND_coord(n).y;
932 cnt++;
933 }
934
935 cycles_free(&cycles);
936
937 sum.x /= cnt;
938 sum.y /= cnt;
939 return sum;
940}
941
942static void bend(pointf spl[4], pointf centroid)
943{
944 pointf a;
945 double r;
946
947 pointf midpt = mid_pointf(spl[0], spl[3]);
948 double dist = DIST(spl[3], spl[0]);
949 r = dist/5.0;
950 {
951 double vX = centroid.x - midpt.x;
952 double vY = centroid.y - midpt.y;
953 double magV = hypot(vX, vY);
954 if (magV == 0) return; /* if midpoint == centroid, don't divide by zero */
955 a.x = midpt.x - vX / magV * r; /* + would be closest point */
956 a.y = midpt.y - vY / magV * r;
957 }
958 /* this can be improved */
959 spl[1].x = spl[2].x = a.x;
960 spl[1].y = spl[2].y = a.y;
961}
962
963// FIX: handle ports on boundary?
964void
966{
967 edge_t *e0;
968
969 size_t e_cnt = 1;
970 e0 = e;
971 while (e0 != ED_to_virt(e0) && (e0 = ED_to_virt(e0))) e_cnt++;
972
973 edge_t **edge_list = gv_calloc(e_cnt, sizeof(edge_t *));
974 e0 = e;
975 for (size_t i = 0; i < e_cnt; i++) {
976 edge_list[i] = e0;
977 e0 = ED_to_virt(e0);
978 }
979 assert(e_cnt <= INT_MAX);
980 makeStraightEdges(g, edge_list, e_cnt, et, sinfo);
981 free(edge_list);
982}
983
984void makeStraightEdges(graph_t *g, edge_t **edge_list, size_t e_cnt, int et,
985 splineInfo *sinfo) {
986 pointf dumb[4];
987 bool curved = et == EDGETYPE_CURVED;
988 pointf del;
989
990 edge_t *e = edge_list[0];
991 node_t *n = agtail(e);
992 node_t *head = aghead(e);
993 dumb[1] = dumb[0] = add_pointf(ND_coord(n), ED_tail_port(e).p);
994 dumb[2] = dumb[3] = add_pointf(ND_coord(head), ED_head_port(e).p);
995 if (e_cnt == 1 || Concentrate) {
996 if (curved) bend(dumb,get_cycle_centroid(g, edge_list[0]));
997 clip_and_install(e, aghead(e), dumb, 4, sinfo);
998 addEdgeLabels(e);
999 return;
1000 }
1001
1002 if (APPROXEQPT(dumb[0], dumb[3], MILLIPOINT)) {
1003 /* degenerate case */
1004 dumb[1] = dumb[0];
1005 dumb[2] = dumb[3];
1006 del.x = 0;
1007 del.y = 0;
1008 }
1009 else {
1010 pointf perp = {
1011 .x = dumb[0].y - dumb[3].y,
1012 .y = dumb[3].x - dumb[0].x
1013 };
1014 double l_perp = hypot(perp.x, perp.y);
1015 int xstep = GD_nodesep(g->root);
1016 assert(e_cnt - 1 <= INT_MAX);
1017 int dx = xstep * (int)(e_cnt - 1) / 2;
1018 dumb[1].x = dumb[0].x + dx * perp.x / l_perp;
1019 dumb[1].y = dumb[0].y + dx * perp.y / l_perp;
1020 dumb[2].x = dumb[3].x + dx * perp.x / l_perp;
1021 dumb[2].y = dumb[3].y + dx * perp.y / l_perp;
1022 del.x = -xstep * perp.x / l_perp;
1023 del.y = -xstep * perp.y / l_perp;
1024 }
1025
1026 for (size_t i = 0; i < e_cnt; i++) {
1027 edge_t *e0 = edge_list[i];
1028 pointf dumber[4];
1029 if (aghead(e0) == head) {
1030 for (size_t j = 0; j < 4; j++) {
1031 dumber[j] = dumb[j];
1032 }
1033 } else {
1034 for (size_t j = 0; j < 4; j++) {
1035 dumber[3 - j] = dumb[j];
1036 }
1037 }
1038 if (et == EDGETYPE_PLINE) {
1039 Ppoint_t pts[] = {dumber[0], dumber[1], dumber[2], dumber[3]};
1040 Ppolyline_t spl, line = {.pn = 4, .ps = pts};
1041 make_polyline (line, &spl);
1042 clip_and_install(e0, aghead(e0), spl.ps, (size_t)spl.pn, sinfo);
1043 }
1044 else
1045 clip_and_install(e0, aghead(e0), dumber, 4, sinfo);
1046
1047 addEdgeLabels(e0);
1048 dumb[1] = add_pointf(dumb[1], del);
1049 dumb[2] = add_pointf(dumb[2], del);
1050 }
1051}
static int agxbprint(agxbuf *xb, const char *fmt,...)
Printf-style output to an agxbuf.
Definition agxbuf.h:234
static char * agxbdisown(agxbuf *xb)
Definition agxbuf.h:327
Memory allocation wrappers that exit on failure.
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 NORMAL
Definition const.h:24
#define EDGETYPE_CURVED
Definition const.h:250
#define EDGETYPE_PLINE
Definition const.h:251
helpers for verbose/debug printing
#define GV_INFO(...)
Definition debug.h:15
static splineInfo sinfo
Definition dotsplines.c:129
static float dx
Definition draw.c:38
#define head
Definition dthdr.h:15
static void del(Dict_t *d, Dtlink_t **set, Agedge_t *e)
Definition edge.c:156
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 pointf mid_pointf(pointf p, pointf q)
Definition geomprocs.h:106
static pointf add_pointf(pointf p, pointf q)
Definition geomprocs.h:88
static pointf perp(pointf p)
Definition geomprocs.h:146
bool Concentrate
Definition globals.h:59
show_boxes_t Show_boxes
Definition globals.h:57
static bool Verbose
Definition gml2gv.c:23
void free(void *)
edge
Definition gmlparse.y:239
#define SIZE_MAX
Definition gmlscan.c:347
node NULL
Definition grammar.y:180
static int cnt(Dict_t *d, Dtlink_t **set)
Definition graph.c:198
#define ED_to_orig(e)
Definition types.h:598
#define ED_showboxes(e)
Definition types.h:594
Agedge_t * agfstout(Agraph_t *g, Agnode_t *n)
Definition edge.c:26
#define agtail(e)
Definition cgraph.h:988
#define ED_edge_type(e)
Definition types.h:582
#define aghead(e)
Definition cgraph.h:989
Agedge_t * agnxtout(Agraph_t *g, Agedge_t *e)
Definition edge.c:41
#define ED_head_port(e)
Definition types.h:588
#define ED_tail_port(e)
Definition types.h:597
#define ED_to_virt(e)
Definition types.h:599
void agwarningf(const char *fmt,...)
Definition agerror.c:173
void agerrorf(const char *fmt,...)
Definition agerror.c:165
#define GD_bb(g)
Definition types.h:354
#define GD_showboxes(g)
Definition types.h:401
#define GD_nodesep(g)
Definition types.h:394
Agnode_t * agnxtnode(Agraph_t *g, Agnode_t *n)
Definition node.c:48
Agnode_t * agfstnode(Agraph_t *g)
Definition node.c:41
#define ND_showboxes(n)
Definition types.h:530
#define ND_coord(n)
Definition types.h:490
Agraph_t * agraphof(void *obj)
Definition obj.c:185
char * agnameof(void *)
returns a string descriptor for the object.
Definition id.c:143
Arithmetic helper functions.
static bool is_exactly_equal(double a, double b)
are two values precisely the same?
Definition gv_math.h:45
$2 u p prev
Definition htmlparse.y:297
#define DEFINE_LIST_WITH_DTOR(name, type, dtor)
Definition list.h:30
#define DEFINE_LIST(name, type)
Definition list.h:22
static int * ps
Definition lu.c:51
#define delta
Definition maze.c:136
finds and smooths shortest paths
void make_polyline(Ppolyline_t line, Ppolyline_t *sline)
Definition util.c:59
int Proutespline(Pedge_t *barriers, size_t n_barriers, Ppolyline_t input_route, Pvector_t endpoint_slopes[2], Ppolyline_t *output_route)
Definition route.c:69
int Pshortestpath(Ppoly_t *boundary, Ppoint_t endpoints[2], Ppolyline_t *output_route)
Definition shortest.c:83
#define PRISIZE_T
Definition prisize_t.h:25
void clip_and_install(edge_t *fe, node_t *hn, pointf *ps, size_t pn, splineInfo *info)
Definition splines.c:239
void addEdgeLabels(edge_t *e)
Definition splines.c:1324
static bool is_cycle_unique(cycles_t *cycles, nodes_t *cycle)
Definition routespl.c:820
#define INIT_DELTA
Definition routespl.c:281
static void printpath(path *pp)
Definition routespl.c:765
static int routeinit
Definition routespl.c:35
static pointf get_centroid(Agraph_t *g)
Definition routespl.c:780
static void dfs(graph_t *g, node_t *search, nodes_t *visited, node_t *end, cycles_t *cycles)
Definition routespl.c:848
int routesplinesinit(void)
Definition routespl.c:221
static int nedges
total no. of edges used in routing
Definition routespl.c:32
static void nodes_delete(nodes_t *pvec)
Definition routespl.c:791
pointf * simpleSplineRoute(pointf tp, pointf hp, Ppoly_t poly, size_t *n_spl_pts, int polyline)
Given a simple (ccw) polygon, route an edge from tp to hp.
Definition routespl.c:174
static nodes_t * find_shortest_cycle_with_edge(cycles_t *cycles, edge_t *edge, size_t min_size)
Definition routespl.c:893
static bool eq(const node_t *a, const node_t *b)
Definition routespl.c:818
static bool cycle_contains_edge(nodes_t *cycle, edge_t *edge)
Definition routespl.c:800
static cycles_t find_all_cycles(graph_t *g)
Definition routespl.c:874
#define LOOP_TRIES
Definition routespl.c:282
static size_t nboxes
total no. of boxes used in routing
Definition routespl.c:33
static void limitBoxes(boxf *boxes, size_t boxn, const pointf *pps, size_t pn, double delta)
Definition routespl.c:243
static int checkpath(size_t, boxf *, path *)
Definition routespl.c:642
static pointf get_cycle_centroid(graph_t *g, edge_t *edge)
Definition routespl.c:913
static double overlap(double i0, double i1, double j0, double j1)
Definition routespl.c:613
#define FUDGE
void routesplinesterm(void)
Definition routespl.c:234
void makeStraightEdges(graph_t *g, edge_t **edge_list, size_t e_cnt, int et, splineInfo *sinfo)
Definition routespl.c:984
void makeStraightEdge(graph_t *g, edge_t *e, int et, splineInfo *sinfo)
Definition routespl.c:965
pointf * routesplines(path *pp, size_t *npoints)
Definition routespl.c:605
pointf * routepolylines(path *pp, size_t *npoints)
Definition routespl.c:609
static pointf * routesplines_(path *pp, size_t *npoints, int polyline)
Definition routespl.c:299
graph or subgraph
Definition cgraph.h:424
Agraph_t * root
subgraphs - ancestors
Definition cgraph.h:433
Ppoint_t b
Definition pathgeom.h:53
Ppoint_t a
Definition pathgeom.h:53
size_t pn
Definition pathgeom.h:47
Ppoint_t * ps
Definition pathgeom.h:46
double x
Definition pathgeom.h:38
double y
Definition pathgeom.h:38
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
Definition geom.h:27
int y
Definition geom.h:27
int x
Definition geom.h:27
double x
Definition geom.h:29
double y
Definition geom.h:29
pointf p
Definition types.h:49
double theta
Definition types.h:50
bool constrained
Definition types.h:55
bend
Definition structures.h:32
struct poly_s poly
double elapsed_sec(void)
Definition timing.c:48
void start_timer(void)
Definition timing.c:43