public P()
 {
     GridIndex = new GridIndex();
 }
Ejemplo n.º 2
0
        // Single detect
        // 20 nearest boxes
        public List<IP> GetGridNeighborContent(IP p)
        {
            var i = p.GridIndex;

            // nearest neighbor
            var n = new GridIndex { X = i.X, Y = i.Y - 1 };
            var ne = new GridIndex { X = i.X + 1, Y = i.Y - 1 };
            var e = new GridIndex { X = i.X + 1, Y = i.Y };
            var se = new GridIndex { X = i.X + 1, Y = i.Y + 1 };
            var s = new GridIndex { X = i.X, Y = i.Y + 1 };
            var sw = new GridIndex { X = i.X - 1, Y = i.Y + 1 };
            var w = new GridIndex { X = i.X - 1, Y = i.Y };
            var nw = new GridIndex { X = i.X - 1, Y = i.Y - 1 };

            // outer north
            var nnw = new GridIndex { X = i.X - 1, Y = i.Y - 2 };
            var nn = new GridIndex { X = i.X, Y = i.Y - 2 };
            var nne = new GridIndex { X = i.X + 1, Y = i.Y - 2 };

            // outer east
            var nee = new GridIndex { X = i.X + 2, Y = i.Y - 1 };
            var ee = new GridIndex { X = i.X + 2, Y = i.Y };
            var see = new GridIndex { X = i.X + 2, Y = i.Y + 1 };

            // outer south
            var sse = new GridIndex { X = i.X + 1, Y = i.Y + 2 };
            var ss = new GridIndex { X = i.X, Y = i.Y + 2 };
            var ssw = new GridIndex { X = i.X - 1, Y = i.Y + 2 };

            // outer west
            var sww = new GridIndex { X = i.X - 2, Y = i.Y - 1 };
            var ww = new GridIndex { X = i.X - 2, Y = i.Y };
            var nww = new GridIndex { X = i.X - 2, Y = i.Y + 1 };

            var list = new List<IP>();
            GridIndex gi;
            if (IsValidGridIndex(gi = n)) list.AddRange(Grid.Get(gi));
            if (IsValidGridIndex(gi = ne)) list.AddRange(Grid.Get(gi));
            if (IsValidGridIndex(gi = e)) list.AddRange(Grid.Get(gi));
            if (IsValidGridIndex(gi = se)) list.AddRange(Grid.Get(gi));
            if (IsValidGridIndex(gi = s)) list.AddRange(Grid.Get(gi));
            if (IsValidGridIndex(gi = sw)) list.AddRange(Grid.Get(gi));
            if (IsValidGridIndex(gi = w)) list.AddRange(Grid.Get(gi));
            if (IsValidGridIndex(gi = nw)) list.AddRange(Grid.Get(gi));

            if (IsValidGridIndex(gi = nnw)) list.AddRange(Grid.Get(gi));
            if (IsValidGridIndex(gi = nn)) list.AddRange(Grid.Get(gi));
            if (IsValidGridIndex(gi = nne)) list.AddRange(Grid.Get(gi));

            if (IsValidGridIndex(gi = nee)) list.AddRange(Grid.Get(gi));
            if (IsValidGridIndex(gi = ee)) list.AddRange(Grid.Get(gi));
            if (IsValidGridIndex(gi = see)) list.AddRange(Grid.Get(gi));

            if (IsValidGridIndex(gi = sse)) list.AddRange(Grid.Get(gi));
            if (IsValidGridIndex(gi = ss)) list.AddRange(Grid.Get(gi));
            if (IsValidGridIndex(gi = ssw)) list.AddRange(Grid.Get(gi));

            if (IsValidGridIndex(gi = sww)) list.AddRange(Grid.Get(gi));
            if (IsValidGridIndex(gi = ww)) list.AddRange(Grid.Get(gi));
            if (IsValidGridIndex(gi = nww)) list.AddRange(Grid.Get(gi));

            return list;
        }
Ejemplo n.º 3
0
 bool IsValidGridIndex(GridIndex i)
 {
     if (i.X < 0 || i.X >= Grid.X) return false;
     if (i.Y < 0 || i.Y >= Grid.Y) return false;
     return true;
 }
Ejemplo n.º 4
0
 public P()
 {
     Uid       = ++_counter;
     GridIndex = new GridIndex();
 }
Ejemplo n.º 5
0
 public P()
 {
     Uid = ++_counter;
     GridIndex = new GridIndex();
 }
Ejemplo n.º 6
0
 public MySet<IP> Get(GridIndex i)
 {
     return Get(i.X, i.Y);
 }