Graphviz  2.41.20171026.1811
util.c
Go to the documentation of this file.
1 /* $Id$ $Revision$ */
2 /* vim:set shiftwidth=4 ts=8: */
3 
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 v1.0
8  * which accompanies this distribution, and is available at
9  * http://www.eclipse.org/legal/epl-v10.html
10  *
11  * Contributors: See CVS logs. Details at http://www.graphviz.org/
12  *************************************************************************/
13 
14 
15 #include <assert.h>
16 #include <stdlib.h>
17 #include "pathutil.h"
18 
19 #ifdef DMALLOC
20 #include "dmalloc.h"
21 #endif
22 
23 #define ALLOC(size,ptr,type) (ptr? (type*)realloc(ptr,(size)*sizeof(type)):(type*)malloc((size)*sizeof(type)))
24 
26 {
27  Ppoly_t rv;
28  int i;
29 
30  rv.pn = argpoly.pn;
31  rv.ps = malloc(sizeof(Ppoint_t) * argpoly.pn);
32  for (i = 0; i < argpoly.pn; i++)
33  rv.ps[i] = argpoly.ps[i];
34  return rv;
35 }
36 
38 {
39  free(p->ps);
40  free(p);
41 }
42 
43 void freepoly(Ppoly_t argpoly)
44 {
45  free(argpoly.ps);
46 }
47 
48 int Ppolybarriers(Ppoly_t ** polys, int npolys, Pedge_t ** barriers,
49  int *n_barriers)
50 {
51  Ppoly_t pp;
52  int i, j, k, n, b;
53  Pedge_t *bar;
54 
55  n = 0;
56  for (i = 0; i < npolys; i++)
57  n = n + polys[i]->pn;
58 
59  bar = malloc(n * sizeof(Pedge_t));
60 
61  b = 0;
62  for (i = 0; i < npolys; i++) {
63  pp = *polys[i];
64  for (j = 0; j < pp.pn; j++) {
65  k = j + 1;
66  if (k >= pp.pn)
67  k = 0;
68  bar[b].a = pp.ps[j];
69  bar[b].b = pp.ps[k];
70  b++;
71  }
72  }
73  assert(b == n);
74  *barriers = bar;
75  *n_barriers = n;
76  return 1;
77 }
78 
79 /* make_polyline:
80  */
81 void
83 {
84  static int isz = 0;
85  static Ppoint_t* ispline = 0;
86  int i, j;
87  int npts = 4 + 3*(line.pn-2);
88 
89  if (npts > isz) {
90  ispline = ALLOC(npts, ispline, Ppoint_t);
91  isz = npts;
92  }
93 
94  j = i = 0;
95  ispline[j+1] = ispline[j] = line.ps[i];
96  j += 2;
97  i++;
98  for (; i < line.pn-1; i++) {
99  ispline[j+2] = ispline[j+1] = ispline[j] = line.ps[i];
100  j += 3;
101  }
102  ispline[j+1] = ispline[j] = line.ps[i];
103 
104  sline->pn = npts;
105  sline->ps = ispline;
106 }
107 
void freepoly(Ppoly_t)
Definition: util.c:43
int pn
Definition: pathgeom.h:36
#define assert(x)
Definition: cghdr.h:47
void make_polyline(Ppolyline_t line, Ppolyline_t *sline)
Definition: util.c:82
Ppoint_t b
Definition: pathgeom.h:42
int Ppolybarriers(Ppoly_t **polys, int npolys, Pedge_t **barriers, int *n_barriers)
Definition: util.c:48
Ppoint_t * ps
Definition: pathgeom.h:35
Ppoint_t a
Definition: pathgeom.h:42
void freePath(Ppolyline_t *p)
Definition: util.c:37
Definition: pathgeom.h:26
#define ALLOC(size, ptr, type)
Definition: util.c:23
Ppoly_t copypoly(Ppoly_t)
Definition: util.c:25