Exemple #1
0
        /*
         * FIXME: this algorithm shouldn't be recursive. -- andy 8 November 2007
         */
        static void FloodFill(Hashtable hash, int x, int y, CheckCallback ccb, Callback cb, object tag)
        {
            ArrayList al = hash[x] as ArrayList;

            if (al == null)
            {
                al = new ArrayList();
                al.Add(y);
                hash[x] = al;
            }
            else
            {
                if (al.Contains(y))
                {
                    return;
                }
                else
                {
                    al.Add(y);
                }
            }

            if (ccb(x, y, tag))
            {
                cb(x, y, tag);
                FloodFill(hash, x + 1, y, ccb, cb, tag);
                FloodFill(hash, x - 1, y, ccb, cb, tag);
                FloodFill(hash, x, y + 1, ccb, cb, tag);
                FloodFill(hash, x, y - 1, ccb, cb, tag);
            }
        }
Exemple #2
0
        public static void FloodFill(int x, int y, CheckCallback ccb, Callback cb, object tag)
        {
            Hashtable hash = new Hashtable();

            FloodFill(hash, x, y, ccb, cb, tag);
        }
Exemple #3
0
        /*
         * FIXME: this algorithm shouldn't be recursive. -- andy 8 November 2007
         */
        static void FloodFill(Hashtable hash, int x, int y, CheckCallback ccb, Callback cb, object tag)
        {
            //ArrayList al = hash[x] as ArrayList;
            //if (al == null) {
            //    al = new ArrayList();
            //    al.Add(y);
            //    hash[x] = al;
            //} else {
            //    if (al.Contains(y)) {
            //        return;
            //    } else {
            //        al.Add(y);
            //    }
            //}

            //if (ccb(x, y, tag)) {
            //    cb(x, y, tag);
            //    FloodFill(hash, x + 1, y, ccb, cb, tag);
            //    FloodFill(hash, x - 1, y, ccb, cb, tag);
            //    FloodFill(hash, x, y + 1, ccb, cb, tag);
            //    FloodFill(hash, x, y - 1, ccb, cb, tag);
            //}
        }
Exemple #4
0
 public static void FloodFill(int x, int y, CheckCallback ccb, Callback cb, object tag)
 {
     Queue<Point> todo = new Queue<Point>();
     Dictionary<Point,bool> map = new Dictionary<Point,bool>();
     todo.Enqueue(new Point(x,y));
     while (todo.Count > 0)
     {
         Point pt = todo.Dequeue();
         if(map.ContainsKey(pt)) continue;
         if (ccb(pt.X, pt.Y, tag))
         {
             cb(pt.X, pt.Y, tag);
             todo.Enqueue(new Point(pt.X + 1, pt.Y));
             todo.Enqueue(new Point(pt.X - 1, pt.Y));
             todo.Enqueue(new Point(pt.X, pt.Y + 1));
             todo.Enqueue(new Point(pt.X, pt.Y - 1));
         }
     }
 }
        /*
         * FIXME: this algorithm shouldn't be recursive. -- andy 8 November 2007
         */
        static void FloodFill(Hashtable hash, int x, int y, CheckCallback ccb, Callback cb, object tag)
        {
            ArrayList al = hash[x] as ArrayList;
            if (al == null) {
                al = new ArrayList();
                al.Add(y);
                hash[x] = al;
            } else {
                if (al.Contains(y)) {
                    return;
                } else {
                    al.Add(y);
                }
            }

            if (ccb(x, y, tag)) {
                cb(x, y, tag);
                FloodFill(hash, x + 1, y, ccb, cb, tag);
                FloodFill(hash, x - 1, y, ccb, cb, tag);
                FloodFill(hash, x, y + 1, ccb, cb, tag);
                FloodFill(hash, x, y - 1, ccb, cb, tag);
            }
        }
 public static void FloodFill(int x, int y, CheckCallback ccb, Callback cb, object tag)
 {
     Hashtable hash = new Hashtable();
     FloodFill(hash, x, y, ccb, cb, tag);
 }