Esempio n. 1
0
            private IEnumerable <LocationSet> getCurrentLocationSets(ILayoutAccess layout)
            {
                HashSet <Location> locs = new HashSet <Location>();

                foreach (WireSegment w in layout.Wires)
                {
                    locs.Add(w.End0);
                    locs.Add(w.End1);
                }
                foreach (Component c in layout.Components)
                {
                    Location cloc = c.GetLocation(layout);
                    foreach (ConnectionPoint p in c.Connections)
                    {
                        locs.Add(cloc.Translate(p.Dx, p.Dy));
                    }
                }

                UnionFind <Location> allNodes = new UnionFind <Location>(locs);

                foreach (WireSegment w in layout.Wires)
                {
                    UnionFindNode <Location> e0 = allNodes[w.End0];
                    UnionFindNode <Location> e1 = allNodes[w.End1];
                    e0.Unite(e1);
                }

                IEnumerable <UnionFindNode <Location> > roots = allNodes.Roots;
                List <LocationSet> result = new List <LocationSet>();

                foreach (UnionFindNode <Location> root in roots)
                {
                    IEnumerable <UnionFindNode <Location> > rootMembers = root.GetSetMembers();
                    List <Location> setMembers = new List <Location>();
                    foreach (UnionFindNode <Location> n in rootMembers)
                    {
                        setMembers.Add(n.Value);
                    }
                    result.Add(new LocationSet(setMembers));
                }
                return(result);
            }