public static TCell[,] Overlay(Layer <TCell> layer1, Layer <TCell> layer2, IOverlay <TCell> overlayer) { var sizeX = Math.Min(layer1.SizeX, layer2.SizeX); var sizeY = Math.Min(layer1.SizeY, layer2.SizeY); var cells = new TCell[sizeX, sizeY]; for (var x = 0; x < sizeX; x++) { for (var y = 0; y < sizeY; y++) { cells[x, y] = overlayer.Overlay(layer1._cells[x, y], layer2._cells[x, y]); } } return(cells); }