Exemple #1
0
 static void FloodFillBlob(NMap map, NLocate loc, NLocateSet set, byte valid)
 {
     if (!map.WithIn(loc))
     {
         return;
     }
     if (map.GetBlock(loc.X, loc.Y) == valid)
     {
         map.SetBlock(loc.X, loc.Y, (byte)(255 - valid));
         set.Set.Add(loc);
         foreach (var l in loc.Direction4())
         {
             FloodFillBlob(map, l, set, valid);
         }
     }
 }
Exemple #2
0
        public static NBlob Find(NMap map, byte valid)
        {
            var res = new NBlob();
            var tmp = new NMap(map);

            for (int i = 0; i < tmp.DataSize(); i++)
            {
                if (tmp.GetBlock(i) == valid)
                {
                    var set = new NLocateSet();
                    FloodFillBlob(tmp, new NLocate(i % tmp.Width, i / tmp.Width), set, valid);
                    res.Blobs.Add(set);
                }
            }
            return(res);
        }
Exemple #3
0
        public double DistanceTo(NLocateSet set, out NLocate srcLoc, out NLocate dstLoc)
        {
            double min = double.MaxValue;

            srcLoc = new NLocate(0, 0);
            dstLoc = new NLocate(0, 0);
            foreach (var l in set.Set)
            {
                NLocate nearestLoc;
                var     dis = DistanceTo(l, out nearestLoc);
                if (dis < min)
                {
                    min    = dis;
                    srcLoc = nearestLoc;
                    dstLoc = l;
                }
            }
            return(min);
        }