Exemplo n.º 1
0
        public static Voronoi Relax(Voronoi voronoi, List <Vector2> toRelax = null)
        {
            var regions = voronoi.Partitioning();

            var points = Enumerable.Except <Vector2> (voronoi.Points, voronoi.Frame).ToList();

            toRelax = toRelax ?? voronoi.Points;

            foreach (var region in regions)
            {
                if (toRelax.Contains(region.Seed))
                {
                    points.Remove(region.Seed);
                    points.Add(region.Center());
                }
            }
            return(Build(points));
        }
Exemplo n.º 2
0
        public static Voronoi Build(List <Vector2> points)
        {
            var minx = points.Min(p => p.x);
            var miny = points.Min(p => p.y);
            var maxx = points.Max(p => p.x);
            var maxy = points.Max(p => p.y);

            var dx = (maxx - minx) * 0.5f;
            var dy = (maxy - miny) * 0.5f;

            var voronoi = new Voronoi(minx - dx / 2, miny - dy / 2, maxx + dx / 2, maxy + dy / 2);

            foreach (var point in points)
            {
                voronoi.AddPoint(point);
            }

            return(voronoi);
        }