Graphviz 12.0.1~dev.20240716.0800
Loading...
Searching...
No Matches
util.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#include <assert.h>
13#include <cgraph/alloc.h>
14#include <limits.h>
15#include <stdlib.h>
16#include <pathplan/pathutil.h>
17
19{
20 free(p->ps);
21 free(p);
22}
23
24int Ppolybarriers(Ppoly_t ** polys, int npolys, Pedge_t ** barriers,
25 int *n_barriers)
26{
27 Ppoly_t pp;
28 int i, n, b;
29
30 n = 0;
31 for (i = 0; i < npolys; i++) {
32 assert(polys[i]->pn <= INT_MAX);
33 n += (int)polys[i]->pn;
34 }
35
36 Pedge_t *bar = gv_calloc(n, sizeof(Pedge_t));
37
38 b = 0;
39 for (i = 0; i < npolys; i++) {
40 pp = *polys[i];
41 for (size_t j = 0; j < pp.pn; j++) {
42 size_t k = j + 1;
43 if (k >= pp.pn)
44 k = 0;
45 bar[b].a = pp.ps[j];
46 bar[b].b = pp.ps[k];
47 b++;
48 }
49 }
50 assert(b == n);
51 *barriers = bar;
52 *n_barriers = n;
53 return 1;
54}
55
56/* make_polyline:
57 */
58void
60{
61 static size_t isz = 0;
62 static Ppoint_t* ispline = 0;
63 const size_t npts = 4 + 3 * (line.pn - 2);
64
65 if (npts > isz) {
66 ispline = gv_recalloc(ispline, isz, npts, sizeof(Ppoint_t));
67 isz = npts;
68 }
69
70 size_t j = 0;
71 size_t i = 0;
72 ispline[j+1] = ispline[j] = line.ps[i];
73 j += 2;
74 i++;
75 for (; i + 1 < line.pn; i++) {
76 ispline[j+2] = ispline[j+1] = ispline[j] = line.ps[i];
77 j += 3;
78 }
79 ispline[j+1] = ispline[j] = line.ps[i];
80
81 sline->pn = npts;
82 sline->ps = ispline;
83}
84
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 void * gv_calloc(size_t nmemb, size_t size)
Definition alloc.h:26
void free(void *)
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
void make_polyline(Ppolyline_t line, Ppolyline_t *sline)
Definition util.c:59
void freePath(Ppolyline_t *p)
Definition util.c:18
int Ppolybarriers(Ppoly_t **polys, int npolys, Pedge_t **barriers, int *n_barriers)
Definition util.c:24