예제 #1
0
        /// <summary>
        /// Get a clone of this class but without any edges that appear in the input collection.
        /// </summary>
        /// <param name="excludeCollection">Collection of edges to exclude from this one.</param>
        /// <returns>This collection but without any edges that are in excludeCollection.</returns>
        public EdgeCollection <T> GetExcludedCollection(EdgeCollection <T> excludeCollection)
        {
            if (excludeCollection is null)
            {
                throw new ArgumentNullException(nameof(excludeCollection));
            }

            EdgeCollection <T> cloneCollection = this.Clone();
            var removeCollection = new List <T>();

            foreach (T excludeEdge in excludeCollection)
            {
                foreach (T existingEdge in this)
                {
                    if (existingEdge.a == excludeEdge.a && existingEdge.b == excludeEdge.b ||
                        existingEdge.b == excludeEdge.a && existingEdge.a == excludeEdge.b)
                    {
                        removeCollection.Add(existingEdge);
                    }
                }
                //cloneCollection.Remove(edge);
            }
            foreach (T removeEdge in removeCollection)
            {
                cloneCollection.Remove(removeEdge);
            }
            return(cloneCollection);
        }
예제 #2
0
        /// <summary>
        /// Returns a set of this EdgeCollection, AKA without duplicate edges.
        /// </summary>
        /// <returns>The same EdgeCollection but without duplicates</returns>
        public EdgeCollection <T> GetSetCollection()
        {
            var hashSet = new HashSet <T>();
            var edgeSet = new EdgeCollection <T>();

            foreach (T edge in this.Where(edge => !hashSet.Contains(edge)))
            {
                hashSet.Add(edge);
                edgeSet.Add(edge);
            }
            return(edgeSet);
        }
예제 #3
0
        /// <summary>
        /// Simplifies outer perimeter using EdgeCollection's simplification algorithm to
        /// merge collinear segments together.
        /// </summary>
        /// <param name="outerPerimUnsimplified"></param>
        /// <returns></returns>
        private static Vector2[] _SimplifyOuterPerim(Vector2[] outerPerimUnsimplified)
        {
            var edgeCollection = new EdgeCollection <PolyEdge>();

            for (int i = 0; i < outerPerimUnsimplified.Length; i++)
            {
                Vector2 thisVertex = outerPerimUnsimplified[i];
                Vector2 nextVertex = outerPerimUnsimplified[(i + 1) % outerPerimUnsimplified.Length];
                if (thisVertex == nextVertex)
                {
                    continue;
                }
                var polyEdge = new PolyEdge(thisVertex, nextVertex);
                edgeCollection.Add(polyEdge);
            }
            List <Vector2> simplified = edgeCollection.GetSimplifiedPerim();

            return(simplified.ToArray());
        }