public FilmTile GetTile(Bounds2 <int> sampleBounds) { // Account for the radius of the filter var halfPixel = Vector2 <float> .One * 0.5f; var p0 = (sampleBounds.Min.ToFloat() - halfPixel - Filter.Radius).Ceiling().ToInt(); var p1 = (sampleBounds.Max.ToFloat() - halfPixel + Filter.Radius).Floor().ToInt() + Vector2 <int> .One; // Account for the overall image bounds var tilePixelBounds = Bounds2 <int> .Intersect(new Bounds2 <int>(p0, p1), croppedPixelsBounds); return(new FilmTile(tilePixelBounds, Filter, filterTable)); }
/// <summary> /// Returns a list of <see cref="Bounds2"/> objects which have the maximum extend given in /// <paramref name="tile"/>. The <paramref name="original"/> object will enclose the result. /// </summary> /// <param name="original">Original <see cref="Bounds2"/> object which should be splitted.</param> /// <param name="tile">Maximum extend of a single resulting <see cref="Bounds2"/> object.</param> /// <returns>List of <see cref="Bounds2"/> objects which have the maximum size defined in /// <paramref name="tile"/>. All objects fit inside the <paramref name="original"/> object.</returns> /// <remarks>The bound inside the <paramref name="tile"/> object must start at zero.</remarks> public static List <Bounds2> Split(Bounds2 original, Bounds2 tile) { if (original == null) { throw new ArgumentNullException("original"); } if (tile == null) { throw new ArgumentNullException("tile"); } if (tile.MinX != 0 || tile.MinY != 0) { throw new ArgumentException("The MinX and MinY property must be zero.", "tile"); } if (tile.DeltaX == 0 || tile.DeltaY == 0) { throw new ArgumentException("The given tile bound has no extent.", "tile"); } List <Bounds2> result = new List <Bounds2> (); double currentX = original.MinX; while (currentX < original.MaxX) { double currentY = original.MinY; while (currentY < original.MaxY) { tile.MoveTo(currentX, currentY); Bounds2 newTile = original.Intersect(tile); result.Add(newTile); currentY += tile.DeltaY; } currentX += tile.DeltaX; } return(result); }