public SpatiallyPartitioned(int width, int height, int binSize) { this.binSize = binSize; rows = Exts.IntegerDivisionRoundingAwayFromZero(height, binSize); cols = Exts.IntegerDivisionRoundingAwayFromZero(width, binSize); itemBoundsBins = Exts.MakeArray(rows * cols, _ => new Dictionary <T, Rectangle>()); }
/// <summary> /// /// </summary> /// <param name="bounds"></param> /// <param name="minRow"></param> /// <param name="maxRow"></param> /// <param name="minCol"></param> /// <param name="maxCol"></param> void BoundsToBinRowsAndCols(Rectangle bounds, out int minRow, out int maxRow, out int minCol, out int maxCol) { var top = Math.Min(bounds.Top, bounds.Bottom); var bottom = Math.Max(bounds.Top, bounds.Bottom); var left = Math.Min(bounds.Left, bounds.Right); var right = Math.Max(bounds.Left, bounds.Right); minRow = Math.Max(0, top / binSize); minCol = Math.Max(0, left / binSize); maxRow = Math.Min(rows, Exts.IntegerDivisionRoundingAwayFromZero(bottom, binSize)); maxCol = Math.Min(cols, Exts.IntegerDivisionRoundingAwayFromZero(right, binSize)); }