private Voronoi GetVoronoi(int width, int height, int sitecount, int seed, int smoothingFactor)
{
var sw = new Stopwatch();
sw.Start();
var points = new List <Vector2>();
Random.seed = seed;
for (int i = 0; i < sitecount; i++)
{
points.Add(new Vector2(
Random.Range(0f, width),
Random.Range(0f, height))
);
}
var v = new Voronoi(points, null, new Rect(0, 0, width, height));
for (int i = 0; i < smoothingFactor; i++)
{
points = new List <Vector2>();
foreach (var site in v.Sites())
{
//brnkhy - voices are telling me that, this should use circumference, not average
var sum = Vector2.zero;
var count = 0;
foreach (var r in site.edges)
{
if (r.leftVertex != null)
{
sum += r.leftVertex.Coord;
}
if (r.rightVertex != null)
{
sum += r.rightVertex.Coord;
}
count += 2;
}
points.Add(sum / count);
}
v = new Voronoi(points, null, new Rect(0, 0, width, height));
}
sw.Stop();
Debug.Log(string.Format("Voronoi generation took [{0}] milisecs with {1} smoothing iterations", sw.ElapsedMilliseconds, smoothingFactor));
return(v);
}