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;
20 Site *bottomsite;
21 
22 static Freelist sfl;
23 static int nvertices;
24 
siteinit()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 
getsite()36 Site *getsite()
37 {
38     return ((Site *) getfree(&sfl));
39 }
40 
dist(Site * s,Site * t)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 
makevertex(Site * v)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 
deref(Site * v)63 void deref(Site * v)
64 {
65     v->refcnt -= 1;
66     if (v->refcnt == 0)
67 	makefree(v, &sfl);
68 }
69 
ref(Site * v)70 void ref(Site * v)
71 {
72     v->refcnt += 1;
73 }
74