00001 /* $Id: site.c,v 1.1.1.1 2004/12/23 04:05:16 ellson Exp $ $Revision: 1.1.1.1 $ */ 00002 /* vim:set shiftwidth=4 ts=8: */ 00003 00004 /********************************************************** 00005 * This software is part of the graphviz package * 00006 * http://www.graphviz.org/ * 00007 * * 00008 * Copyright (c) 1994-2004 AT&T Corp. * 00009 * and is licensed under the * 00010 * Common Public License, Version 1.0 * 00011 * by AT&T Corp. * 00012 * * 00013 * Information and Software Systems Research * 00014 * AT&T Research, Florham Park NJ * 00015 **********************************************************/ 00016 00017 #include "mem.h" 00018 #include "site.h" 00019 #include <math.h> 00020 00021 00022 int siteidx; 00023 Site *bottomsite; 00024 00025 static Freelist sfl; 00026 static int nvertices; 00027 00028 void siteinit() 00029 { 00030 /* double sn; */ 00031 00032 freeinit(&sfl, sizeof(Site)); 00033 nvertices = 0; 00034 /* sn = nsites+4; */ 00035 /* sqrt_nsites = sqrt(sn); */ 00036 } 00037 00038 00039 Site *getsite() 00040 { 00041 return ((Site *) getfree(&sfl)); 00042 } 00043 00044 double dist(Site * s, Site * t) 00045 { 00046 double ans; 00047 double dx, dy; 00048 00049 dx = s->coord.x - t->coord.x; 00050 dy = s->coord.y - t->coord.y; 00051 ans = sqrt(dx * dx + dy * dy); 00052 return ans; 00053 } 00054 00055 00056 void makevertex(Site * v) 00057 { 00058 v->sitenbr = nvertices; 00059 nvertices += 1; 00060 #ifdef STANDALONE 00061 out_vertex(v); 00062 #endif 00063 } 00064 00065 00066 void deref(Site * v) 00067 { 00068 v->refcnt -= 1; 00069 if (v->refcnt == 0) 00070 makefree(v, &sfl); 00071 } 00072 00073 void ref(Site * v) 00074 { 00075 v->refcnt += 1; 00076 }