public override bool Equals(object obj)
        {
            GraphVertex <K, T> objitem = obj as GraphVertex <K, T>;
            var otherval = objitem.Face;

            return(otherval.Equals(this.Face));
        }
        /// <summary>
        /// actually construct list of graph verts with stored faces and edges
        /// iterates dictionary of edges to faces and building graph
        /// </summary>
        /// <param name="faces"></param>
        /// <param name="edgeDict"></param>
        /// <returns></returns>
        public static List <GraphVertex <K, T> > GenGraph <T, K>(List <T> facelikes, Dictionary <K, List <T> > edgeDict)
            where K : IUnfoldableEdge
            where T : IUnfoldablePlanarFace <K>
        {
            List <GraphVertex <K, T> > graph = new List <GraphVertex <K, T> >();

            // first build the graph nodes, just referencing faces
            foreach (T face in facelikes)
            {
                var CurrentVertex = new GraphVertex <K, T>(face);
                graph.Add(CurrentVertex);
            }

            // then build edges, need to use edge dict to do this
            foreach (GraphVertex <K, T> vertex in graph)
            {
                T facelike = vertex.Face;
                foreach (K edgelike in facelike.EdgeLikeEntities)
                {
                    //var edgekey = new EdgeLikeEntity(edge);
                    // again we dont need to generate a new key with this wrapper - already stored on the face in this form

                    var edgekey = edgelike;

                    // find adjacent faces in the dict
                    var subfaces = edgeDict[edgekey];
                    // find the graph verts that represent these faces
                    var verts = GraphUtilities.FindNodesByMatchingFaces(graph, subfaces);
                    //remove dupe faces, not sure if these should really be removed
                    verts = verts.Distinct().ToList();
                    //need to remove self loops
                    //build list of toremove, then remove them
                    var toremove = new List <GraphVertex <K, T> >();
                    foreach (GraphVertex <K, T> testvert in verts)
                    {
                        if (testvert == vertex)
                        {
                            toremove.Add(testvert);
                        }
                    }
                    verts = verts.Except(toremove).ToList();


                    // these are the verts this edge connects
                    foreach (var VertToConnectTo in verts)
                    {
                        K   wrappedEdgeOnThisGraphEdge = GraphUtilities.FindRealEdgeByTwoFaces <T, K>(graph, subfaces, edgeDict);
                        var CurrentGraphEdge           = new GraphEdge <K, T>(wrappedEdgeOnThisGraphEdge, vertex, VertToConnectTo);
                        vertex.GraphEdges.Add(CurrentGraphEdge);
                    }
                }
            }
            return(graph);
        }
 public GraphEdge(K edge, GraphVertex <K, T> tail, GraphVertex <K, T> head)
 {
     Tail         = tail;
     Head         = head;
     GeometryEdge = edge;
 }
        // be careful here, modifying the verts may causing issues,
        // might be better to create new verts, or implement Icloneable


        public static List <GraphVertex <K, T> > BFS <K, T>(List <GraphVertex <K, T> > graph)
            where T : IUnfoldablePlanarFace <K>
            where K : IUnfoldableEdge
        {
            var graphToTraverse = graph;
            // this is a clone of the graph that we modify to store the tree edges on
            //var graphToTraverse = GraphUtilities.CloneGraph<K, T>(graph);
            // this is the final form of the graph, we can replace references to the graph edges with only tree edges
            // and treat this tree as a graph
            List <GraphVertex <K, T> > TreeTransformedToGraph;

            // now can start actually traversing the graph and building a tree.

            Queue <GraphVertex <K, T> > Q = new Queue <GraphVertex <K, T> >();


            foreach (var node in graphToTraverse)
            {
                if (node.Explored == false)
                {
                    GraphVertex <K, T> root = node;
                    root.FinishTime = 0;
                    root.Parent     = null;
                    Q.Enqueue(root);
                }
                while (Q.Count > 0)
                {
                    GraphVertex <K, T> CurrentVertex = Q.Dequeue();


                    foreach (GraphEdge <K, T> vedge in CurrentVertex.GraphEdges)
                    {
                        GraphVertex <K, T> V = vedge.Head;
                        if (V.Explored == false)
                        {
                            V.Explored   = true;
                            V.FinishTime = CurrentVertex.FinishTime + 1;
                            V.Parent     = CurrentVertex;

                            CurrentVertex.TreeEdges.Add(vedge);

                            Q.Enqueue(V);
                        }
                    }
                    // look at BFS implementation again - CLRS ? colors? I am mutating verts too many times?
                    // check how many times this loop is running with acounter
                    CurrentVertex.Explored = true;
                }
            }

            //TreeTransformedToGraph = GraphUtilities.CloneGraph<K, T>(graphToTraverse);

            // set the grap edges to the tree edges incase
            // we want to use general graph algos on the tree;

            /* foreach (var Vertex in graphToTraverse)
             * {
             *   Vertex.GraphEdges = Vertex.TreeEdges;
             *   Vertex.TreeEdges.Clear();
             *
             * }
             */
            return(graphToTraverse);
        }