Exemple #1
0
        public List <ProxListPosition> GetNeighbors(
            ProxListPosition item
            )
        {
            var x      = item.box.X;
            var y      = item.box.Y;
            var result = new List <ProxListPosition>();

            var x_mod = 1;
            var y_mod = 1;

            if (item.Position.X < 0.5f)
            {
                x_mod = -1;
            }
            if (item.Position.Y < 0.5f)
            {
                y_mod = -1;
            }
            TryAddRange(result, x, y);
            TryAddRange(result, x + x_mod, y);
            TryAddRange(result, x, y + y_mod);
            TryAddRange(result, x + x_mod, y + y_mod);

            result.Remove(item);
            return(result);
        }
Exemple #2
0
 public void Remove(ProxListPosition item)
 {
     if (!_groups[item.box.X, item.box.Y].Remove(item))
     {
         throw new Exception("Failed to remove given item.");
     }
 }
Exemple #3
0
        internal Point AddToArray(ProxListPosition item, Point2 position)
        {
            var new_box = GetBox(position);

            _groups[new_box.X, new_box.Y].Add(item);
            return(new_box);
        }
Exemple #4
0
        internal Point UpdateBox(ProxListPosition item, Point2 position)
        {
            var new_box = GetBox(position);

            if (new_box == item.box)
            {
                return(item.box);
            }

            if (!_groups[item.box.X, item.box.Y].Remove(item))
            {
                throw new Exception("Error updating position.");
            }

            _groups[new_box.X, new_box.Y].Add(item);

            return(new_box);
        }