public VoronoiCell[] GenerateTileCells(int internalCellsCount)
{
var mapWidth = TilesSize.x;
var mapHeight = TilesSize.y;
var cells = new Dictionary<FortuneVoronoi.Common.Point, VoronoiCell>();
var dx = mapWidth / HorBorderSitesCnt / Resolution;
var dy = mapHeight / VertBorderSitesCnt / Resolution;
var internalSites = SitesGridGenerator.GenerateInternalSites(HorBorderSitesCnt, VertBorderSitesCnt, Resolution, internalCellsCount,
(min, max) => new IntPoint(Random.Range(min,max), Random.Range(min,max)));
if (!CachedBorders.ContainsKey(TilesSize)) {
var borderSites = SitesGridGenerator.GenerateTileBorder(HorBorderSitesCnt, VertBorderSitesCnt, Resolution,
(min, max) => new IntPoint(Random.Range(min, max), Random.Range(min, max))); // (int)((min + max) * 0.5f)
CachedBorders.Add(TilesSize, borderSites);
}
foreach (var site in internalSites.Concat(CachedBorders[TilesSize]).Distinct()) {
var x = site.X * dx;
var y = site.Y * dy;
var v = new FortuneVoronoi.Common.Point(x,y);
cells.Add(v, new VoronoiCell{IsVisible = !site.IsBorder, Site = v});
}
var graph = Fortune.ComputeVoronoiGraph(cells);
return cells.Values.Where(c => c.IsVisible && c.IsClosed).ToArray();
}