Graphviz  2.41.20171026.1811
site.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 #include "mem.h"
15 #include "site.h"
16 #include <math.h>
17 
18 
19 int siteidx;
21 
22 static Freelist sfl;
23 static int nvertices;
24 
25 void siteinit()
26 {
27  /* double sn; */
28 
29  freeinit(&sfl, sizeof(Site));
30  nvertices = 0;
31  /* sn = nsites+4; */
32  /* sqrt_nsites = sqrt(sn); */
33 }
34 
35 
37 {
38  return ((Site *) getfree(&sfl));
39 }
40 
41 double dist(Site * s, Site * t)
42 {
43  double ans;
44  double dx, dy;
45 
46  dx = s->coord.x - t->coord.x;
47  dy = s->coord.y - t->coord.y;
48  ans = sqrt(dx * dx + dy * dy);
49  return ans;
50 }
51 
52 
53 void makevertex(Site * v)
54 {
55  v->sitenbr = nvertices;
56  nvertices += 1;
57 #ifdef STANDALONE
58  out_vertex(v);
59 #endif
60 }
61 
62 
63 void deref(Site * v)
64 {
65  v->refcnt -= 1;
66  if (v->refcnt == 0)
67  makefree(v, &sfl);
68 }
69 
70 void ref(Site * v)
71 {
72  v->refcnt += 1;
73 }
int refcnt
Definition: site.h:29
Site * bottomsite
Definition: site.c:20
Site * getsite()
Definition: site.c:36
double y
Definition: geometry.h:27
void * getfree(Freelist *)
Definition: memory.c:62
void siteinit()
Definition: site.c:25
Definition: site.h:26
int siteidx
Definition: site.c:19
double x
Definition: geometry.h:27
void makefree(void *, Freelist *)
Definition: memory.c:86
Definition: mem.h:29
Definition: grammar.c:79
void deref(Site *v)
Definition: site.c:63
void ref(Site *v)
Definition: site.c:70
double dist(Site *s, Site *t)
Definition: site.c:41
Point coord
Definition: site.h:27
int sitenbr
Definition: site.h:28
void makevertex(Site *v)
Definition: site.c:53
void freeinit(Freelist *, int)
Definition: memory.c:43