2d coord to 1d index code example
Example 1: js 1d index to 2d coord
y = index / width;
x = index % width;
Example 2: how to convert a 2d coordinate to an index
index = x + width * y;
y = index / width;
x = index % width;
index = x + width * y;