Debian Codegraph @

lib/pathplan/util.c

raw
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 #include "config.h"
12
13 #include <assert.h>
14 #include <limits.h>
15 #include <stdlib.h>
16 #include <pathplan/pathutil.h>
17 #include <util/alloc.h>
18
19 void freePath(Ppolyline_t* p)
20 {
21 free(p->ps);
22 free(p);
23 }
24
25 int Ppolybarriers(Ppoly_t ** polys, int npolys, Pedge_t ** barriers,
26 int *n_barriers)
27 {
28 Ppoly_t pp;
29 int i, n, b;
30
31 n = 0;
32 for (i = 0; i < npolys; i++) {
33 assert(polys[i]->pn <= INT_MAX);
34 n += (int)polys[i]->pn;
35 }
36
37 Pedge_t *bar = gv_calloc(n, sizeof(Pedge_t));
38
39 b = 0;
40 for (i = 0; i < npolys; i++) {
41 pp = *polys[i];
42 for (size_t j = 0; j < pp.pn; j++) {
43 size_t k = j + 1;
44 if (k >= pp.pn)
45 k = 0;
46 bar[b].a = pp.ps[j];
47 bar[b].b = pp.ps[k];
48 b++;
49 }
50 }
51 assert(b == n);
52 *barriers = bar;
53 *n_barriers = n;
54 return 1;
55 }
56
57 /* make_polyline:
58 */
59 void
60 make_polyline(Ppolyline_t line, Ppolyline_t* sline)
61 {
62 static size_t isz = 0;
63 static Ppoint_t* ispline = 0;
64 const size_t npts = 4 + 3 * (line.pn - 2);
65
66 if (npts > isz) {
67 ispline = gv_recalloc(ispline, isz, npts, sizeof(Ppoint_t));
68 isz = npts;
69 }
70
71 size_t j = 0;
72 size_t i = 0;
73 ispline[j+1] = ispline[j] = line.ps[i];
74 j += 2;
75 i++;
76 for (; i + 1 < line.pn; i++) {
77 ispline[j+2] = ispline[j+1] = ispline[j] = line.ps[i];
78 j += 3;
79 }
80 ispline[j+1] = ispline[j] = line.ps[i];
81
82 sline->pn = npts;
83 sline->ps = ispline;
84 }
85
86 /**
87 * @dir lib/pathplan
88 * @brief finds and smooths shortest paths, API pathplan.h
89 *
90 * [man 3 pathplan](https://graphviz.org/pdf/pathplan.3.pdf)
91 *
92 */