public void MustBeLessThan_IsGreaterOrEqual_ThrowsNoException(int value, int max) { var exception = Assert.Throws <ArgumentOutOfRangeException>(() => { DebugGuard.MustBeLessThan(value, max, "myParamName"); }); Assert.Equal("myParamName", exception.ParamName); Assert.True(exception.Message.Contains($"Value must be less than {max}.")); }
/// <summary> /// Gets a reference to the element at the specified position. /// </summary> /// <param name="x">The x coordinate (row)</param> /// <param name="y">The y coordinate (position at row)</param> /// <returns>A reference to the element.</returns> public ref T this[int x, int y] { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { DebugGuard.MustBeLessThan(x, this.Width, nameof(x)); DebugGuard.MustBeLessThan(y, this.Height, nameof(y)); Span <T> span = this.Span; return(ref span[(this.Width * y) + x]);
/// <summary> /// Returns a reference to specified element of the buffer. /// </summary> /// <param name="index">The index</param> /// <returns>The reference to the specified element</returns> public ref T this[int index] { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { DebugGuard.MustBeLessThan(index, this.Length, nameof(index)); Span <T> span = this.Span; return(ref span[index]); } }
/// <summary> /// Gets a reference to the element at the specified position. /// </summary> /// <param name="x">The x coordinate (row)</param> /// <param name="y">The y coordinate (position at row)</param> /// <returns>A reference to the element.</returns> /// <exception cref="IndexOutOfRangeException">When index is out of range of the buffer.</exception> public ref T this[int x, int y] { [MethodImpl(InliningOptions.ShortMethod)] get { DebugGuard.MustBeGreaterThanOrEqualTo(x, 0, nameof(x)); DebugGuard.MustBeGreaterThanOrEqualTo(y, 0, nameof(y)); DebugGuard.MustBeLessThan(x, this.Width, nameof(x)); DebugGuard.MustBeLessThan(y, this.Height, nameof(y)); return(ref this.GetRowSpan(y)[x]); } }
internal bool DangerousTryGetPaddedRowSpan(int y, int padding, out Span <T> paddedSpan) { DebugGuard.MustBeGreaterThanOrEqualTo(y, 0, nameof(y)); DebugGuard.MustBeLessThan(y, this.Height, nameof(y)); int stride = this.Width + padding; Span <T> slice = this.FastMemoryGroup.GetRemainingSliceOfBuffer(y * (long)this.Width); if (slice.Length < stride) { paddedSpan = default; return(false); } paddedSpan = slice.Slice(0, stride); return(true); }
public void Update(byte[] buffer, int offset, int count) { DebugGuard.NotNull(buffer, nameof(buffer)); DebugGuard.MustBeGreaterThanOrEqualTo(offset, 0, nameof(offset)); DebugGuard.MustBeGreaterThanOrEqualTo(count, 0, nameof(count)); DebugGuard.MustBeLessThan(offset, buffer.Length, nameof(offset)); DebugGuard.MustBeLessThanOrEqualTo(offset + count, buffer.Length, nameof(count)); // (By Per Bothner) uint s1 = this.checksum & 0xFFFF; uint s2 = this.checksum >> 16; while (count > 0) { // We can defer the modulo operation: // s1 maximally grows from 65521 to 65521 + 255 * 3800 // s2 maximally grows by 3800 * median(s1) = 2090079800 < 2^31 int n = 3800; if (n > count) { n = count; } count -= n; while (--n >= 0) { s1 = s1 + (uint)(buffer[offset++] & 0xff); s2 = s2 + s1; } s1 %= Base; s2 %= Base; } this.checksum = (s2 << 16) | s1; }
internal Memory <T> GetSafeRowMemory(int y) { DebugGuard.MustBeGreaterThanOrEqualTo(y, 0, nameof(y)); DebugGuard.MustBeLessThan(y, this.Height, nameof(y)); return(this.FastMemoryGroup.View.GetBoundedMemorySlice(y * (long)this.Width, this.Width)); }
public void MustBeLessThan_IsLess_ThrowsNoException() { DebugGuard.MustBeLessThan(0, 1, "myParamName"); }
private static int GetColorIndex(ref Rgba32 color, int level) { DebugGuard.MustBeLessThan(level, Mask.Length, nameof(level)); int shift = 7 - level; ref byte maskRef = ref MemoryMarshal.GetReference(Mask);