* Fixed a potential div by zero with terrain commands.

afrisby
Adam Frisby 2007-07-29 12:11:54 +00:00
parent bdb2ad2d43
commit 7d2f976b14
1 changed files with 17 additions and 4 deletions

View File

@ -65,6 +65,12 @@ namespace libTerrain
{ {
SetDiff(); SetDiff();
if (minv == maxv)
{
Fill(minv);
return this;
}
double max = FindMax(); double max = FindMax();
double min = FindMin(); double min = FindMin();
@ -73,6 +79,8 @@ namespace libTerrain
for (x = 0; x < w; x++) for (x = 0; x < w; x++)
{ {
for (y = 0; y < h; y++) for (y = 0; y < h; y++)
{
if (min != max)
{ {
double val = (map[x, y] - min) * (1.0 / max - min); double val = (map[x, y] - min) * (1.0 / max - min);
val *= maxv - minv; val *= maxv - minv;
@ -80,6 +88,11 @@ namespace libTerrain
map[x, y] = val; map[x, y] = val;
} }
else
{
map[x, y] = 0.5;
}
}
} }
return this; return this;