public void update(MouseEventArgs e)
        {
            var g = pictureBox1.CreateGraphics();

            if (clr > W8interval * 2)
            {
                if (ImageMatrix != null)
                {
                    var mouseNode = Helper.Flatten(e.X, e.Y, ImageOperations.GetWidth(ImageMatrix));

                    if (curr_source != -1 && Prev_mouse_pos != mouseNode)
                    {
                        Prev_mouse_pos = mouseNode;
                        if (Helper.IN_Boundary(mouseNode, SB, ImageOperations.GetWidth(ImageMatrix)))
                        {
                            int Segment_mouse = Helper.crosspond(mouseNode, SB,
                                                                 ImageOperations.GetWidth(ImageMatrix), ImageOperations.GetWidth(Square_segment));
                            List <Point> segmentpath = new List <Point>();
                            segmentpath = ShortestPath_Operations.Backtracking(parent_list, Segment_mouse, ImageOperations.GetWidth(Square_segment));
                            List <Point> Curpath = Helper.crosspond(segmentpath, SB);
                            curr_path = Curpath.ToArray();
                            if (AutoAnchor_WORK)
                            {
                                double freq = (double)frequancy / 1000;
                                Autoancor.Update(Curpath, freq);
                                List <Point> cooledpath = Autoancor.anchor_path();
                                if (cooledpath.Count > 0)
                                {
                                    Point anchor = cooledpath[cooledpath.Count - 1];
                                    AnchorPts.Add(anchor);
                                    curr_source = Helper.Flatten(anchor.X, anchor.Y, ImageOperations.GetWidth(ImageMatrix));
                                    //curr_path = cooledpath.ToArray();
                                    Helper.AppendToList <Point>(Mainselction, cooledpath);
                                    SB = new Boundary();
                                    SB = ShortestPath_Operations.Square_Boundary(curr_source,
                                                                                 ImageOperations.GetWidth(ImageMatrix) - 1, ImageOperations.GetHeight(ImageMatrix) - 1);
                                    //make a square segment
                                    Square_segment = Helper.COPY_Segment(ImageMatrix, SB);
                                    // currsrc in segment
                                    int newsrc = Helper.crosspond(curr_source, SB, ImageOperations.GetWidth(ImageMatrix), ImageOperations.GetWidth(Square_segment));
                                    parent_list = ShortestPath_Operations.Dijkstra(newsrc, Square_segment);
                                    Autoancor.reset();
                                }
                            }
                        }
                        else
                        {
                            curr_path = ShortestPath_Operations.GenerateShortestPath(curr_source, mouseNode, ImageMatrix).ToArray();
                        }
                    }
                }
                clr = 0.0f;
            }
            if (clr > W8interval)
            {
                pictureBox1.Refresh();
                g.Dispose();
            }
            clr += .019f;
        }
 private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
 {
     if (pictureBox1.Image != null)
     {
         var clicked_node = Helper.Flatten(e.X, e.Y, ImageOperations.GetWidth(ImageMatrix));
         if (curr_source != clicked_node)
         {
             if (curr_source == -1) // in the first click save frist clicked anchor
             {
                 main_source = clicked_node;
             }
             else
             {
                 Helper.AppendToList <Point>(Mainselction, curr_path);
             }
             curr_source = clicked_node;
             AnchorPts.Add(e.Location);
             SB = new Boundary();
             SB = ShortestPath_Operations.Square_Boundary(curr_source,
                                                          ImageOperations.GetWidth(ImageMatrix) - 1, ImageOperations.GetHeight(ImageMatrix) - 1);
             //make a square segment
             Square_segment = Helper.COPY_Segment(ImageMatrix, SB);
             // currsrc in segment
             int newsrc = Helper.crosspond(curr_source, SB, ImageOperations.GetWidth(ImageMatrix), ImageOperations.GetWidth(Square_segment));
             parent_list = ShortestPath_Operations.Dijkstra(newsrc, Square_segment);
             Autoancor.reset();
         }
     }
 }