private void AddTile(CustomTile tile, int currentDepth, ref BoundingBox box) { BoundingBox = box; if (currentDepth >= MaxDepth) { if (Tiles == null) { Tiles = new List <CustomTile>(); } Tiles.Add(tile); } else { var dividedBoxes = DivideBoundingBox(ref box, currentDepth); var leftBoundingBox = dividedBoxes.Item1; var rightBoundingBox = dividedBoxes.Item2; var leftContainment = leftBoundingBox.Contains(tile.BoundingBox); var rightContainment = rightBoundingBox.Contains(tile.BoundingBox); if (leftContainment == ContainmentType.Contains || leftContainment == ContainmentType.Intersects) { if (Left == null) { Left = new IntersectionCheckNode(); } Left.AddTile(tile, currentDepth + 1, ref leftBoundingBox); } if (rightContainment == ContainmentType.Contains || rightContainment == ContainmentType.Intersects) { if (Right == null) { Right = new IntersectionCheckNode(); } Right.AddTile(tile, currentDepth + 1, ref rightBoundingBox); } } }