// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // namespace ImageProcessor { using System; using System.Collections.Generic; /// /// Encapsulates a series of time saving extension methods to the interface. /// public static class EnumerableExtensions { /// /// Generates a sequence of integral numbers within a specified range. /// /// /// The start index, inclusive. /// /// /// The end index, exclusive. /// /// /// The incremental step. /// /// /// The that contains a range of sequential integral numbers. /// public static IEnumerable SteppedRange(int fromInclusive, int toExclusive, int step) { // Borrowed from Enumerable.Range long num = (fromInclusive + toExclusive) - 1L; if ((toExclusive < 0) || (num > 0x7fffffffL)) { throw new ArgumentOutOfRangeException(nameof(toExclusive)); } return RangeIterator(fromInclusive, i => i < toExclusive, step); } /// /// Generates a sequence of integral numbers within a specified range. /// /// /// The start index, inclusive. /// /// /// A method that has one parameter and returns a calculating the end index /// /// /// The incremental step. /// /// /// The that contains a range of sequential integral numbers. /// public static IEnumerable SteppedRange(int fromInclusive, Func toDelegate, int step) { return RangeIterator(fromInclusive, toDelegate, step); } /// /// Generates a sequence of integral numbers within a specified range. /// /// /// The start index, inclusive. /// /// /// A method that has one parameter and returns a calculating the end index /// /// /// The incremental step. /// /// /// The that contains a range of sequential integral numbers. /// private static IEnumerable RangeIterator(int fromInclusive, Func toDelegate, int step) { int i = fromInclusive; while (toDelegate(i)) { yield return i; i += step; } } } }