void VoronoiDiagramGenerator::reset()
{
	cleanup();
	cleanupEdges();

	if(allMemoryList != 0)
		delete allMemoryList;

	if(finalVertices != 0)
		free(finalVertices);

	if(vertexLinks != 0)
		free(vertexLinks);

	if(vertices != 0)
		free(vertices);

	if(finalVertexLinks != 0)
		free(finalVertexLinks);	

	allMemoryList = 0;
	finalVertices = 0;
	vertexLinks = 0;
	vertices = 0;
	finalVertexLinks = 0;
}
VoronoiDiagramGenerator::~VoronoiDiagramGenerator()
{
	cleanup();
	cleanupEdges();

	if(allMemoryList != 0)
		delete allMemoryList;
}
bool VoronoiDiagramGenerator::generateVoronoi(float *xValues, float *yValues, int numPoints, float minX, float maxX, float minY, float maxY, float minDist)
{
	cleanup();
	cleanupEdges();
	int i;

	minDistanceBetweenSites = minDist;

	nsites=numPoints;
	plot = 0;
	triangulate = 0;	
	debug = 1;
	sorted = 0; 
	freeinit(&sfl, sizeof (Site));
		
	sites = (struct Site *) myalloc(nsites*sizeof( *sites));

	if(sites == 0)
		return false;

	xmin = xValues[0];
	ymin = yValues[0];
	xmax = xValues[0];
	ymax = yValues[0];

	for(i = 0; i< nsites; i++)
	{
		sites[i].coord.x = xValues[i];
		sites[i].coord.y = yValues[i];
		sites[i].sitenbr = i;
		sites[i].refcnt = 0;

		if(xValues[i] < xmin)
			xmin = xValues[i];
		else if(xValues[i] > xmax)
			xmax = xValues[i];

		if(yValues[i] < ymin)
			ymin = yValues[i];
		else if(yValues[i] > ymax)
			ymax = yValues[i];

		//printf("\n%f %f\n",xValues[i],yValues[i]);
	}
	
	qsort(sites, nsites, sizeof (*sites), scomp);
	
	siteidx = 0;
	geominit();
	float temp = 0;
	if(minX > maxX)
	{
		temp = minX;
		minX = maxX;
		maxX = temp;
	}
	if(minY > maxY)
	{
		temp = minY;
		minY = maxY;
		maxY = temp;
	}
	borderMinX = minX;
	borderMinY = minY;
	borderMaxX = maxX;
	borderMaxY = maxY;
	
	siteidx = 0;
	voronoi(triangulate);

	return true;
}