示例#1
0
        /// <summary>
        /// Given an EdgeCollection with a bunch of edges:
        ///     1. Grabs the outside perimeter formed by the available edges.
        ///        Edges not connected to this perimeter are left behind.
        ///     2. Out of the left behind edges, grabs a cycle that contains no non-perimeter edges within it and orders them.
        ///        Again, edges not connected to this group are left behind.
        ///     3. Repeat until all edges are ordered and split into their own connected groups.
        /// Returns the split and ordered edges in a List.
        /// </summary>
        /// <param name="originalEdgeColl">Collection of all edges in a TileMap, regardless of whether they are connected or not</param>
        /// <returns>A list of Edge Collections, all ordered, and all split into connected groups</returns>
        private static List <EdgeCollection <TileEdge> > _SplitEdgeColl(EdgeCollection <TileEdge> originalEdgeColl)
        {
            var splitEdgeColl = new List <EdgeCollection <TileEdge> >();
            EdgeCollection <TileEdge> cloneEdgeColl  = originalEdgeColl.Clone();
            EdgeCollection <TileEdge> outerEdgesColl = cloneEdgeColl.GetOuterClosedLoop(); //first pull the outer perim

            splitEdgeColl.Add(outerEdgesColl);
            cloneEdgeColl = cloneEdgeColl.GetExcludedCollection(outerEdgesColl);
            while (cloneEdgeColl.Count > 0)
            {
                List <EdgeCollection <TileEdge> > smallClosedLoops = cloneEdgeColl.GetSmallClosedLoops();
                foreach (EdgeCollection <TileEdge> smallClosedLoop in smallClosedLoops)
                {
                    splitEdgeColl.Add(smallClosedLoop);
                    cloneEdgeColl = cloneEdgeColl.GetExcludedCollection(smallClosedLoop);
                }
            }
            return(splitEdgeColl);
        }