/// <summary> /// Finds the specified point. /// </summary> /// <param name="point">The point.</param> /// <returns>JGVertex.</returns> public JGVertex Find(UV point) { JGVertex vertex = null; this.dict.TryGetValue(point.GetHashCode(), out vertex); return(vertex); }
public override bool Equals(object obj) { JGVertex v = obj as JGVertex; if (v == null) { return(false); } return(this.Point == v.Point); }
/// <summary> /// Initializes a new instance of the <see cref="JGGraph"/> class. /// </summary> /// <param name="Vertexes">The vertexes.</param> public JGGraph(HashSet <UV> Vertexes) { Vertices = new HashSet <JGVertex>(); dict = new Dictionary <int, JGVertex>(); foreach (UV item in Vertexes) { JGVertex v = new JGVertex(item); this.Vertices.Add(v); this.dict.Add(item.GetHashCode(), v); } }
/// <summary> /// Adds the connection. /// </summary> /// <param name="a">a.</param> /// <param name="b">The b.</param> public void AddConnection(UV a, UV b) { JGVertex A = null; JGVertex B = null; dict.TryGetValue(a.GetHashCode(), out A); dict.TryGetValue(b.GetHashCode(), out B); if (A != null && B != null) { A.AddToConnections(B); B.AddToConnections(A); } }
/// <summary> /// Adds the connection. /// </summary> /// <param name="edge">The edge.</param> public void AddConnection(JGEdge edge) { JGVertex vertex1 = null; dict.TryGetValue(edge.P1.GetHashCode(), out vertex1); JGVertex vertex2 = null; dict.TryGetValue(edge.P2.GetHashCode(), out vertex2); if (vertex1 != null && vertex2 != null) { vertex1.Connections.Add(vertex2); vertex2.Connections.Add(vertex1); } }
/// <summary> /// Converts the graph to a list of edges. /// </summary> /// <returns>List<JGEdge>.</returns> public List <JGEdge> ToEdges() { List <JGEdge> edges = new List <JGEdge>(); JGGraph g = this.Copy(); while (g.Vertices.Count != 0) { JGVertex v = g.Vertices.FirstOrDefault <JGVertex>(); foreach (JGVertex item in v.Connections) { if (g.Vertices.Contains(item)) { edges.Add(new JGEdge(item.Point, v.Point)); } } g.Vertices.Remove(v); } g = null; return(edges); }
/// <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); }
/// <summary> /// Adds a vertex. /// </summary> /// <param name="vertex">The vertex.</param> public void AddVertex(JGVertex vertex) { dict.Add(vertex.GetHashCode(), vertex); this.Vertices.Add(vertex); }
/// <summary> /// Adds to connections. /// </summary> /// <param name="newVertex">The new vertex.</param> public void AddToConnections(JGVertex newVertex) { this.Connections.Add(newVertex); }