public Graph(Nodes n, Edges e) { nodes = n; edges = e; home = null; destination = null; }
public DijkstraAnimation(Canvas c) : base() { popped = new Nodes(); pushing = new Nodes(); incomingEdge = new Hashtable(); proposedWeight = new Hashtable(); pq = new BinaryPriorityQueue(Node.sortAscending()); graph = new Graph(); //empty graph until initialized. this.c = c; t = new Thread(new ThreadStart(Run)); }
//Get the nodes corresponding to the following strokes public Nodes getNodes(Strokes strokes) { Nodes found = new Nodes(); for(int i=0; i<strokes.Count; i++) { Node a = getNode(strokes[i]); if(a != null) { found.Add(a); } } return found; }
/* Determines whether the following stroke could be interpreted as * an edge (or edges) and if so, returns all the consecutive nodes that the * stroke has gone through in order. */ public static Nodes ifEdgeGetNodes(Stroke s, Graph g) { Point[] sPoints = s.GetPoints(); Nodes strokeHitNodes = new Nodes(); Node prev = null; for(int i=0; i<sPoints.Length; i++) { for(int j=0; j<g.Nodes.Length(); j++) { Node n = g.Nodes[j]; Rectangle r = n.Stroke.GetBoundingBox(); if(s.HitTest(n.CenterPoint,Math.Max(r.Width/2, r.Height/2)) && r.Contains(sPoints[i]) && !n.Equals(prev)) { strokeHitNodes.Add(n); prev = n; break; } } } //If stroke hit one or less nodes, it is clearly not an edge. if(strokeHitNodes.Length() < 2) { return null; } return strokeHitNodes; }