Пример #1
0
    /// <summary>
    /// Gets an enumerable sequence of all the indices of an array.
    /// </summary>
    /// <typeparam name="T">The type of values stored in the array.</typeparam>
    /// <param name="array">The array.</param>
    /// <returns>The enumerable sequence of indices.</returns>
    public static IEnumerable <Index4D> GetIndices <T>(this T[,,,] array)
    {
        Contracts.Requires.That(array != null);

        foreach (var index in Index.Range(array.GetLowerBounds(), array.GetDimensions()))
        {
            yield return(index);
        }
    }
Пример #2
0
    /// <summary>
    /// Gets an enumerable sequence of all the indices along with their associated values of an array.
    /// </summary>
    /// <typeparam name="T">The type of values stored in the array.</typeparam>
    /// <param name="array">The array.</param>
    /// <returns>The enumerable sequence of indices paired with their values.</returns>
    public static IEnumerable <KeyValuePair <Index4D, T> > GetIndexValuePairs <T>(this T[,,,] array)
    {
        Contracts.Requires.That(array != null);

        foreach (var index in Index.Range(array.GetLowerBounds(), array.GetDimensions()))
        {
            yield return(new KeyValuePair <Index4D, T>(index, array[index.X, index.Y, index.Z, index.W]));
        }
    }
Пример #3
0
    /// <summary>
    /// Determines whether the specified index is valid to use with this array's indexer.
    /// </summary>
    /// <typeparam name="T">The type of values stored in the array.</typeparam>
    /// <param name="array">The array.</param>
    /// <param name="index">The index to check.</param>
    /// <returns>True if the index is valid to use, otherwise false.</returns>
    public static bool IsIndexValid <T>(this T[,,,] array, Index4D index)
    {
        Contracts.Requires.That(array != null);

        return(index.IsIn(array.GetLowerBounds(), array.GetUpperBounds()));
    }
Пример #4
0
    public static Index4D GetMiddleIndex <T>(this T[,,,] array, bool roundUp = false)
    {
        Contracts.Requires.That(array != null);

        return(MiddleIndex.Get(array.GetLowerBounds(), array.GetUpperBounds(), roundUp));
    }