static public IGrid <T> BoundSubSection <T>(this IGrid <T> item, int x1, int y1, int x2, int y2) { if (item != null) { x1 = x1.BindBetween(0, item.GetWidth()); x2 = x2.BindBetween(0, item.GetHeight()); y1 = y1.BindBetween(0, item.GetHeight()); y2 = y2.BindBetween(0, item.GetHeight()); if (x1 == 0 && y1 == 0 && x2 == item.GetWidth() && y2 == item.GetHeight()) { return(item); } return(new IGridTransform <T>( x2 - x1, y2 - y1, (x, y) => item[x1 + x, y1 + y], (x, y, v) => item[x1 + x, y1 + y] = v )); } return(Empty.IGrid <T>()); }
static public IGrid <OUTPUT_TYPE> Convert <INPUT_TYPE, OUTPUT_TYPE>(this IGrid <INPUT_TYPE> item, Operation <OUTPUT_TYPE, INPUT_TYPE> operation) { if (item != null) { return(new IGridTransform <OUTPUT_TYPE>(item.GetWidth(), item.GetHeight(), (x, y) => operation(item[x, y]) )); } return(Empty.IGrid <OUTPUT_TYPE>()); }
static public IGrid <T> ConvertMaskedInclusion <T>(this IGrid <T> item, HashSet <VectorI2> included) { if (item != null) { return(new IGridTransform <T>(item.GetWidth(), item.GetHeight(), (x, y) => included.Contains(new VectorI2(x, y)).ConvertBool(() => item[x, y]), (x, y, v) => included.Contains(new VectorI2(x, y)).IfTrue(() => item[x, y] = v) )); } return(Empty.IGrid <T>()); }
static public IGrid <T> UnboundSubSection <T>(this IGrid <T> item, int x1, int y1, int x2, int y2, T default_value = default(T)) { if (item != null) { return(new IGridTransform <T>( x2 - x1, y2 - y1, (x, y) => item.Get(x, y, default_value), (x, y, v) => item.SetDropped(x, y, v) )); } return(Empty.IGrid <T>()); }