Exemple #1
0
 private void Draw(Graphics graphics, NNodeX node, Pen pen)
 {
     if (node != null)
     {
         if (node.Point != null)
         {
             if (node.Parent != null)
             {
                 graphics.DrawLine(
                     pen,
                     node.Point.X,
                     node.Point.Y,
                     node.Parent.Point.X,
                     node.Parent.Point.Y);
                 Draw(graphics, node.Parent, pen);
             }
         }
     }
 }
Exemple #2
0
        private NNodeX Process(NPoint point)
        {
            using (MethodTracer tracer = new MethodTracer())
            {
                int           level      = 0;
                List <NNodeX> masterList = new List <NNodeX>();
                List <NNodeX> neighbours = new List <NNodeX>();
                List <NNodeX> tempList   = new List <NNodeX>();
                int           id         = PointToId(point);
                if (id < 0 || id >= allPoints.Count)
                {
                    return(null);
                }
                NNodeX startRoot = allPoints[id];
                startRoot.Level   = level;
                startRoot.Visited = true;
                List <NNodeX> currNodes = new List <NNodeX> {
                    startRoot
                };
                Connector.StartNode = startRoot;

                if (startRoot.Point.Equals(EndPoint))
                {
                    return(startRoot);
                }
                do
                {
                    level++;
                    neighbours.Clear();
                    foreach (NNodeX currNode in currNodes)
                    {
                        NNodeX node = null;

                        foreach (int x in currNode.Neighbors)
                        {
                            if (allPoints[x].Point.Equals(EndPoint))
                            {
                                node = allPoints[x];
                                break;
                            }
                        }

                        if (node != null)
                        {
                            node.Parent = currNode;
                            return(node);
                        }

                        foreach (int x in currNode.Neighbors)
                        {
                            NNodeX nChild = allPoints[x];
                            if (!nChild.Blocked && !nChild.Visited)
                            {
                                nChild.Visited = true;
                                nChild.Parent  = currNode;
                                neighbours.Add(nChild);
                            }
                        }
                    }
                    currNodes.Clear();
                    currNodes.AddRange(neighbours);
                } while (neighbours.Count > 0);

                return(null);
            }
        }