aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim.Terrain.BasicTerrain/Normalise.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim.Terrain.BasicTerrain/Normalise.cs')
-rw-r--r--OpenSim.Terrain.BasicTerrain/Normalise.cs83
1 files changed, 83 insertions, 0 deletions
diff --git a/OpenSim.Terrain.BasicTerrain/Normalise.cs b/OpenSim.Terrain.BasicTerrain/Normalise.cs
new file mode 100644
index 0000000..507795b
--- /dev/null
+++ b/OpenSim.Terrain.BasicTerrain/Normalise.cs
@@ -0,0 +1,83 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace OpenSim.Terrain.BasicTerrain
6{
7 static class Normalise
8 {
9 public static void normalise(float[,] map)
10 {
11 double max = findMax(map);
12 double min = findMin(map);
13 int w = map.GetLength(0);
14 int h = map.GetLength(1);
15
16 int x, y;
17
18 for (x = 0; x < w; x++)
19 {
20 for (y = 0; y < h; y++)
21 {
22 map[x, y] = (float)((map[x, y] - min) * (1.0 / (max - min)));
23 }
24 }
25 }
26
27 public static void normalise(float[,] map, double newmax)
28 {
29 double max = findMax(map);
30 double min = findMin(map);
31 int w = map.GetLength(0);
32 int h = map.GetLength(1);
33
34 int x, y;
35
36 for (x = 0; x < w; x++)
37 {
38 for (y = 0; y < h; y++)
39 {
40 map[x, y] = (float)((map[x, y] - min) * (1.0 / (max - min)) * newmax);
41 }
42 }
43 }
44
45 public static double findMax(float[,] map)
46 {
47 int x, y;
48 int w = map.GetLength(0);
49 int h = map.GetLength(1);
50 double max = double.MinValue;
51
52 for (x = 0; x < w; x++)
53 {
54 for (y = 0; y < h; y++)
55 {
56 if (map[x, y] > max)
57 max = map[x, y];
58 }
59 }
60
61 return max;
62 }
63
64 public static double findMin(float[,] map)
65 {
66 int x, y;
67 int w = map.GetLength(0);
68 int h = map.GetLength(1);
69 double min = double.MaxValue;
70
71 for (x = 0; x < w; x++)
72 {
73 for (y = 0; y < h; y++)
74 {
75 if (map[x, y] < min)
76 min = map[x, y];
77 }
78 }
79
80 return min;
81 }
82 }
83}