Esempio n. 1
0
        /// <summary>
        /// Copies this instance.
        /// </summary>
        /// <returns>JGGraph.</returns>
        public JGGraph Copy()
        {
            var graph = new JGGraph();

            foreach (JGVertex item in this.Vertices)
            {
                graph.AddVertex(item);
            }
            return(graph);
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a deep copy of this instance.
        /// </summary>
        /// <returns>JGGraph.</returns>
        public JGGraph DeepCopy()
        {
            JGGraph copied = new JGGraph();

            //copying vertices
            foreach (JGVertex item in this.Vertices)
            {
                JGVertex newJGV = new JGVertex(item.Point.Copy());
                copied.AddVertex(newJGV);
            }
            //copying connections
            foreach (JGVertex item in this.Vertices)
            {
                JGVertex current = copied.Find(item.Point);
                foreach (JGVertex connection in item.Connections)
                {
                    JGVertex next = copied.Find(connection.Point);
                    current.AddToConnections(next);
                    next.AddToConnections(current);
                }
            }
            return(copied);
        }