private static void SewBorder(Voronoi graph) { var farSide = (int)(graph.PlotBounds.width + graph.PlotBounds.x); var borderSites = graph.SitesIndexedByLocation.Values.Where(s => s.IsBorderedOnSeamSite); foreach (var s in borderSites) { var p = new Point(farSide, (int)s.y); var distances = new Dictionary <Site, int>(); var sites = graph.SitesIndexedByLocation.Where(st => st.Key.x > farSide - 150); foreach (var site in sites) { distances.Add(site.Value, Mathf.RoundToInt(Boundary.DistanceBetween(new Point(p.x, s.Coord.y), new Point(site.Key.x, site.Key.y)))); } // Get the closest distance pair. var d = distances.OrderBy(kvp => kvp.Value).First(); s.FalseNeighbours.Add(d.Key); d.Key.FalseNeighbours.Add(s); } }