From 7d2f976b14a526f706cf33bbefce7d4d75d28da5 Mon Sep 17 00:00:00 2001 From: Adam Frisby Date: Sun, 29 Jul 2007 12:11:54 +0000 Subject: * Fixed a potential div by zero with terrain commands. --- .../libTerrainBSD/Channel/Grid.cs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Grid.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Grid.cs index 18e40b5..76bad27 100644 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Grid.cs +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Grid.cs @@ -65,6 +65,12 @@ namespace libTerrain { SetDiff(); + if (minv == maxv) + { + Fill(minv); + return this; + } + double max = FindMax(); double min = FindMin(); @@ -74,11 +80,18 @@ namespace libTerrain { for (y = 0; y < h; y++) { - double val = (map[x, y] - min) * (1.0 / max - min); - val *= maxv - minv; - val += minv; + if (min != max) + { + double val = (map[x, y] - min) * (1.0 / max - min); + val *= maxv - minv; + val += minv; - map[x, y] = val; + map[x, y] = val; + } + else + { + map[x, y] = 0.5; + } } } -- cgit v1.1