public HeightMap(double gridSize, Vector2 min, Vector2 max)
{
if (min.X == max.X || min.Y == max.Y)
throw new Exception("Height map can't be infinitely narrow");
int pointsX = (int)Math.Ceiling((max.X - min.X) / gridSize) + 1;
int pointsY = (int)Math.Ceiling((max.Y - min.Y) / gridSize) + 1;
if (pointsX == 0 || pointsY == 0)
throw new Exception("Height map must have at least 4 points");
Points = new double?[pointsX, pointsY];
if (max.X < min.X)
{
double a = min.X;
min.X = max.X;
max.X = a;
}
if (max.Y < min.Y)
{
double a = min.Y;
min.Y = max.Y;
max.Y = a;
}
Min = min;
Max = max;
SizeX = pointsX;
SizeY = pointsY;
for (int x = 0; x < SizeX; x++)
{
for (int y = 0; y < SizeY; y++)
NotProbed.Enqueue(new Tuple<int, int>(x, y));
if (++x >= SizeX)
break;
for (int y = SizeY - 1; y >= 0; y--)
NotProbed.Enqueue(new Tuple<int, int>(x, y));
}
}