コード例 #1
0
        private static IEnumerable <Constellation> ReduceConstellations(List <Point> points)
        {
            // At the beginning, every points is a constellation
            Queue <Constellation> queue = new Queue <Constellation>();

            foreach (Point p in points)
            {
                queue.Enqueue(new Constellation()
                {
                    Points = new List <Point>()
                    {
                        p
                    }
                });
            }

            // Do search
            while (queue.Any())
            {
                // Get the first
                Constellation constellation = queue.Dequeue();

                // Find if belongs anywhere
                Constellation target = queue.FirstOrDefault(x => x.CanJoin(constellation));
                if (target != null)
                {
                    target.Join(constellation);
                }
                else
                {
                    yield return(constellation);
                }
            }
        }
コード例 #2
0
 public void Join(Constellation constellation2)
 {
     Points.AddRange(constellation2.Points);
 }
コード例 #3
0
 public bool CanJoin(Constellation constellation2)
 {
     return(Points.CartesianJoin(constellation2.Points).Any(x => Utilities.Distance(x.Item1, x.Item2) <= 3));
 }