Graphviz  2.29.20120524.0446
lib/neatogen/site.c
Go to the documentation of this file.
00001 /* $Id$ $Revision$ */
00002 /* vim:set shiftwidth=4 ts=8: */
00003 
00004 /*************************************************************************
00005  * Copyright (c) 2011 AT&T Intellectual Property 
00006  * All rights reserved. This program and the accompanying materials
00007  * are made available under the terms of the Eclipse Public License v1.0
00008  * which accompanies this distribution, and is available at
00009  * http://www.eclipse.org/legal/epl-v10.html
00010  *
00011  * Contributors: See CVS logs. Details at http://www.graphviz.org/
00012  *************************************************************************/
00013 
00014 #include "mem.h"
00015 #include "site.h"
00016 #include <math.h>
00017 
00018 
00019 int siteidx;
00020 Site *bottomsite;
00021 
00022 static Freelist sfl;
00023 static int nvertices;
00024 
00025 void siteinit()
00026 {
00027     /* double sn; */
00028 
00029     freeinit(&sfl, sizeof(Site));
00030     nvertices = 0;
00031     /* sn = nsites+4; */
00032     /* sqrt_nsites = sqrt(sn); */
00033 }
00034 
00035 
00036 Site *getsite()
00037 {
00038     return ((Site *) getfree(&sfl));
00039 }
00040 
00041 double dist(Site * s, Site * t)
00042 {
00043     double ans;
00044     double dx, dy;
00045 
00046     dx = s->coord.x - t->coord.x;
00047     dy = s->coord.y - t->coord.y;
00048     ans = sqrt(dx * dx + dy * dy);
00049     return ans;
00050 }
00051 
00052 
00053 void makevertex(Site * v)
00054 {
00055     v->sitenbr = nvertices;
00056     nvertices += 1;
00057 #ifdef STANDALONE
00058     out_vertex(v);
00059 #endif
00060 }
00061 
00062 
00063 void deref(Site * v)
00064 {
00065     v->refcnt -= 1;
00066     if (v->refcnt == 0)
00067         makefree(v, &sfl);
00068 }
00069 
00070 void ref(Site * v)
00071 {
00072     v->refcnt += 1;
00073 }