Graphviz 14.1.2~dev.20260123.1158
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#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
20{
21 free(p->ps);
22 free(p);
23}
24
25int 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 */
59void
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
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:60
void freePath(Ppolyline_t *p)
Definition util.c:19
int Ppolybarriers(Ppoly_t **polys, int npolys, Pedge_t **barriers, int *n_barriers)
Definition util.c:25