/// <summary> /// Checks coordinates for over-/underflow and does the correction based on the given OutOfBoundsMode. /// </summary> /// <param name="index">The coordinate index.</param> /// <param name="count">The sample count.</param> /// <param name="handler">The handler.</param> /// <returns> /// A coordinate index that is surely between the bounds. /// </returns> public static int GetBoundsCheckedCoordinate(int index, int count, OutOfBoundsHandler handler) { #if !NET35 Contract.Requires(count > 0, "Number of samples must be above 0"); Contract.Requires(handler != null, "OutOfBounds handler missing"); #endif // check bounds var underflow = index < 0; var overflow = index >= count; if (!(overflow || underflow)) { return(index); } // execute handler return(handler(index, count, overflow, underflow)); }
/// <summary> /// Checks coordinates for over-/underflow and does the correction based on the given OutOfBoundsMode. /// </summary> /// <param name="index">The coordinate index.</param> /// <param name="count">The sample count.</param> /// <param name="handler">The handler.</param> /// <returns> /// A coordinate index that is surely between the bounds. /// </returns> public static int GetBoundsCheckedCoordinate(int index, int count, OutOfBoundsHandler handler) { #if !NET35 Contract.Requires(count > 0, "Number of samples must be above 0"); Contract.Requires(handler != null, "OutOfBounds handler missing"); #endif // check bounds var underflow = index < 0; var overflow = index >= count; if (!(overflow || underflow)) return (index); // execute handler return (handler(index, count, overflow, underflow)); }