Exemple #1
0
        public static void CreateConstellations(IList <Point> points)
        {
            foreach (var p in points)
            {
                var newConstellation = new Constellation();
                newConstellation.AddPoint(p);
                Constellations.Add(newConstellation);
            }

            var continueUnion = true;

            while (continueUnion)
            {
                continueUnion = false;
                foreach (var c in Constellations.ToList())
                {
                    var remainingConstellation = new HashSet <Constellation>(Constellations);
                    foreach (var d in remainingConstellation)
                    {
                        if (c.ShouldUnion(d))
                        {
                            c.Union(d);
                            continueUnion = true;
                        }
                    }
                }
                Constellations = Constellations.Where(c => c.Points.Count > 0).ToHashSet();
            }
        }
Exemple #2
0
        public Constellation Union(Constellation otherConstellation)
        {
            foreach (var p in otherConstellation.Points)
            {
                Points.Add(p);
            }

            otherConstellation.Points.Clear();
            return(this);
        }
Exemple #3
0
        public bool ShouldUnion(Constellation otherConstellation)
        {
            var result = false;

            if (this == otherConstellation)
            {
                return(result);
            }

            foreach (var p in Points)
            {
                if (otherConstellation.Points.Any(q => q.Distance(p) <= 3))
                {
                    result = true;
                }
            }
            return(result);
        }
 public void Merge(Constellation other)
 {
     stars.AddRange(other.stars);
 }