Array2D<T>.generated constructor
Creates a new array with width
, height
elements initialized to the
result of calling generator
on each element.
Implementation
Array2D.generated(int width, int height, T Function(Vec) generator)
: bounds = Rect(0, 0, width, height),
_elements = width * height > 0
? List<T>.filled(width * height, generator(Vec.zero))
: List<T>.empty() {
// Don't call generator() on the first cell twice.
for (var x = 1; x < width; x++) {
set(x, 0, generator(Vec(x, 0)));
}
for (var y = 1; y < height; y++) {
for (var x = 0; x < width; x++) {
set(x, y, generator(Vec(x, y)));
}
}
}