public static Xy FlatTo2DIndex(this Array array, int flattenedIndex) { #if DEV_MODE && PI_ASSERTATIONS var test = Xy.Get2DIndex(array, flattenedIndex); Debug.Assert(test.ToFlattenedIndex(array) == flattenedIndex); #endif return(Xy.Get2DIndex(array, flattenedIndex)); }
public static object GetValue(this Array array, Xy index) { #if DEV_MODE && PI_ASSERTATIONS Debug.Assert(array.Rank == 2, "Array.GetValue rank " + array.Rank + " not valid for two-dimensional index."); if (array.Height() <= index.x) { throw new IndexOutOfRangeException("GetCollectionValue array2D Height (" + array.Height() + ") < index.x (" + index.x + ") for array: " + StringUtils.ToString(array)); } if (array.Width() <= index.y) { throw new IndexOutOfRangeException("GetCollectionValue array2D Width (" + array.Width() + ") < index.y (" + index.y + ") for array: " + StringUtils.ToString(array)); } #endif return(array.GetValue(index.x, index.y)); }
public static T GetValue <T>(this T[][] jaggedArray, Xy index) { return(jaggedArray[index.x][index.y]); }
public static T GetValue <T>(this T[,] array2D, Xy index) { return(array2D[index.x, index.y]); }
public static int FlattenIndex(this Array array, Xy index) { return(index.ToFlattenedIndex(array)); }
/// <summary> /// Where this Size2D represents the width and height of a two-dimensional collection, /// converts given flattened index to height and width indexes of a member in the collection. /// in the collection. /// </summary> /// <param name="flattenedIndex"> Zero-based flattened index of a member in a two-dimensional collection. </param> /// <returns> The two-dimensional index of a member in the collection. </returns> public Xy Get2DIndex(int flattenedIndex) { return(Xy.Get2DIndex(width, flattenedIndex)); }