public static List <Vec> PositionsNearBorder <T>(this VecArray <T> array, int distance) { List <Vec> result = new List <Vec>(); if (distance <= 0) { return(result); } int width = array.Get().GetLength(0); int height = array.Get().GetLength(1); if (distance * 2 >= width && distance * 2 >= height) { return(array.AllPositions()); } for (int x = 0; x < width; ++x) { for (int y = 0; y < height; ++y) { if (y == distance && x >= distance && x < width - distance) { y = height - distance; } result.Add(new Vec(x, y)); } } return(result); }