/// <summary> /// Determines whether the specified index is within the bounds of the <see cref="IIndexingBounds{TIndex}"/>. /// </summary> /// <typeparam name="TIndex">The type of the index.</typeparam> /// <param name="bounded">The bounds to check against.</param> /// <param name="index">The index to check.</param> /// <returns> /// <c>true</c> if the index is within bounds; otherwise, <c>false</c>. /// </returns> public static bool IsIndexInBounds <TIndex>(this IIndexingBounds <TIndex> bounded, TIndex index) where TIndex : IIndex { Contracts.Requires.That(bounded != null); Contracts.Requires.That(index != null); Contracts.Requires.That(bounded.Rank == index.Rank); return(IndexUtilities.IsIn(index, bounded.LowerBounds, bounded.UpperBounds)); }
public static Index2D GetMiddleIndex(this IIndexingBounds <Index2D> bounds, bool roundUp = false) { Contracts.Requires.That(bounds != null); return(MiddleIndex.Get(bounds.LowerBounds, bounds.UpperBounds, roundUp)); }
/// <summary> /// Gets the index of the last slot of the specified dimension within the specified bounds. /// </summary> /// <param name="bounds">The bounds to check against.</param> /// <param name="axis">The axis of the dimension whose ending index needs to be determined.</param> /// <returns> /// The index of the last slot of the specified dimension. /// </returns> public static int GetUpperBound(this IIndexingBounds <Index2D> bounds, Axis2D axis) { Contracts.Requires.That(bounds != null); return(bounds.GetUpperBound((int)axis)); }
/// <summary> /// Determines whether the specified index is within bounds. /// </summary> /// <param name="bounds">The bounds to check against.</param> /// <param name="index">The index to check.</param> /// <returns> /// <c>true</c> if the index is within bounds; otherwise, <c>false</c>. /// </returns> public static bool IsIndexInBounds(this IIndexingBounds <Index2D> bounds, Index2D index) { Contracts.Requires.That(bounds != null); return(index.IsIn(bounds.LowerBounds, bounds.UpperBounds)); }
/// <summary> /// Gets a 32-bit integer that represents the length of the specified dimension of the bounds. /// </summary> /// <param name="bounds">The bounds to check against.</param> /// <param name="axis">The axis of the dimension whose length needs to be determined.</param> /// <returns> /// A 32-bit integer that represents the length of the specified dimension. /// </returns> public static int GetLength(this IIndexingBounds <Index1D> bounds, Axis1D axis) { Contracts.Requires.That(bounds != null); return(bounds.GetLength((int)axis)); }
public static void GetUpperBound <TIndex>(IIndexingBounds <TIndex> instance, int dimension) where TIndex : IIndex { Contracts.Requires.That(instance != null); Contracts.Requires.That(dimension.IsIn(Range.FromLength(instance.Rank))); }