예제 #1
0
        /// <summary>
        /// Remove a UIBox from all the cells it currently intersects.  This is the opposite of PlaceUIBox()
        /// </summary>
        /// <param name="item">UIBox reference to remove</param>
        public void RemoveUIBox(UIBox item)
        {
            //Get the start and end positions
            int startCol = Utils.Clamp(0, this.cellNum, (int)Math.Floor((double)item.boundaries.X / this.cellWidth));
            int endCol   = Utils.Clamp(0, this.cellNum, (int)Math.Ceiling((double)(item.boundaries.X + item.boundaries.Width) / this.cellWidth));
            int startRow = Utils.Clamp(0, this.cellNum, (int)Math.Floor((double)item.boundaries.Y / this.cellHeight));
            int endRow   = Utils.Clamp(0, this.cellNum, (int)Math.Ceiling((double)(item.boundaries.Y + item.boundaries.Height) / this.cellHeight));

            //Loop through all sections that the object intersects with
            int h = startRow;

            do
            {
                int w = startCol;
                do
                {
                    //Remove this item from that cell's list
                    this.dataGrid[h][w].Remove(item);
                    w++;
                } while (w <= endCol);

                h++;
            } while (h <= endRow);
        }
예제 #2
0
        /// <summary>
        /// Take a UIBox and place it in all grid cells intersecting with it
        /// </summary>
        /// <param name="item">UIBox to place</param>
        public void PlaceUIBox(UIBox item)
        {
            //Get the start and end positions
            int startCol = Utils.Clamp(0, this.cellNum, (int)Math.Floor((double)item.boundaries.X / this.cellWidth));
            int endCol   = Utils.Clamp(0, this.cellNum, (int)Math.Ceiling((double)(item.boundaries.X + item.boundaries.Width) / this.cellWidth));
            int startRow = Utils.Clamp(0, this.cellNum, (int)Math.Floor((double)item.boundaries.Y / this.cellHeight));
            int endRow   = Utils.Clamp(0, this.cellNum, (int)Math.Ceiling((double)(item.boundaries.Y + item.boundaries.Height) / this.cellHeight));

            //Loop through all sections that the object intersects with.  Use a do/while loop in case the entire UIBox fits into the 0, 0 cell
            int h = startRow;

            do
            {
                int w = startCol;
                do
                {
                    //Add this item to that cell's list
                    this.dataGrid[h][w].Add(item);
                    w++;
                } while (w < endCol);

                h++;
            } while (h < endRow);
        }
예제 #3
0
 /// <summary>
 /// Swaps two items in a UIBox list
 /// </summary>
 /// <param name="arr">UIBox list with items to swap</param>
 /// <param name="targ">Index of the item to swap with dest</param>
 /// <param name="dest">Index of the item to swap with targ</param>
 public static void SwapUIBox(List <UI.UIBox> arr, int targ, int dest)
 {
     UI.UIBox temp = arr[dest];
     arr[dest] = arr[targ];
     arr[targ] = temp;
 }