26 lines
425 B
C#
26 lines
425 B
C#
|
|
namespace StitchATon.Utility;
|
||
|
|
|
||
|
|
public class Grid2D<T>
|
||
|
|
{
|
||
|
|
private T[] _buffer;
|
||
|
|
public readonly int W;
|
||
|
|
public readonly int H;
|
||
|
|
|
||
|
|
public Grid2D( int width, int height )
|
||
|
|
{
|
||
|
|
W = width;
|
||
|
|
H = height;
|
||
|
|
_buffer = new T[W * H];
|
||
|
|
}
|
||
|
|
|
||
|
|
private int Map( int x, int y )
|
||
|
|
{
|
||
|
|
return x + ( y * W );
|
||
|
|
}
|
||
|
|
|
||
|
|
public T this[ int x, int y ]
|
||
|
|
{
|
||
|
|
get => _buffer[Map( x, y )];
|
||
|
|
set => _buffer[Map( x, y )] = value;
|
||
|
|
}
|
||
|
|
}
|