public double Clash(IClashAble clashAble, Vector movement) { double bound = clashAble.BoundRadius; Vector checkFrom = FromBlockPosition(new Vector(clashAble.Position.x - bound + Math.Min(0, movement.x), clashAble.Position.y - bound + Math.Min(0, movement.y))); Vector checkTo = FromBlockPosition(new Vector(clashAble.Position.x + bound + Math.Max(0, movement.x), clashAble.Position.y + bound + Math.Max(0, movement.y))); double min = 1; for (int i = (int)Math.Max(0, checkFrom.y); i < Math.Min(blocks.GetLength(0), checkTo.y); ++i) { for (int j = (int)Math.Max(0, checkFrom.x); j < Math.Min(blocks.GetLength(1), checkTo.x); ++j) { if (blocks[i, j].Solid) { min = Math.Min(min, clashAble.Clash(blocks[i, j].body, movement)); } } } return(min); }