/*************************************************************************
 * Copyright (c) 2011 AT&T Intellectual Property 
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors: Details at https://graphviz.org
 *************************************************************************/

#include <neatogen/mem.h>
#include <neatogen/site.h>
#include <math.h>


int siteidx;
Site *bottomsite;

static Freelist sfl;
static int nvertices;

void siteinit()
{
    freeinit(&sfl, sizeof(Site));
    nvertices = 0;
}


Site *getsite()
{
    return getfree(&sfl);
}

double dist(Site * s, Site * t)
{
    double ans;
    double dx, dy;

    dx = s->coord.x - t->coord.x;
    dy = s->coord.y - t->coord.y;
    ans = hypot(dx, dy);
    return ans;
}


void makevertex(Site * v)
{
    v->sitenbr = nvertices;
    ++nvertices;
#ifdef STANDALONE
    out_vertex(v);
#endif
}


void deref(Site * v)
{
    --v->refcnt;
    if (v->refcnt == 0)
	makefree(v, &sfl);
}

void ref(Site * v)
{
    ++v->refcnt;
}
