Ejemplo n.º 1
0
 /* Assigns the following node to either home or destination
  * depending on what was previously assigned
  */
 public void AssignNode(Node n)
 {
     if (n.Equals(destination))
     {
         destination = null;
         home        = n;
     }
     else if (home == null)
     {
         home = n;
     }
     else if (destination == null)
     {
         destination = n;
     }
     else
     {
         Node tmp = destination;
         destination = n;
         home        = tmp;
     }
 }
Ejemplo n.º 2
0
        /* Assigns the following node to either home or destination
         * depending on what was previously assigned
         */
        public void AssignNode(Node n)
        {
            if(n.Equals(destination))
            {
                destination = null;
                home = n;
            }
            else if(home == null)
            {
                home = n;
            }
            else if(destination == null)
            {
                destination = n;
            }
            else
            {

                Node tmp = destination;
                destination = n;
                home = tmp;
            }
        }
Ejemplo n.º 3
0
        /* 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);
        }
Ejemplo n.º 4
0
        /* Pops a node from the PQ and checks whether it is
         * the destination node or was the last node in the PQ
         * and terminates the animation if necessary.  Colors
         * popNode and its incoming edge as appropriate.
         */
        private void step1()
        {
            if(!pq.Contains(graph.Home) && !popped.Contains(graph.Home))
            {
                graph.Home.Distance = 0;
                pq.Add(graph.Home);
            }
            updateText();
            if(pq.Count <= 0)
            {
                stepCount = -1;
                finalize(false);
                return;
            }
            popNode = pq.Pop() as Node;
            popNode.Color = POPPED_N;

            if(incomingEdge[popNode] != null)
                ((Edge)incomingEdge[popNode]).Color = POPPED_E;

            popped.Add(popNode);
            if(popNode.Equals(graph.Destination))
            {
                stepCount = -1;
                finalize(true);
                return;
            }
            stepCount = 1;
        }
Ejemplo n.º 5
0
 //Get the node attached to Edge e that isn't Node n
 public static Node GetOther(Node n, Edge e)
 {
     if(n == null || !n.Edges.Contains(e)) return null;
     return (n.Equals(e.NodeB)) ? e.NodeA : e.NodeB;
 }
Ejemplo n.º 6
0
 private void RemoveNode(Node dead)
 {
     if(dead.Equals(home)) home = null;
     if(dead.Equals(destination)) destination = null;
     while(dead.Edges.Length()>0)
     {
         Edge e = dead.Edges[dead.Edges.Length()-1];
         RemoveEdge(e);
     }
     nodes.Remove(dead);
     dead.Stroke.Ink.DeleteStroke(dead.Stroke);
 }