예제 #1
0
        /// <summary>
        /// Inserts an object into a grid cell at the given index
        /// </summary>
        /// <param name="elt">The object to insert</param>
        /// <param name="xIdx">The column index of the cell</param>
        /// <param name="yIdx">The row index of the cell</param>
        private void InsertToCell(IGridElt elt, int xIdx, int yIdx)
        {
            LooseCell cell = rows[yIdx].cells[xIdx];

            //if the cell is empty, initialize the bounds to match the element
            if (cell.FirstElt == null)
            {
                cell.Push(elt);
                cell.lft = (int)elt.Xf;
                cell.btm = (int)elt.Yf;
                cell.rgt = cell.lft + elt.Width;
                cell.top = cell.btm + elt.Height;

                //insert into the tight cells it overlaps
                InsertToCoarseGrid(cell);
            }
            else    //otherwise, see if the bounds need to change to fit the element
            {
                cell.Push(elt);
                ExpandCell(cell, elt);
            }
        }
예제 #2
0
        private void RemoveFromCell(IGridElt obj, int xIdx, int yIdx)
        {
            LooseCell cell = rows[yIdx].cells[xIdx];

            IGridElt elt     = cell.FirstElt;
            IGridElt prevElt = null;

            while (elt.ID != obj.ID)
            {
                prevElt = elt;
                elt     = elt.NextElt;
            }

            if (prevElt == null)
            {
                cell.Pop();
            }
            else
            {
                prevElt.NextElt = elt.NextElt;
            }
        }