Exemple #1
0
        //Checks for a connection to the left side of the gate
        public bool ConnectsToLeftWireGroup(WireGroup group)
        {
            int    size      = GetSize();
            Coords baseCoord = new Coords(Symbol.Location);

            if (size > 2)
            {
                for (int i = 0; i < size; i++)
                {
                    if (group.coords.Exists(x => x.x == baseCoord.x + LeftPinOffset[size].OffsetX && x.y == baseCoord.y + LeftPinOffset[size].OffsetY + i))
                    {
                        return(true);
                    }
                }
            }
            else if (size == 2)
            {
                return(group.coords.Exists(x => x.x == baseCoord.x + LeftPinOffset[size].OffsetX && x.y == baseCoord.y + LeftPinOffset[size].OffsetY) ||
                       group.coords.Exists(x => x.x == baseCoord.x + LeftPinOffset[size].OffsetX && x.y == baseCoord.y + LeftPinOffset[size].OffsetY + 2));
            }
            else
            {
                return(group.coords.Exists(x => x.x == baseCoord.x + LeftPinOffset[1].OffsetX && x.y == baseCoord.y + LeftPinOffset[1].OffsetY));
            }
            return(false);
        }
Exemple #2
0
        //Checks for a connection to the output pin of the gate
        public bool ConnectsToRightWireGroup(WireGroup group)
        {
            Coords baseCoord = new Coords(Symbol.Location);

            baseCoord.x = baseCoord.x + RightPinOffset[GetSize()].OffsetX;
            baseCoord.y = baseCoord.y + RightPinOffset[GetSize()].OffsetY;

            return(group.coords.Exists(x => x.x == baseCoord.x && x.y == baseCoord.y));
        }
 public bool Intersection(WireGroup group)
 {
     for (int i = 0; i < group.wires.Count; i++)
     {
         if (ContainsConnectingWire(group.wires[i]))
         {
             return(true);
         }
     }
     return(false);
 }
        public static WireGroup Merge(WireGroup a, WireGroup b)
        {
            List <Wire> newWireList = new List <Wire>();

            newWireList.AddRange(a.wires);
            foreach (var wire in b.wires)
            {
                if (!newWireList.Exists(x => x.Point1 == wire.Point1 && x.Point2 == wire.Point2))
                {
                    newWireList.Add(wire);
                }
            }
            a.wires = newWireList;
            return(a);
        }
        /// <summary>
        /// This method iterates through all wires and groups them into a wire cluster.
        /// This allows us to see all objects connected to a specific wire network.
        /// </summary>
        /// <param name="wires">All wires you want to group</param>
        /// <returns>A set of grouped wires</returns>
        public static List <WireGroup> CombineWires(List <Wire> wires)
        {
            List <WireGroup> groups = new List <WireGroup>();

            //Create an initial group
            groups.Add(new WireGroup(wires[0]));
            //Create a bool to detect if we found a group for the wire
            bool groupFound;

            for (int i = 1; i < wires.Count; i++)
            {
                groupFound = false;
                foreach (var group in groups)
                {
                    if (group.ContainsConnectingWire(wires[i]))//See if we can add the current wire to an existing group
                    {
                        group.Add(wires[i]);
                        groupFound = true;
                        break;
                    }
                }
                if (!groupFound)//If no group is found create a new group
                {
                    groups.Add(new WireGroup(wires[i]));
                }
            }

            List <WireGroup> newGroups = new List <WireGroup>();

            if (groups.Count > 1)
            {
                bool groupMerged;
                int  jStart = 1;
                while (true)
                {
                    groupMerged = false;
                    for (int i = 0; i < groups.Count - 1; i++)
                    {
                        for (int j = jStart; j < groups.Count; j++)
                        {
                            if (groups[i].Intersection(groups[j]))
                            {
                                groups[i] = WireGroup.Merge(groups[i], groups[j]); //Merge the groups into the first element
                                groups.RemoveAt(j);                                //Remove the group that was merged
                                groupMerged = true;
                            }
                        }
                        if (groupMerged)//If we have merged a group we need to restart
                        {
                            break;
                        }
                        jStart++;
                    }
                    if (!groupMerged)//If we have not merged a group then all groups have been merged
                    {
                        break;
                    }
                }
            }
            foreach (var group in groups)//Extract each coordinate in the group.
            {
                group.Process();
            }
            return(groups);
        }