aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD')
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Bitmap/Bitmap.cs148
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Channel.cs132
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Common.cs554
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Flatten.cs296
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Raise.cs276
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/File.cs154
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Fracture.cs288
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Gradient.cs130
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/HillPlanter.cs566
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Noise.cs112
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Spiral.cs310
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Voronoi.cs428
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Worms.cs146
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Grid.cs700
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/AerobicErosion.cs424
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/HydraulicErosion.cs290
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/NavierStokes.cs612
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/ThermalWeathering.cs224
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Neighbours.cs282
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Operators.cs486
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Tools/Point2D.cs98
21 files changed, 3328 insertions, 3328 deletions
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Bitmap/Bitmap.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Bitmap/Bitmap.cs
index 1ef09fc..4093f51 100644
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Bitmap/Bitmap.cs
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Bitmap/Bitmap.cs
@@ -1,74 +1,74 @@
1/* 1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/ 2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders. 3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4* 4*
5* Redistribution and use in source and binary forms, with or without 5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met: 6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright 7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer. 8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright 9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the 10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution. 11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the 12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products 13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission. 14* derived from this software without specific prior written permission.
15* 15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY 16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26* 26*
27*/ 27*/
28 28
29using System; 29using System;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Text; 31using System.Text;
32using System.Drawing; 32using System.Drawing;
33 33
34namespace libTerrain 34namespace libTerrain
35{ 35{
36 class Raster 36 class Raster
37 { 37 {
38 int w; 38 int w;
39 int h; 39 int h;
40 Bitmap bmp; 40 Bitmap bmp;
41 41
42 public Raster(int width, int height) 42 public Raster(int width, int height)
43 { 43 {
44 w = width; 44 w = width;
45 h = height; 45 h = height;
46 bmp = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format24bppRgb); 46 bmp = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
47 } 47 }
48 48
49 public Channel ToChannel() 49 public Channel ToChannel()
50 { 50 {
51 Channel chan = new Channel(bmp.Width, bmp.Height); 51 Channel chan = new Channel(bmp.Width, bmp.Height);
52 52
53 int x, y; 53 int x, y;
54 for (x = 0; x < bmp.Width; x++) 54 for (x = 0; x < bmp.Width; x++)
55 { 55 {
56 for (y = 0; y < bmp.Height; y++) 56 for (y = 0; y < bmp.Height; y++)
57 { 57 {
58 Color val = bmp.GetPixel(x, y); 58 Color val = bmp.GetPixel(x, y);
59 chan.map[x, y] = (((double)val.R + (double)val.G + (double)val.B) / 3.0) / 255.0; 59 chan.map[x, y] = (((double)val.R + (double)val.G + (double)val.B) / 3.0) / 255.0;
60 } 60 }
61 } 61 }
62 62
63 return chan; 63 return chan;
64 } 64 }
65 65
66 public void DrawText(string txt, string font, double size) 66 public void DrawText(string txt, string font, double size)
67 { 67 {
68 Graphics gd = Graphics.FromImage(bmp); 68 Graphics gd = Graphics.FromImage(bmp);
69 //gd.DrawString(txt, 69 //gd.DrawString(txt,
70 70
71 71
72 } 72 }
73 } 73 }
74} 74}
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Channel.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Channel.cs
index 6dfee1f..2e84409 100644
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Channel.cs
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Channel.cs
@@ -1,66 +1,66 @@
1/* 1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/ 2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders. 3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4* 4*
5* Redistribution and use in source and binary forms, with or without 5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met: 6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright 7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer. 8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright 9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the 10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution. 11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the 12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products 13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission. 14* derived from this software without specific prior written permission.
15* 15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY 16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26* 26*
27*/ 27*/
28 28
29using System; 29using System;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Text; 31using System.Text;
32 32
33 33
34/* Channel 34/* Channel
35 * A channel is a single heightmap array 35 * A channel is a single heightmap array
36 * */ 36 * */
37 37
38namespace libTerrain 38namespace libTerrain
39{ 39{
40 partial class Channel 40 partial class Channel
41 { 41 {
42 public double[,] map; 42 public double[,] map;
43 public int[,] diff; 43 public int[,] diff;
44 public int w; 44 public int w;
45 public int h; 45 public int h;
46 46
47 public int seed = 1338; // One better than 1337 47 public int seed = 1338; // One better than 1337
48 48
49 public Channel() 49 public Channel()
50 { 50 {
51 w = 256; 51 w = 256;
52 h = 256; 52 h = 256;
53 map = new double[w, h]; 53 map = new double[w, h];
54 diff = new int[(int)(w / 16), (int)(h / 16)]; 54 diff = new int[(int)(w / 16), (int)(h / 16)];
55 } 55 }
56 56
57 public Channel(int width, int height) 57 public Channel(int width, int height)
58 { 58 {
59 w = width; 59 w = width;
60 h = height; 60 h = height;
61 map = new double[w, h]; 61 map = new double[w, h];
62 diff = new int[(int)(w / 16), (int)(h / 16)]; 62 diff = new int[(int)(w / 16), (int)(h / 16)];
63 } 63 }
64 64
65 } 65 }
66} 66}
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Common.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Common.cs
index 1750418..b0182dc 100644
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Common.cs
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Common.cs
@@ -1,277 +1,277 @@
1/* 1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/ 2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders. 3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4* 4*
5* Redistribution and use in source and binary forms, with or without 5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met: 6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright 7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer. 8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright 9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the 10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution. 11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the 12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products 13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission. 14* derived from this software without specific prior written permission.
15* 15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY 16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26* 26*
27*/ 27*/
28 28
29 29
30using System; 30using System;
31using System.Collections.Generic; 31using System.Collections.Generic;
32using System.Text; 32using System.Text;
33 33
34namespace libTerrain 34namespace libTerrain
35{ 35{
36 public partial class Channel 36 public partial class Channel
37 { 37 {
38 public int GetWidth() 38 public int GetWidth()
39 { 39 {
40 return w; 40 return w;
41 } 41 }
42 public int GetHeight() 42 public int GetHeight()
43 { 43 {
44 return h; 44 return h;
45 } 45 }
46 46
47 public Channel Copy() 47 public Channel Copy()
48 { 48 {
49 Channel x = new Channel(w, h); 49 Channel x = new Channel(w, h);
50 x.map = (double[,])this.map.Clone(); 50 x.map = (double[,])this.map.Clone();
51 return x; 51 return x;
52 } 52 }
53 53
54 public void SetDiff() 54 public void SetDiff()
55 { 55 {
56 SetDiff(1); 56 SetDiff(1);
57 } 57 }
58 58
59 public void SetDiff(int val) 59 public void SetDiff(int val)
60 { 60 {
61 for (int x = 0; x < w / 16; x++) 61 for (int x = 0; x < w / 16; x++)
62 { 62 {
63 for (int y = 0; y < h / 16; y++) 63 for (int y = 0; y < h / 16; y++)
64 { 64 {
65 diff[x, y] = val; 65 diff[x, y] = val;
66 } 66 }
67 } 67 }
68 } 68 }
69 69
70 public void SetDiff(int x, int y) 70 public void SetDiff(int x, int y)
71 { 71 {
72 diff[x / 16, y / 16]++; 72 diff[x / 16, y / 16]++;
73 } 73 }
74 74
75 public void Set(int x, int y, double val) 75 public void Set(int x, int y, double val)
76 { 76 {
77 if (x >= w) 77 if (x >= w)
78 throw new Exception("Bounds error while setting pixel (width)"); 78 throw new Exception("Bounds error while setting pixel (width)");
79 if (y >= h) 79 if (y >= h)
80 throw new Exception("Bounds error while setting pixel (height)"); 80 throw new Exception("Bounds error while setting pixel (height)");
81 if (x < 0) 81 if (x < 0)
82 throw new Exception("Bounds error while setting pixel (width)"); 82 throw new Exception("Bounds error while setting pixel (width)");
83 if (y < 0) 83 if (y < 0)
84 throw new Exception("Bounds error while setting pixel (height)"); 84 throw new Exception("Bounds error while setting pixel (height)");
85 85
86 if (map[x, y] != val) 86 if (map[x, y] != val)
87 { 87 {
88 SetDiff(x, y); 88 SetDiff(x, y);
89 89
90 map[x, y] = val; 90 map[x, y] = val;
91 } 91 }
92 } 92 }
93 93
94 public void SetClip(int x, int y, double val) 94 public void SetClip(int x, int y, double val)
95 { 95 {
96 SetDiff(x, y); 96 SetDiff(x, y);
97 97
98 if (x >= w) 98 if (x >= w)
99 throw new Exception("Bounds error while setting pixel (width)"); 99 throw new Exception("Bounds error while setting pixel (width)");
100 if (y >= h) 100 if (y >= h)
101 throw new Exception("Bounds error while setting pixel (height)"); 101 throw new Exception("Bounds error while setting pixel (height)");
102 if (x < 0) 102 if (x < 0)
103 throw new Exception("Bounds error while setting pixel (width)"); 103 throw new Exception("Bounds error while setting pixel (width)");
104 if (y < 0) 104 if (y < 0)
105 throw new Exception("Bounds error while setting pixel (height)"); 105 throw new Exception("Bounds error while setting pixel (height)");
106 106
107 if (val > 1.0) 107 if (val > 1.0)
108 val = 1.0; 108 val = 1.0;
109 if (val < 0.0) 109 if (val < 0.0)
110 val = 0.0; 110 val = 0.0;
111 111
112 map[x, y] = val; 112 map[x, y] = val;
113 } 113 }
114 114
115 private double GetBilinearInterpolate(double x, double y) 115 private double GetBilinearInterpolate(double x, double y)
116 { 116 {
117 if (x > w - 2.0) 117 if (x > w - 2.0)
118 x = w - 2.0; 118 x = w - 2.0;
119 if (y > h - 2.0) 119 if (y > h - 2.0)
120 y = h - 2.0; 120 y = h - 2.0;
121 if (x < 0.0) 121 if (x < 0.0)
122 x = 0.0; 122 x = 0.0;
123 if (y < 0.0) 123 if (y < 0.0)
124 y = 0.0; 124 y = 0.0;
125 125
126 int stepSize = 1; 126 int stepSize = 1;
127 double h00 = Get((int)x, (int)y); 127 double h00 = Get((int)x, (int)y);
128 double h10 = Get((int)x + stepSize, (int)y); 128 double h10 = Get((int)x + stepSize, (int)y);
129 double h01 = Get((int)x, (int)y + stepSize); 129 double h01 = Get((int)x, (int)y + stepSize);
130 double h11 = Get((int)x + stepSize, (int)y + stepSize); 130 double h11 = Get((int)x + stepSize, (int)y + stepSize);
131 double h1 = h00; 131 double h1 = h00;
132 double h2 = h10; 132 double h2 = h10;
133 double h3 = h01; 133 double h3 = h01;
134 double h4 = h11; 134 double h4 = h11;
135 double a00 = h1; 135 double a00 = h1;
136 double a10 = h2 - h1; 136 double a10 = h2 - h1;
137 double a01 = h3 - h1; 137 double a01 = h3 - h1;
138 double a11 = h1 - h2 - h3 + h4; 138 double a11 = h1 - h2 - h3 + h4;
139 double partialx = x - (int)x; 139 double partialx = x - (int)x;
140 double partialz = y - (int)y; 140 double partialz = y - (int)y;
141 double hi = a00 + (a10 * partialx) + (a01 * partialz) + (a11 * partialx * partialz); 141 double hi = a00 + (a10 * partialx) + (a01 * partialz) + (a11 * partialx * partialz);
142 return hi; 142 return hi;
143 } 143 }
144 144
145 public double Get(int x, int y) 145 public double Get(int x, int y)
146 { 146 {
147 if (x >= w) 147 if (x >= w)
148 x = w - 1; 148 x = w - 1;
149 if (y >= h) 149 if (y >= h)
150 y = h - 1; 150 y = h - 1;
151 if (x < 0) 151 if (x < 0)
152 x = 0; 152 x = 0;
153 if (y < 0) 153 if (y < 0)
154 y = 0; 154 y = 0;
155 return map[x, y]; 155 return map[x, y];
156 } 156 }
157 157
158 public void SetWrap(int x, int y, double val) 158 public void SetWrap(int x, int y, double val)
159 { 159 {
160 SetDiff(x, y); 160 SetDiff(x, y);
161 161
162 map[x % w, y % h] = val; 162 map[x % w, y % h] = val;
163 } 163 }
164 164
165 public void SetWrapClip(int x, int y, double val) 165 public void SetWrapClip(int x, int y, double val)
166 { 166 {
167 SetDiff(x, y); 167 SetDiff(x, y);
168 168
169 if (val > 1.0) 169 if (val > 1.0)
170 val = 1.0; 170 val = 1.0;
171 if (val < 0.0) 171 if (val < 0.0)
172 val = 0.0; 172 val = 0.0;
173 173
174 map[x % w, y % h] = val; 174 map[x % w, y % h] = val;
175 } 175 }
176 176
177 public void Fill(double val) 177 public void Fill(double val)
178 { 178 {
179 SetDiff(); 179 SetDiff();
180 180
181 int x, y; 181 int x, y;
182 for (x = 0; x < w; x++) 182 for (x = 0; x < w; x++)
183 { 183 {
184 for (y = 0; y < h; y++) 184 for (y = 0; y < h; y++)
185 { 185 {
186 map[x, y] = val; 186 map[x, y] = val;
187 } 187 }
188 } 188 }
189 } 189 }
190 190
191 public void Fill(double min, double max, double val) 191 public void Fill(double min, double max, double val)
192 { 192 {
193 SetDiff(); 193 SetDiff();
194 194
195 int x, y; 195 int x, y;
196 for (x = 0; x < w; x++) 196 for (x = 0; x < w; x++)
197 { 197 {
198 for (y = 0; y < h; y++) 198 for (y = 0; y < h; y++)
199 { 199 {
200 if (map[x, y] >= min && map[x, y] <= max) 200 if (map[x, y] >= min && map[x, y] <= max)
201 map[x, y] = val; 201 map[x, y] = val;
202 } 202 }
203 } 203 }
204 } 204 }
205 205
206 public double FindMax() 206 public double FindMax()
207 { 207 {
208 int x, y; 208 int x, y;
209 double max = double.MinValue; 209 double max = double.MinValue;
210 210
211 for (x = 0; x < w; x++) 211 for (x = 0; x < w; x++)
212 { 212 {
213 for (y = 0; y < h; y++) 213 for (y = 0; y < h; y++)
214 { 214 {
215 if (map[x, y] > max) 215 if (map[x, y] > max)
216 max = map[x, y]; 216 max = map[x, y];
217 } 217 }
218 } 218 }
219 219
220 return max; 220 return max;
221 } 221 }
222 222
223 public double FindMin() 223 public double FindMin()
224 { 224 {
225 int x, y; 225 int x, y;
226 double min = double.MaxValue; 226 double min = double.MaxValue;
227 227
228 for (x = 0; x < w; x++) 228 for (x = 0; x < w; x++)
229 { 229 {
230 for (y = 0; y < h; y++) 230 for (y = 0; y < h; y++)
231 { 231 {
232 if (map[x, y] < min) 232 if (map[x, y] < min)
233 min = map[x, y]; 233 min = map[x, y];
234 } 234 }
235 } 235 }
236 236
237 return min; 237 return min;
238 } 238 }
239 239
240 public double Sum() 240 public double Sum()
241 { 241 {
242 int x, y; 242 int x, y;
243 double sum = 0.0; 243 double sum = 0.0;
244 244
245 for (x = 0; x < w; x++) 245 for (x = 0; x < w; x++)
246 { 246 {
247 for (y = 0; y < h; y++) 247 for (y = 0; y < h; y++)
248 { 248 {
249 sum += map[x, y]; 249 sum += map[x, y];
250 } 250 }
251 } 251 }
252 252
253 return sum; 253 return sum;
254 } 254 }
255 255
256 public double Avg() 256 public double Avg()
257 { 257 {
258 return Sum() / (w * h); 258 return Sum() / (w * h);
259 } 259 }
260 260
261 public bool ContainsNaN() 261 public bool ContainsNaN()
262 { 262 {
263 int x, y; 263 int x, y;
264 for (x = 0; x < w; x++) 264 for (x = 0; x < w; x++)
265 { 265 {
266 for (y = 0; y < h; y++) 266 for (y = 0; y < h; y++)
267 { 267 {
268 double elm = map[x, y]; 268 double elm = map[x, y];
269 269
270 if (Double.IsNaN(elm)) 270 if (Double.IsNaN(elm))
271 return true; 271 return true;
272 } 272 }
273 } 273 }
274 return false; 274 return false;
275 } 275 }
276 } 276 }
277} 277}
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Flatten.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Flatten.cs
index 48f02e8..713ae23 100644
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Flatten.cs
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Flatten.cs
@@ -1,149 +1,149 @@
1/* 1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/ 2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders. 3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4* 4*
5* Redistribution and use in source and binary forms, with or without 5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met: 6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright 7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer. 8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright 9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the 10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution. 11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the 12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products 13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission. 14* derived from this software without specific prior written permission.
15* 15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY 16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26* 26*
27*/ 27*/
28 28
29 29
30using System; 30using System;
31using System.Collections.Generic; 31using System.Collections.Generic;
32using System.Text; 32using System.Text;
33 33
34namespace libTerrain 34namespace libTerrain
35{ 35{
36 partial class Channel 36 partial class Channel
37 { 37 {
38 /// <summary> 38 /// <summary>
39 /// Flattens the area underneath rx,ry by moving it to the average of the area. Uses a spherical mask provided by the raise() function. 39 /// Flattens the area underneath rx,ry by moving it to the average of the area. Uses a spherical mask provided by the raise() function.
40 /// </summary> 40 /// </summary>
41 /// <param name="rx">The X coordinate of the terrain mask</param> 41 /// <param name="rx">The X coordinate of the terrain mask</param>
42 /// <param name="ry">The Y coordinate of the terrain mask</param> 42 /// <param name="ry">The Y coordinate of the terrain mask</param>
43 /// <param name="size">The size of the terrain mask</param> 43 /// <param name="size">The size of the terrain mask</param>
44 /// <param name="amount">The scale of the terrain mask</param> 44 /// <param name="amount">The scale of the terrain mask</param>
45 public void Flatten(double rx, double ry, double size, double amount) 45 public void Flatten(double rx, double ry, double size, double amount)
46 { 46 {
47 FlattenSlow(rx, ry, size, amount); 47 FlattenSlow(rx, ry, size, amount);
48 } 48 }
49 49
50 private void FlattenSlow(double rx, double ry, double size, double amount) 50 private void FlattenSlow(double rx, double ry, double size, double amount)
51 { 51 {
52 // Generate the mask 52 // Generate the mask
53 Channel temp = new Channel(w, h); 53 Channel temp = new Channel(w, h);
54 temp.Fill(0); 54 temp.Fill(0);
55 temp.Raise(rx, ry, size, amount); 55 temp.Raise(rx, ry, size, amount);
56 temp.Normalise(); 56 temp.Normalise();
57 double total_mod = temp.Sum(); 57 double total_mod = temp.Sum();
58 58
59 // Establish the average height under the area 59 // Establish the average height under the area
60 Channel newmap = new Channel(w, h); 60 Channel newmap = new Channel(w, h);
61 newmap.map = (double[,])map.Clone(); 61 newmap.map = (double[,])map.Clone();
62 62
63 newmap *= temp; 63 newmap *= temp;
64 64
65 double total_terrain = newmap.Sum(); 65 double total_terrain = newmap.Sum();
66 double avg_height = total_terrain / total_mod; 66 double avg_height = total_terrain / total_mod;
67 67
68 // Create a flat terrain using the average height 68 // Create a flat terrain using the average height
69 Channel flat = new Channel(w, h); 69 Channel flat = new Channel(w, h);
70 flat.Fill(avg_height); 70 flat.Fill(avg_height);
71 71
72 // Blend the current terrain with the average height terrain 72 // Blend the current terrain with the average height terrain
73 // using the "raised" empty terrain as a mask 73 // using the "raised" empty terrain as a mask
74 Blend(flat, temp); 74 Blend(flat, temp);
75 75
76 } 76 }
77 77
78 private void FlattenFast(double rx, double ry, double size, double amount) 78 private void FlattenFast(double rx, double ry, double size, double amount)
79 { 79 {
80 int x, y; 80 int x, y;
81 double avg = 0; 81 double avg = 0;
82 double div = 0; 82 double div = 0;
83 83
84 int minX = Math.Max(0, (int)(rx - (size + 1))); 84 int minX = Math.Max(0, (int)(rx - (size + 1)));
85 int maxX = Math.Min(w, (int)(rx + (size + 1))); 85 int maxX = Math.Min(w, (int)(rx + (size + 1)));
86 int minY = Math.Max(0, (int)(ry - (size + 1))); 86 int minY = Math.Max(0, (int)(ry - (size + 1)));
87 int maxY = Math.Min(h, (int)(ry + (size + 1))); 87 int maxY = Math.Min(h, (int)(ry + (size + 1)));
88 88
89 for (x = minX; x < maxX; x++) 89 for (x = minX; x < maxX; x++)
90 { 90 {
91 for (y = minY; y < maxY; y++) 91 for (y = minY; y < maxY; y++)
92 { 92 {
93 double z = size; 93 double z = size;
94 z *= z; 94 z *= z;
95 z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); 95 z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry));
96 96
97 if (z < 0) 97 if (z < 0)
98 z = 0; 98 z = 0;
99 99
100 avg += z * amount; 100 avg += z * amount;
101 div += z; 101 div += z;
102 } 102 }
103 } 103 }
104 104
105 double height = avg / div; 105 double height = avg / div;
106 106
107 for (x = minX; x < maxX; x++) 107 for (x = minX; x < maxX; x++)
108 { 108 {
109 for (y = minY; y < maxY; y++) 109 for (y = minY; y < maxY; y++)
110 { 110 {
111 double z = size; 111 double z = size;
112 z *= z; 112 z *= z;
113 z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); 113 z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry));
114 114
115 if (z < 0) 115 if (z < 0)
116 z = 0; 116 z = 0;
117 117
118 Set(x, y, Tools.linearInterpolate(map[x, y], height, z)); 118 Set(x, y, Tools.linearInterpolate(map[x, y], height, z));
119 } 119 }
120 } 120 }
121 } 121 }
122 122
123 public void Flatten(Channel mask, double amount) 123 public void Flatten(Channel mask, double amount)
124 { 124 {
125 // Generate the mask 125 // Generate the mask
126 Channel temp = mask * amount; 126 Channel temp = mask * amount;
127 temp.Clip(0, 1); // Cut off out-of-bounds values 127 temp.Clip(0, 1); // Cut off out-of-bounds values
128 128
129 double total_mod = temp.Sum(); 129 double total_mod = temp.Sum();
130 130
131 // Establish the average height under the area 131 // Establish the average height under the area
132 Channel map = new Channel(w, h); 132 Channel map = new Channel(w, h);
133 map.map = (double[,])this.map.Clone(); 133 map.map = (double[,])this.map.Clone();
134 134
135 map *= temp; 135 map *= temp;
136 136
137 double total_terrain = map.Sum(); 137 double total_terrain = map.Sum();
138 double avg_height = total_terrain / total_mod; 138 double avg_height = total_terrain / total_mod;
139 139
140 // Create a flat terrain using the average height 140 // Create a flat terrain using the average height
141 Channel flat = new Channel(w, h); 141 Channel flat = new Channel(w, h);
142 flat.Fill(avg_height); 142 flat.Fill(avg_height);
143 143
144 // Blend the current terrain with the average height terrain 144 // Blend the current terrain with the average height terrain
145 // using the "raised" empty terrain as a mask 145 // using the "raised" empty terrain as a mask
146 Blend(flat, temp); 146 Blend(flat, temp);
147 } 147 }
148 } 148 }
149} \ No newline at end of file 149} \ No newline at end of file
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Raise.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Raise.cs
index 1d04a4f..64d175c 100644
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Raise.cs
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Raise.cs
@@ -1,139 +1,139 @@
1/* 1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/ 2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders. 3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4* 4*
5* Redistribution and use in source and binary forms, with or without 5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met: 6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright 7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer. 8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright 9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the 10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution. 11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the 12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products 13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission. 14* derived from this software without specific prior written permission.
15* 15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY 16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26* 26*
27*/ 27*/
28 28
29 29
30using System; 30using System;
31using System.Collections.Generic; 31using System.Collections.Generic;
32using System.Text; 32using System.Text;
33 33
34namespace libTerrain 34namespace libTerrain
35{ 35{
36 partial class Channel 36 partial class Channel
37 { 37 {
38 /// <summary> 38 /// <summary>
39 /// Raises land around the selection 39 /// Raises land around the selection
40 /// </summary> 40 /// </summary>
41 /// <param name="rx">The center the X coordinate of where you wish to raise the land</param> 41 /// <param name="rx">The center the X coordinate of where you wish to raise the land</param>
42 /// <param name="ry">The center the Y coordinate of where you wish to raise the land</param> 42 /// <param name="ry">The center the Y coordinate of where you wish to raise the land</param>
43 /// <param name="size">The radius of the dimple</param> 43 /// <param name="size">The radius of the dimple</param>
44 /// <param name="amount">How much impact to add to the terrain (0..2 usually)</param> 44 /// <param name="amount">How much impact to add to the terrain (0..2 usually)</param>
45 public void Raise(double rx, double ry, double size, double amount) 45 public void Raise(double rx, double ry, double size, double amount)
46 { 46 {
47 RaiseSphere(rx, ry, size, amount); 47 RaiseSphere(rx, ry, size, amount);
48 } 48 }
49 49
50 /// <summary> 50 /// <summary>
51 /// Raises land in a sphere around the selection 51 /// Raises land in a sphere around the selection
52 /// </summary> 52 /// </summary>
53 /// <param name="rx">The center the X coordinate of where you wish to raise the land</param> 53 /// <param name="rx">The center the X coordinate of where you wish to raise the land</param>
54 /// <param name="ry">The center the Y coordinate of where you wish to raise the land</param> 54 /// <param name="ry">The center the Y coordinate of where you wish to raise the land</param>
55 /// <param name="size">The radius of the sphere dimple</param> 55 /// <param name="size">The radius of the sphere dimple</param>
56 /// <param name="amount">How much impact to add to the terrain (0..2 usually)</param> 56 /// <param name="amount">How much impact to add to the terrain (0..2 usually)</param>
57 public void RaiseSphere(double rx, double ry, double size, double amount) 57 public void RaiseSphere(double rx, double ry, double size, double amount)
58 { 58 {
59 int x, y; 59 int x, y;
60 for (x = 0; x < w; x++) 60 for (x = 0; x < w; x++)
61 { 61 {
62 for (y = 0; y < h; y++) 62 for (y = 0; y < h; y++)
63 { 63 {
64 double z = size; 64 double z = size;
65 z *= z; 65 z *= z;
66 z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); 66 z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry));
67 67
68 if (z < 0) 68 if (z < 0)
69 z = 0; 69 z = 0;
70 70
71 Set(x, y, map[x, y] + (z * amount)); 71 Set(x, y, map[x, y] + (z * amount));
72 } 72 }
73 } 73 }
74 } 74 }
75 75
76 /// <summary> 76 /// <summary>
77 /// Raises land in a cone around the selection 77 /// Raises land in a cone around the selection
78 /// </summary> 78 /// </summary>
79 /// <param name="rx">The center the X coordinate of where you wish to raise the land</param> 79 /// <param name="rx">The center the X coordinate of where you wish to raise the land</param>
80 /// <param name="ry">The center the Y coordinate of where you wish to raise the land</param> 80 /// <param name="ry">The center the Y coordinate of where you wish to raise the land</param>
81 /// <param name="size">The radius of the cone</param> 81 /// <param name="size">The radius of the cone</param>
82 /// <param name="amount">How much impact to add to the terrain (0..2 usually)</param> 82 /// <param name="amount">How much impact to add to the terrain (0..2 usually)</param>
83 public void RaiseCone(double rx, double ry, double size, double amount) 83 public void RaiseCone(double rx, double ry, double size, double amount)
84 { 84 {
85 int x, y; 85 int x, y;
86 for (x = 0; x < w; x++) 86 for (x = 0; x < w; x++)
87 { 87 {
88 for (y = 0; y < h; y++) 88 for (y = 0; y < h; y++)
89 { 89 {
90 double z = size; 90 double z = size;
91 z -= Math.Sqrt(((x - rx) * (x - rx)) + ((y - ry) * (y - ry))); 91 z -= Math.Sqrt(((x - rx) * (x - rx)) + ((y - ry) * (y - ry)));
92 92
93 if (z < 0) 93 if (z < 0)
94 z = 0; 94 z = 0;
95 95
96 Set(x, y, map[x, y] + (z * amount)); 96 Set(x, y, map[x, y] + (z * amount));
97 } 97 }
98 } 98 }
99 } 99 }
100 100
101 /// <summary> 101 /// <summary>
102 /// Lowers land in a sphere around the selection 102 /// Lowers land in a sphere around the selection
103 /// </summary> 103 /// </summary>
104 /// <param name="rx">The center the X coordinate of where you wish to lower the land</param> 104 /// <param name="rx">The center the X coordinate of where you wish to lower the land</param>
105 /// <param name="ry">The center the Y coordinate of where you wish to lower the land</param> 105 /// <param name="ry">The center the Y coordinate of where you wish to lower the land</param>
106 /// <param name="size">The radius of the sphere dimple</param> 106 /// <param name="size">The radius of the sphere dimple</param>
107 /// <param name="amount">How much impact to remove from the terrain (0..2 usually)</param> 107 /// <param name="amount">How much impact to remove from the terrain (0..2 usually)</param>
108 public void Lower(double rx, double ry, double size, double amount) 108 public void Lower(double rx, double ry, double size, double amount)
109 { 109 {
110 LowerSphere(rx, ry, size, amount); 110 LowerSphere(rx, ry, size, amount);
111 } 111 }
112 112
113 /// <summary> 113 /// <summary>
114 /// Lowers land in a sphere around the selection 114 /// Lowers land in a sphere around the selection
115 /// </summary> 115 /// </summary>
116 /// <param name="rx">The center the X coordinate of where you wish to lower the land</param> 116 /// <param name="rx">The center the X coordinate of where you wish to lower the land</param>
117 /// <param name="ry">The center the Y coordinate of where you wish to lower the land</param> 117 /// <param name="ry">The center the Y coordinate of where you wish to lower the land</param>
118 /// <param name="size">The radius of the sphere dimple</param> 118 /// <param name="size">The radius of the sphere dimple</param>
119 /// <param name="amount">How much impact to remove from the terrain (0..2 usually)</param> 119 /// <param name="amount">How much impact to remove from the terrain (0..2 usually)</param>
120 public void LowerSphere(double rx, double ry, double size, double amount) 120 public void LowerSphere(double rx, double ry, double size, double amount)
121 { 121 {
122 int x, y; 122 int x, y;
123 for (x = 0; x < w; x++) 123 for (x = 0; x < w; x++)
124 { 124 {
125 for (y = 0; y < h; y++) 125 for (y = 0; y < h; y++)
126 { 126 {
127 double z = size; 127 double z = size;
128 z *= z; 128 z *= z;
129 z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); 129 z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry));
130 130
131 if (z < 0) 131 if (z < 0)
132 z = 0; 132 z = 0;
133 133
134 Set(x, y, map[x, y] - (z * amount)); 134 Set(x, y, map[x, y] - (z * amount));
135 } 135 }
136 } 136 }
137 } 137 }
138 } 138 }
139} \ No newline at end of file 139} \ No newline at end of file
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/File.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/File.cs
index c0173c0..cfefb6b 100644
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/File.cs
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/File.cs
@@ -1,77 +1,77 @@
1/* 1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/ 2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders. 3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4* 4*
5* Redistribution and use in source and binary forms, with or without 5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met: 6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright 7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer. 8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright 9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the 10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution. 11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the 12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products 13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission. 14* derived from this software without specific prior written permission.
15* 15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY 16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26* 26*
27*/ 27*/
28 28
29using System; 29using System;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Text; 31using System.Text;
32using System.Drawing; 32using System.Drawing;
33 33
34namespace libTerrain 34namespace libTerrain
35{ 35{
36 partial class Channel 36 partial class Channel
37 { 37 {
38 public Channel LoadImage(string filename) 38 public Channel LoadImage(string filename)
39 { 39 {
40 SetDiff(); 40 SetDiff();
41 41
42 Bitmap bit = new Bitmap(filename); 42 Bitmap bit = new Bitmap(filename);
43 Channel chan = new Channel(bit.Width, bit.Height); 43 Channel chan = new Channel(bit.Width, bit.Height);
44 44
45 int x, y; 45 int x, y;
46 for (x = 0; x < bit.Width; x++) 46 for (x = 0; x < bit.Width; x++)
47 { 47 {
48 for (y = 0; y < bit.Height; y++) 48 for (y = 0; y < bit.Height; y++)
49 { 49 {
50 Color val = bit.GetPixel(x, y); 50 Color val = bit.GetPixel(x, y);
51 chan.map[x, y] = (((double)val.R + (double)val.G + (double)val.B) / 3.0) / 255.0; 51 chan.map[x, y] = (((double)val.R + (double)val.G + (double)val.B) / 3.0) / 255.0;
52 } 52 }
53 } 53 }
54 54
55 return chan; 55 return chan;
56 } 56 }
57 57
58 public void SaveImage(string filename) 58 public void SaveImage(string filename)
59 { 59 {
60 Channel outmap = this.Copy(); 60 Channel outmap = this.Copy();
61 outmap.Normalise(); 61 outmap.Normalise();
62 62
63 Bitmap bit = new Bitmap(w, h, System.Drawing.Imaging.PixelFormat.Format24bppRgb); 63 Bitmap bit = new Bitmap(w, h, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
64 int x, y; 64 int x, y;
65 for (x = 0; x < w; x++) 65 for (x = 0; x < w; x++)
66 { 66 {
67 for (y = 0; y < h; y++) 67 for (y = 0; y < h; y++)
68 { 68 {
69 int val = Math.Min(255, (int)(outmap.map[x,y] * 255)); 69 int val = Math.Min(255, (int)(outmap.map[x,y] * 255));
70 Color col = Color.FromArgb(val,val,val); 70 Color col = Color.FromArgb(val,val,val);
71 bit.SetPixel(x, y, col); 71 bit.SetPixel(x, y, col);
72 } 72 }
73 } 73 }
74 bit.Save(filename); 74 bit.Save(filename);
75 } 75 }
76 } 76 }
77} 77}
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Fracture.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Fracture.cs
index 13dd1bc..2d42759 100644
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Fracture.cs
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Fracture.cs
@@ -1,145 +1,145 @@
1/* 1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/ 2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders. 3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4* 4*
5* Redistribution and use in source and binary forms, with or without 5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met: 6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright 7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer. 8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright 9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the 10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution. 11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the 12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products 13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission. 14* derived from this software without specific prior written permission.
15* 15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY 16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26* 26*
27*/ 27*/
28 28
29using System; 29using System;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Text; 31using System.Text;
32 32
33namespace libTerrain 33namespace libTerrain
34{ 34{
35 partial class Channel 35 partial class Channel
36 { 36 {
37 /// <summary> 37 /// <summary>
38 /// Produces a set of coordinates defined by an edge point. Eg - 0 = 0,0. 256 = 0,256. 512 = 256,256 38 /// Produces a set of coordinates defined by an edge point. Eg - 0 = 0,0. 256 = 0,256. 512 = 256,256
39 /// Assumes a 256^2 heightmap. This needs fixing for input values of w,h 39 /// Assumes a 256^2 heightmap. This needs fixing for input values of w,h
40 /// </summary> 40 /// </summary>
41 /// <param name="val"></param> 41 /// <param name="val"></param>
42 /// <param name="w"></param> 42 /// <param name="w"></param>
43 /// <param name="h"></param> 43 /// <param name="h"></param>
44 /// <returns></returns> 44 /// <returns></returns>
45 private int[] RadialEdge256(int val) 45 private int[] RadialEdge256(int val)
46 { 46 {
47 // Four cases: 47 // Four cases:
48 // 1. 000..255 return 0,val 48 // 1. 000..255 return 0,val
49 // 2. 256..511 return val - 256,255 49 // 2. 256..511 return val - 256,255
50 // 3. 512..767 return 255, val - 511 50 // 3. 512..767 return 255, val - 511
51 // 4. 768..1023 return val - 768,0 51 // 4. 768..1023 return val - 768,0
52 52
53 int[] ret = new int[2]; 53 int[] ret = new int[2];
54 54
55 if (val < 256) 55 if (val < 256)
56 { 56 {
57 ret[0] = 0; 57 ret[0] = 0;
58 ret[1] = val; 58 ret[1] = val;
59 return ret; 59 return ret;
60 } 60 }
61 if (val < 512) 61 if (val < 512)
62 { 62 {
63 ret[0] = (val % 256); 63 ret[0] = (val % 256);
64 ret[1] = 255; 64 ret[1] = 255;
65 return ret; 65 return ret;
66 } 66 }
67 if (val < 768) 67 if (val < 768)
68 { 68 {
69 ret[0] = 255; 69 ret[0] = 255;
70 ret[1] = 255 - (val % 256); 70 ret[1] = 255 - (val % 256);
71 return ret; 71 return ret;
72 } 72 }
73 if (val < 1024) 73 if (val < 1024)
74 { 74 {
75 ret[0] = 255 - (val % 256); 75 ret[0] = 255 - (val % 256);
76 ret[1] = 255; 76 ret[1] = 255;
77 return ret; 77 return ret;
78 } 78 }
79 79
80 throw new Exception("Out of bounds parameter (val)"); 80 throw new Exception("Out of bounds parameter (val)");
81 } 81 }
82 82
83 public void Fracture(int number, double scalemin, double scalemax) 83 public void Fracture(int number, double scalemin, double scalemax)
84 { 84 {
85 SetDiff(); 85 SetDiff();
86 86
87 Random rand = new Random(seed); 87 Random rand = new Random(seed);
88 88
89 for (int i = 0; i < number; i++) 89 for (int i = 0; i < number; i++)
90 { 90 {
91 int[] a, b; 91 int[] a, b;
92 92
93 a = RadialEdge256(rand.Next(1023)); // TODO: Broken 93 a = RadialEdge256(rand.Next(1023)); // TODO: Broken
94 b = RadialEdge256(rand.Next(1023)); // TODO: Broken 94 b = RadialEdge256(rand.Next(1023)); // TODO: Broken
95 double z = rand.NextDouble(); 95 double z = rand.NextDouble();
96 double u = rand.NextDouble(); 96 double u = rand.NextDouble();
97 double v = rand.NextDouble(); 97 double v = rand.NextDouble();
98 98
99 for (int x = 0; x < w; x++) 99 for (int x = 0; x < w; x++)
100 { 100 {
101 for (int y = 0; y < h; y++) 101 for (int y = 0; y < h; y++)
102 { 102 {
103 double miny = Tools.linearInterpolate(a[1], b[1], (double)x / (double)w); 103 double miny = Tools.linearInterpolate(a[1], b[1], (double)x / (double)w);
104 104
105 if (v >= 0.5) 105 if (v >= 0.5)
106 { 106 {
107 if (u >= 0.5) 107 if (u >= 0.5)
108 { 108 {
109 if (y > miny) 109 if (y > miny)
110 { 110 {
111 map[x, y] += Tools.linearInterpolate(scalemin, scalemax, z); 111 map[x, y] += Tools.linearInterpolate(scalemin, scalemax, z);
112 } 112 }
113 } 113 }
114 else 114 else
115 { 115 {
116 if (y < miny) 116 if (y < miny)
117 { 117 {
118 map[x, y] += Tools.linearInterpolate(scalemin, scalemax, z); 118 map[x, y] += Tools.linearInterpolate(scalemin, scalemax, z);
119 } 119 }
120 } 120 }
121 } 121 }
122 else 122 else
123 { 123 {
124 if (u >= 0.5) 124 if (u >= 0.5)
125 { 125 {
126 if (x > miny) 126 if (x > miny)
127 { 127 {
128 map[x, y] += Tools.linearInterpolate(scalemin, scalemax, z); 128 map[x, y] += Tools.linearInterpolate(scalemin, scalemax, z);
129 } 129 }
130 } 130 }
131 else 131 else
132 { 132 {
133 if (x < miny) 133 if (x < miny)
134 { 134 {
135 map[x, y] += Tools.linearInterpolate(scalemin, scalemax, z); 135 map[x, y] += Tools.linearInterpolate(scalemin, scalemax, z);
136 } 136 }
137 } 137 }
138 } 138 }
139 } 139 }
140 } 140 }
141 } 141 }
142 Normalise(); 142 Normalise();
143 } 143 }
144 } 144 }
145} \ No newline at end of file 145} \ No newline at end of file
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Gradient.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Gradient.cs
index 47b7a66..141fe04 100644
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Gradient.cs
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Gradient.cs
@@ -1,66 +1,66 @@
1/* 1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/ 2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders. 3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4* 4*
5* Redistribution and use in source and binary forms, with or without 5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met: 6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright 7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer. 8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright 9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the 10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution. 11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the 12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products 13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission. 14* derived from this software without specific prior written permission.
15* 15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY 16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26* 26*
27*/ 27*/
28 28
29using System; 29using System;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Text; 31using System.Text;
32 32
33namespace libTerrain 33namespace libTerrain
34{ 34{
35 partial class Channel 35 partial class Channel
36 { 36 {
37 37
38 public void GradientCube() 38 public void GradientCube()
39 { 39 {
40 SetDiff(); 40 SetDiff();
41 41
42 int x, y; 42 int x, y;
43 for (x = 0; x < w; x++) 43 for (x = 0; x < w; x++)
44 { 44 {
45 for (y = 0; y < h; y++) 45 for (y = 0; y < h; y++)
46 { 46 {
47 map[x, y] = x*y; 47 map[x, y] = x*y;
48 } 48 }
49 } 49 }
50 Normalise(); 50 Normalise();
51 } 51 }
52 52
53 public void GradientStripe() 53 public void GradientStripe()
54 { 54 {
55 int x, y; 55 int x, y;
56 for (x = 0; x < w; x++) 56 for (x = 0; x < w; x++)
57 { 57 {
58 for (y = 0; y < h; y++) 58 for (y = 0; y < h; y++)
59 { 59 {
60 map[x, y] = x; 60 map[x, y] = x;
61 } 61 }
62 } 62 }
63 Normalise(); 63 Normalise();
64 } 64 }
65 } 65 }
66} \ No newline at end of file 66} \ No newline at end of file
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/HillPlanter.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/HillPlanter.cs
index 5a697b1..aa18e40 100644
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/HillPlanter.cs
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/HillPlanter.cs
@@ -1,283 +1,283 @@
1/* 1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/ 2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders. 3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4* 4*
5* Redistribution and use in source and binary forms, with or without 5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met: 6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright 7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer. 8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright 9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the 10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution. 11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the 12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products 13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission. 14* derived from this software without specific prior written permission.
15* 15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY 16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26* 26*
27*/ 27*/
28 28
29using System; 29using System;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Text; 31using System.Text;
32 32
33namespace libTerrain 33namespace libTerrain
34{ 34{
35 partial class Channel 35 partial class Channel
36 { 36 {
37 /// <summary> 37 /// <summary>
38 /// Generates a series of spheres which are then either max()'d or added together. Inspired by suggestion from jh. 38 /// Generates a series of spheres which are then either max()'d or added together. Inspired by suggestion from jh.
39 /// </summary> 39 /// </summary>
40 /// <remarks>3-Clause BSD Licensed</remarks> 40 /// <remarks>3-Clause BSD Licensed</remarks>
41 /// <param name="number">The number of hills to generate</param> 41 /// <param name="number">The number of hills to generate</param>
42 /// <param name="scale_min">The minimum size of each hill</param> 42 /// <param name="scale_min">The minimum size of each hill</param>
43 /// <param name="scale_range">The maximum size of each hill</param> 43 /// <param name="scale_range">The maximum size of each hill</param>
44 /// <param name="island">Whether to bias hills towards the center of the map</param> 44 /// <param name="island">Whether to bias hills towards the center of the map</param>
45 /// <param name="additive">Whether to add hills together or to pick the largest value</param> 45 /// <param name="additive">Whether to add hills together or to pick the largest value</param>
46 /// <param name="noisy">Generates hill-shaped noise instead of consistent hills</param> 46 /// <param name="noisy">Generates hill-shaped noise instead of consistent hills</param>
47 public void HillsSpheres(int number, double scale_min, double scale_range, bool island, bool additive, bool noisy) 47 public void HillsSpheres(int number, double scale_min, double scale_range, bool island, bool additive, bool noisy)
48 { 48 {
49 SetDiff(); 49 SetDiff();
50 50
51 Random random = new Random(seed); 51 Random random = new Random(seed);
52 52
53 int x, y; 53 int x, y;
54 int i; 54 int i;
55 55
56 for (i = 0; i < number; i++) 56 for (i = 0; i < number; i++)
57 { 57 {
58 double rx = Math.Min(255.0, random.NextDouble() * w); 58 double rx = Math.Min(255.0, random.NextDouble() * w);
59 double ry = Math.Min(255.0, random.NextDouble() * h); 59 double ry = Math.Min(255.0, random.NextDouble() * h);
60 double rand = random.NextDouble(); 60 double rand = random.NextDouble();
61 61
62 if (island) 62 if (island)
63 { 63 {
64 // Move everything towards the center 64 // Move everything towards the center
65 rx -= w / 2; 65 rx -= w / 2;
66 rx /= 2; 66 rx /= 2;
67 rx += w / 2; 67 rx += w / 2;
68 68
69 ry -= h / 2; 69 ry -= h / 2;
70 ry /= 2; 70 ry /= 2;
71 ry += h / 2; 71 ry += h / 2;
72 } 72 }
73 73
74 for (x = 0; x < w; x++) 74 for (x = 0; x < w; x++)
75 { 75 {
76 for (y = 0; y < h; y++) 76 for (y = 0; y < h; y++)
77 { 77 {
78 if (noisy) 78 if (noisy)
79 rand = random.NextDouble(); 79 rand = random.NextDouble();
80 80
81 double z = (scale_min + (scale_range * rand)); 81 double z = (scale_min + (scale_range * rand));
82 z *= z; 82 z *= z;
83 z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); 83 z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry));
84 84
85 if (z < 0) 85 if (z < 0)
86 z = 0; 86 z = 0;
87 87
88 if (additive) 88 if (additive)
89 { 89 {
90 map[x, y] += z; 90 map[x, y] += z;
91 } 91 }
92 else 92 else
93 { 93 {
94 map[x, y] = Math.Max(map[x, y], z); 94 map[x, y] = Math.Max(map[x, y], z);
95 } 95 }
96 } 96 }
97 } 97 }
98 } 98 }
99 99
100 Normalise(); 100 Normalise();
101 } 101 }
102 102
103 /// <summary> 103 /// <summary>
104 /// Generates a series of cones which are then either max()'d or added together. Inspired by suggestion from jh. 104 /// Generates a series of cones which are then either max()'d or added together. Inspired by suggestion from jh.
105 /// </summary> 105 /// </summary>
106 /// <remarks>3-Clause BSD Licensed</remarks> 106 /// <remarks>3-Clause BSD Licensed</remarks>
107 /// <param name="number">The number of hills to generate</param> 107 /// <param name="number">The number of hills to generate</param>
108 /// <param name="scale_min">The minimum size of each hill</param> 108 /// <param name="scale_min">The minimum size of each hill</param>
109 /// <param name="scale_range">The maximum size of each hill</param> 109 /// <param name="scale_range">The maximum size of each hill</param>
110 /// <param name="island">Whether to bias hills towards the center of the map</param> 110 /// <param name="island">Whether to bias hills towards the center of the map</param>
111 /// <param name="additive">Whether to add hills together or to pick the largest value</param> 111 /// <param name="additive">Whether to add hills together or to pick the largest value</param>
112 /// <param name="noisy">Generates hill-shaped noise instead of consistent hills</param> 112 /// <param name="noisy">Generates hill-shaped noise instead of consistent hills</param>
113 public void HillsCones(int number, double scale_min, double scale_range, bool island, bool additive, bool noisy) 113 public void HillsCones(int number, double scale_min, double scale_range, bool island, bool additive, bool noisy)
114 { 114 {
115 SetDiff(); 115 SetDiff();
116 116
117 Random random = new Random(seed); 117 Random random = new Random(seed);
118 118
119 int x, y; 119 int x, y;
120 int i; 120 int i;
121 121
122 for (i = 0; i < number; i++) 122 for (i = 0; i < number; i++)
123 { 123 {
124 double rx = Math.Min(255.0, random.NextDouble() * w); 124 double rx = Math.Min(255.0, random.NextDouble() * w);
125 double ry = Math.Min(255.0, random.NextDouble() * h); 125 double ry = Math.Min(255.0, random.NextDouble() * h);
126 double rand = random.NextDouble(); 126 double rand = random.NextDouble();
127 127
128 if (island) 128 if (island)
129 { 129 {
130 // Move everything towards the center 130 // Move everything towards the center
131 rx -= w / 2; 131 rx -= w / 2;
132 rx /= 2; 132 rx /= 2;
133 rx += w / 2; 133 rx += w / 2;
134 134
135 ry -= h / 2; 135 ry -= h / 2;
136 ry /= 2; 136 ry /= 2;
137 ry += h / 2; 137 ry += h / 2;
138 } 138 }
139 139
140 for (x = 0; x < w; x++) 140 for (x = 0; x < w; x++)
141 { 141 {
142 for (y = 0; y < h; y++) 142 for (y = 0; y < h; y++)
143 { 143 {
144 if (noisy) 144 if (noisy)
145 rand = random.NextDouble(); 145 rand = random.NextDouble();
146 146
147 double z = (scale_min + (scale_range * rand)); 147 double z = (scale_min + (scale_range * rand));
148 z -= Math.Sqrt(((x - rx) * (x - rx)) + ((y - ry) * (y - ry))); 148 z -= Math.Sqrt(((x - rx) * (x - rx)) + ((y - ry) * (y - ry)));
149 149
150 if (z < 0) 150 if (z < 0)
151 z = 0; 151 z = 0;
152 152
153 if (additive) 153 if (additive)
154 { 154 {
155 map[x, y] += z; 155 map[x, y] += z;
156 } 156 }
157 else 157 else
158 { 158 {
159 map[x, y] = Math.Max(map[x, y], z); 159 map[x, y] = Math.Max(map[x, y], z);
160 } 160 }
161 } 161 }
162 } 162 }
163 } 163 }
164 164
165 Normalise(); 165 Normalise();
166 } 166 }
167 167
168 public void HillsBlocks(int number, double scale_min, double scale_range, bool island, bool additive, bool noisy) 168 public void HillsBlocks(int number, double scale_min, double scale_range, bool island, bool additive, bool noisy)
169 { 169 {
170 SetDiff(); 170 SetDiff();
171 171
172 Random random = new Random(seed); 172 Random random = new Random(seed);
173 173
174 int x, y; 174 int x, y;
175 int i; 175 int i;
176 176
177 for (i = 0; i < number; i++) 177 for (i = 0; i < number; i++)
178 { 178 {
179 double rx = Math.Min(255.0, random.NextDouble() * w); 179 double rx = Math.Min(255.0, random.NextDouble() * w);
180 double ry = Math.Min(255.0, random.NextDouble() * h); 180 double ry = Math.Min(255.0, random.NextDouble() * h);
181 double rand = random.NextDouble(); 181 double rand = random.NextDouble();
182 182
183 if (island) 183 if (island)
184 { 184 {
185 // Move everything towards the center 185 // Move everything towards the center
186 rx -= w / 2; 186 rx -= w / 2;
187 rx /= 2; 187 rx /= 2;
188 rx += w / 2; 188 rx += w / 2;
189 189
190 ry -= h / 2; 190 ry -= h / 2;
191 ry /= 2; 191 ry /= 2;
192 ry += h / 2; 192 ry += h / 2;
193 } 193 }
194 194
195 for (x = 0; x < w; x++) 195 for (x = 0; x < w; x++)
196 { 196 {
197 for (y = 0; y < h; y++) 197 for (y = 0; y < h; y++)
198 { 198 {
199 if (noisy) 199 if (noisy)
200 rand = random.NextDouble(); 200 rand = random.NextDouble();
201 201
202 double z = (scale_min + (scale_range * rand)); 202 double z = (scale_min + (scale_range * rand));
203 z -= Math.Abs(x-rx) + Math.Abs(y-ry); 203 z -= Math.Abs(x-rx) + Math.Abs(y-ry);
204 //z -= Math.Sqrt(((x - rx) * (x - rx)) + ((y - ry) * (y - ry))); 204 //z -= Math.Sqrt(((x - rx) * (x - rx)) + ((y - ry) * (y - ry)));
205 205
206 if (z < 0) 206 if (z < 0)
207 z = 0; 207 z = 0;
208 208
209 if (additive) 209 if (additive)
210 { 210 {
211 map[x, y] += z; 211 map[x, y] += z;
212 } 212 }
213 else 213 else
214 { 214 {
215 map[x, y] = Math.Max(map[x, y], z); 215 map[x, y] = Math.Max(map[x, y], z);
216 } 216 }
217 } 217 }
218 } 218 }
219 } 219 }
220 220
221 Normalise(); 221 Normalise();
222 } 222 }
223 223
224 public void HillsSquared(int number, double scale_min, double scale_range, bool island, bool additive, bool noisy) 224 public void HillsSquared(int number, double scale_min, double scale_range, bool island, bool additive, bool noisy)
225 { 225 {
226 SetDiff(); 226 SetDiff();
227 227
228 Random random = new Random(seed); 228 Random random = new Random(seed);
229 229
230 int x, y; 230 int x, y;
231 int i; 231 int i;
232 232
233 for (i = 0; i < number; i++) 233 for (i = 0; i < number; i++)
234 { 234 {
235 double rx = Math.Min(255.0, random.NextDouble() * w); 235 double rx = Math.Min(255.0, random.NextDouble() * w);
236 double ry = Math.Min(255.0, random.NextDouble() * h); 236 double ry = Math.Min(255.0, random.NextDouble() * h);
237 double rand = random.NextDouble(); 237 double rand = random.NextDouble();
238 238
239 if (island) 239 if (island)
240 { 240 {
241 // Move everything towards the center 241 // Move everything towards the center
242 rx -= w / 2; 242 rx -= w / 2;
243 rx /= 2; 243 rx /= 2;
244 rx += w / 2; 244 rx += w / 2;
245 245
246 ry -= h / 2; 246 ry -= h / 2;
247 ry /= 2; 247 ry /= 2;
248 ry += h / 2; 248 ry += h / 2;
249 } 249 }
250 250
251 for (x = 0; x < w; x++) 251 for (x = 0; x < w; x++)
252 { 252 {
253 for (y = 0; y < h; y++) 253 for (y = 0; y < h; y++)
254 { 254 {
255 if (noisy) 255 if (noisy)
256 rand = random.NextDouble(); 256 rand = random.NextDouble();
257 257
258 double z = (scale_min + (scale_range * rand)); 258 double z = (scale_min + (scale_range * rand));
259 z *= z * z * z; 259 z *= z * z * z;
260 double dx = Math.Abs(x - rx); 260 double dx = Math.Abs(x - rx);
261 double dy = Math.Abs(y - ry); 261 double dy = Math.Abs(y - ry);
262 z -= (dx * dx * dx * dx) + (dy * dy * dy * dy); 262 z -= (dx * dx * dx * dx) + (dy * dy * dy * dy);
263 263
264 if (z < 0) 264 if (z < 0)
265 z = 0; 265 z = 0;
266 266
267 if (additive) 267 if (additive)
268 { 268 {
269 map[x, y] += z; 269 map[x, y] += z;
270 } 270 }
271 else 271 else
272 { 272 {
273 map[x, y] = Math.Max(map[x, y], z); 273 map[x, y] = Math.Max(map[x, y], z);
274 } 274 }
275 } 275 }
276 } 276 }
277 } 277 }
278 278
279 Normalise(); 279 Normalise();
280 } 280 }
281 281
282 } 282 }
283} 283}
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Noise.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Noise.cs
index 3cefcfe..d40302c 100644
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Noise.cs
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Noise.cs
@@ -1,56 +1,56 @@
1/* 1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/ 2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders. 3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4* 4*
5* Redistribution and use in source and binary forms, with or without 5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met: 6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright 7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer. 8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright 9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the 10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution. 11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the 12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products 13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission. 14* derived from this software without specific prior written permission.
15* 15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY 16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26* 26*
27*/ 27*/
28 28
29using System; 29using System;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Text; 31using System.Text;
32 32
33namespace libTerrain 33namespace libTerrain
34{ 34{
35 partial class Channel 35 partial class Channel
36 { 36 {
37 /// <summary> 37 /// <summary>
38 /// Fills a channel with 0..1 noise 38 /// Fills a channel with 0..1 noise
39 /// </summary> 39 /// </summary>
40 /// <remarks>3-Clause BSD Licensed</remarks> 40 /// <remarks>3-Clause BSD Licensed</remarks>
41 public void Noise() 41 public void Noise()
42 { 42 {
43 SetDiff(); 43 SetDiff();
44 44
45 Random rand = new Random(seed); 45 Random rand = new Random(seed);
46 int x, y; 46 int x, y;
47 for (x = 0; x < w; x++) 47 for (x = 0; x < w; x++)
48 { 48 {
49 for (y = 0; y < h; y++) 49 for (y = 0; y < h; y++)
50 { 50 {
51 map[x, y] = rand.NextDouble(); 51 map[x, y] = rand.NextDouble();
52 } 52 }
53 } 53 }
54 } 54 }
55 } 55 }
56} 56}
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Spiral.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Spiral.cs
index 80abfe5..59d877a 100644
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Spiral.cs
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Spiral.cs
@@ -1,156 +1,156 @@
1/* 1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/ 2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders. 3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4* 4*
5* Redistribution and use in source and binary forms, with or without 5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met: 6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright 7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer. 8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright 9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the 10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution. 11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the 12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products 13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission. 14* derived from this software without specific prior written permission.
15* 15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY 16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26* 26*
27*/ 27*/
28 28
29using System; 29using System;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Text; 31using System.Text;
32 32
33namespace libTerrain 33namespace libTerrain
34{ 34{
35 partial class Channel 35 partial class Channel
36 { 36 {
37 private double[] CoordinatesToPolar(int x, int y) 37 private double[] CoordinatesToPolar(int x, int y)
38 { 38 {
39 double theta = Math.Atan2(x - (w / 2), y - (h / 2)); 39 double theta = Math.Atan2(x - (w / 2), y - (h / 2));
40 double rx = (double)x - ((double)w / 2); 40 double rx = (double)x - ((double)w / 2);
41 double ry = (double)y - ((double)h / 2); 41 double ry = (double)y - ((double)h / 2);
42 double r = Math.Sqrt((rx * rx) + (ry * ry)); 42 double r = Math.Sqrt((rx * rx) + (ry * ry));
43 43
44 double[] coords = new double[2]; 44 double[] coords = new double[2];
45 coords[0] = r; 45 coords[0] = r;
46 coords[1] = theta; 46 coords[1] = theta;
47 return coords; 47 return coords;
48 } 48 }
49 49
50 public int[] PolarToCoordinates(double r, double theta) { 50 public int[] PolarToCoordinates(double r, double theta) {
51 double nx; 51 double nx;
52 double ny; 52 double ny;
53 53
54 nx = (double)r * Math.Cos(theta); 54 nx = (double)r * Math.Cos(theta);
55 ny = (double)r * Math.Sin(theta); 55 ny = (double)r * Math.Sin(theta);
56 56
57 nx += w / 2; 57 nx += w / 2;
58 ny += h / 2; 58 ny += h / 2;
59 59
60 if (nx >= w) 60 if (nx >= w)
61 nx = w - 1; 61 nx = w - 1;
62 62
63 if (ny >= h) 63 if (ny >= h)
64 ny = h - 1; 64 ny = h - 1;
65 65
66 if (nx < 0) 66 if (nx < 0)
67 nx = 0; 67 nx = 0;
68 68
69 if (ny < 0) 69 if (ny < 0)
70 ny = 0; 70 ny = 0;
71 71
72 int[] coords = new int[2]; 72 int[] coords = new int[2];
73 coords[0] = (int)nx; 73 coords[0] = (int)nx;
74 coords[1] = (int)ny; 74 coords[1] = (int)ny;
75 return coords; 75 return coords;
76 } 76 }
77 77
78 public void Polar() 78 public void Polar()
79 { 79 {
80 SetDiff(); 80 SetDiff();
81 81
82 Channel n = this.Copy(); 82 Channel n = this.Copy();
83 83
84 int x, y; 84 int x, y;
85 for (x = 0; x < w; x++) 85 for (x = 0; x < w; x++)
86 { 86 {
87 for (y = 0; y < h; y++) 87 for (y = 0; y < h; y++)
88 { 88 {
89 double[] coords = CoordinatesToPolar(x,y); 89 double[] coords = CoordinatesToPolar(x,y);
90 90
91 coords[0] += w / 2.0; 91 coords[0] += w / 2.0;
92 coords[1] += h / 2.0; 92 coords[1] += h / 2.0;
93 93
94 map[x, y] = n.map[(int)coords[0] % n.w, (int)coords[1] % n.h]; 94 map[x, y] = n.map[(int)coords[0] % n.w, (int)coords[1] % n.h];
95 } 95 }
96 } 96 }
97 } 97 }
98 98
99 public void SpiralPlanter(int steps, double incAngle, double incRadius, double offsetRadius, double offsetAngle) 99 public void SpiralPlanter(int steps, double incAngle, double incRadius, double offsetRadius, double offsetAngle)
100 { 100 {
101 SetDiff(); 101 SetDiff();
102 102
103 int i; 103 int i;
104 double r = offsetRadius; 104 double r = offsetRadius;
105 double theta = offsetAngle; 105 double theta = offsetAngle;
106 for (i = 0; i < steps; i++) 106 for (i = 0; i < steps; i++)
107 { 107 {
108 r += incRadius; 108 r += incRadius;
109 theta += incAngle; 109 theta += incAngle;
110 110
111 int[] coords = PolarToCoordinates(r,theta); 111 int[] coords = PolarToCoordinates(r,theta);
112 Raise(coords[0], coords[1], 20, 1); 112 Raise(coords[0], coords[1], 20, 1);
113 } 113 }
114 } 114 }
115 115
116 public void SpiralCells(int steps, double incAngle, double incRadius, double offsetRadius, double offsetAngle, double[] c) 116 public void SpiralCells(int steps, double incAngle, double incRadius, double offsetRadius, double offsetAngle, double[] c)
117 { 117 {
118 SetDiff(); 118 SetDiff();
119 119
120 List<Point2D> points = new List<Point2D>(); 120 List<Point2D> points = new List<Point2D>();
121 121
122 int i; 122 int i;
123 double r = offsetRadius; 123 double r = offsetRadius;
124 double theta = offsetAngle; 124 double theta = offsetAngle;
125 for (i = 0; i < steps; i++) 125 for (i = 0; i < steps; i++)
126 { 126 {
127 r += incRadius; 127 r += incRadius;
128 theta += incAngle; 128 theta += incAngle;
129 129
130 int[] coords = PolarToCoordinates(r, theta); 130 int[] coords = PolarToCoordinates(r, theta);
131 points.Add(new Point2D(coords[0],coords[1])); 131 points.Add(new Point2D(coords[0],coords[1]));
132 } 132 }
133 133
134 VoronoiDiagram(points, c); 134 VoronoiDiagram(points, c);
135 } 135 }
136 136
137 public void Spiral(double wid, double hig, double offset) 137 public void Spiral(double wid, double hig, double offset)
138 { 138 {
139 SetDiff(); 139 SetDiff();
140 140
141 int x, y, z; 141 int x, y, z;
142 z = 0; 142 z = 0;
143 for (x = 0; x < w; x++) 143 for (x = 0; x < w; x++)
144 { 144 {
145 for (y = 0; y < h; y++) 145 for (y = 0; y < h; y++)
146 { 146 {
147 z++; 147 z++;
148 double dx = Math.Abs((w / 2) - x); 148 double dx = Math.Abs((w / 2) - x);
149 double dy = Math.Abs((h / 2) - y); 149 double dy = Math.Abs((h / 2) - y);
150 map[x, y] += Math.Sin(dx / wid) + Math.Cos(dy / hig); 150 map[x, y] += Math.Sin(dx / wid) + Math.Cos(dy / hig);
151 } 151 }
152 } 152 }
153 Normalise(); 153 Normalise();
154 } 154 }
155 } 155 }
156} \ No newline at end of file 156} \ No newline at end of file
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Voronoi.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Voronoi.cs
index eb8f7ba..3411ccf 100644
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Voronoi.cs
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Voronoi.cs
@@ -1,214 +1,214 @@
1/* 1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/ 2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders. 3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4* 4*
5* Redistribution and use in source and binary forms, with or without 5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met: 6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright 7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer. 8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright 9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the 10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution. 11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the 12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products 13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission. 14* derived from this software without specific prior written permission.
15* 15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY 16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26* 26*
27*/ 27*/
28 28
29using System; 29using System;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Text; 31using System.Text;
32 32
33namespace libTerrain 33namespace libTerrain
34{ 34{
35 partial class Channel 35 partial class Channel
36 { 36 {
37 /// <summary> 37 /// <summary>
38 /// Generates a Voronoi diagram (sort of a stained glass effect) which will fill the entire channel 38 /// Generates a Voronoi diagram (sort of a stained glass effect) which will fill the entire channel
39 /// </summary> 39 /// </summary>
40 /// <remarks>3-Clause BSD Licensed</remarks> 40 /// <remarks>3-Clause BSD Licensed</remarks>
41 /// <param name="pointsPerBlock">The number of generator points in each block</param> 41 /// <param name="pointsPerBlock">The number of generator points in each block</param>
42 /// <param name="blockSize">A multiple of the channel width and height which will have voronoi points generated in it. 42 /// <param name="blockSize">A multiple of the channel width and height which will have voronoi points generated in it.
43 /// <para>This is to ensure a more even distribution of the points than pure random allocation.</para></param> 43 /// <para>This is to ensure a more even distribution of the points than pure random allocation.</para></param>
44 /// <param name="c">The Voronoi diagram type. Usually an array with values consisting of [-1,1]. Experiment with the chain, you can have as many values as you like.</param> 44 /// <param name="c">The Voronoi diagram type. Usually an array with values consisting of [-1,1]. Experiment with the chain, you can have as many values as you like.</param>
45 public void VoronoiDiagram(int pointsPerBlock, int blockSize, double[] c) 45 public void VoronoiDiagram(int pointsPerBlock, int blockSize, double[] c)
46 { 46 {
47 SetDiff(); 47 SetDiff();
48 48
49 List<Point2D> points = new List<Point2D>(); 49 List<Point2D> points = new List<Point2D>();
50 Random generator = new Random(seed); 50 Random generator = new Random(seed);
51 51
52 // Generate the emitter points 52 // Generate the emitter points
53 int x, y, i; 53 int x, y, i;
54 for (x = -blockSize; x < w + blockSize; x += blockSize) 54 for (x = -blockSize; x < w + blockSize; x += blockSize)
55 { 55 {
56 for (y = -blockSize; y < h + blockSize; y += blockSize) 56 for (y = -blockSize; y < h + blockSize; y += blockSize)
57 { 57 {
58 for (i = 0; i < pointsPerBlock; i++) 58 for (i = 0; i < pointsPerBlock; i++)
59 { 59 {
60 double pX = x + (generator.NextDouble() * (double)blockSize); 60 double pX = x + (generator.NextDouble() * (double)blockSize);
61 double pY = y + (generator.NextDouble() * (double)blockSize); 61 double pY = y + (generator.NextDouble() * (double)blockSize);
62 62
63 points.Add(new Point2D(pX, pY)); 63 points.Add(new Point2D(pX, pY));
64 } 64 }
65 } 65 }
66 } 66 }
67 67
68 double[] distances = new double[points.Count]; 68 double[] distances = new double[points.Count];
69 69
70 // Calculate the distance each pixel is from an emitter 70 // Calculate the distance each pixel is from an emitter
71 for (x = 0; x < w; x++) 71 for (x = 0; x < w; x++)
72 { 72 {
73 for (y = 0; y < h; y++) 73 for (y = 0; y < h; y++)
74 { 74 {
75 for (i = 0; i < points.Count; i++) 75 for (i = 0; i < points.Count; i++)
76 { 76 {
77 double dx, dy; 77 double dx, dy;
78 dx = Math.Abs((double)x - points[i].x); 78 dx = Math.Abs((double)x - points[i].x);
79 dy = Math.Abs((double)y - points[i].y); 79 dy = Math.Abs((double)y - points[i].y);
80 80
81 distances[i] = (dx * dx + dy * dy); 81 distances[i] = (dx * dx + dy * dy);
82 } 82 }
83 83
84 Array.Sort(distances); 84 Array.Sort(distances);
85 85
86 double f = 0.0; 86 double f = 0.0;
87 87
88 // Multiply the distances with their 'c' counterpart 88 // Multiply the distances with their 'c' counterpart
89 // ordering the distances descending 89 // ordering the distances descending
90 for (i = 0; i < c.Length; i++) 90 for (i = 0; i < c.Length; i++)
91 { 91 {
92 if (i >= points.Count) 92 if (i >= points.Count)
93 break; 93 break;
94 94
95 f += c[i] * distances[i]; 95 f += c[i] * distances[i];
96 } 96 }
97 97
98 map[x, y] = f; 98 map[x, y] = f;
99 } 99 }
100 } 100 }
101 101
102 // Normalise the result 102 // Normalise the result
103 Normalise(); 103 Normalise();
104 } 104 }
105 105
106 public void VoronoiDiagram(List<Point2D> points, double[] c) 106 public void VoronoiDiagram(List<Point2D> points, double[] c)
107 { 107 {
108 SetDiff(); 108 SetDiff();
109 109
110 Random generator = new Random(seed); 110 Random generator = new Random(seed);
111 int x, y, i; 111 int x, y, i;
112 double[] distances = new double[points.Count]; 112 double[] distances = new double[points.Count];
113 113
114 // Calculate the distance each pixel is from an emitter 114 // Calculate the distance each pixel is from an emitter
115 for (x = 0; x < w; x++) 115 for (x = 0; x < w; x++)
116 { 116 {
117 for (y = 0; y < h; y++) 117 for (y = 0; y < h; y++)
118 { 118 {
119 for (i = 0; i < points.Count; i++) 119 for (i = 0; i < points.Count; i++)
120 { 120 {
121 double dx, dy; 121 double dx, dy;
122 dx = Math.Abs((double)x - points[i].x); 122 dx = Math.Abs((double)x - points[i].x);
123 dy = Math.Abs((double)y - points[i].y); 123 dy = Math.Abs((double)y - points[i].y);
124 124
125 distances[i] = (dx * dx + dy * dy); 125 distances[i] = (dx * dx + dy * dy);
126 } 126 }
127 127
128 Array.Sort(distances); 128 Array.Sort(distances);
129 129
130 double f = 0.0; 130 double f = 0.0;
131 131
132 // Multiply the distances with their 'c' counterpart 132 // Multiply the distances with their 'c' counterpart
133 // ordering the distances descending 133 // ordering the distances descending
134 for (i = 0; i < c.Length; i++) 134 for (i = 0; i < c.Length; i++)
135 { 135 {
136 if (i >= points.Count) 136 if (i >= points.Count)
137 break; 137 break;
138 138
139 f += c[i] * distances[i]; 139 f += c[i] * distances[i];
140 } 140 }
141 141
142 map[x, y] = f; 142 map[x, y] = f;
143 } 143 }
144 } 144 }
145 145
146 // Normalise the result 146 // Normalise the result
147 Normalise(); 147 Normalise();
148 } 148 }
149 149
150 public void VoroflatDiagram(int pointsPerBlock, int blockSize) 150 public void VoroflatDiagram(int pointsPerBlock, int blockSize)
151 { 151 {
152 SetDiff(); 152 SetDiff();
153 153
154 List<Point2D> points = new List<Point2D>(); 154 List<Point2D> points = new List<Point2D>();
155 Random generator = new Random(seed); 155 Random generator = new Random(seed);
156 156
157 // Generate the emitter points 157 // Generate the emitter points
158 int x, y, i; 158 int x, y, i;
159 for (x = -blockSize; x < w + blockSize; x += blockSize) 159 for (x = -blockSize; x < w + blockSize; x += blockSize)
160 { 160 {
161 for (y = -blockSize; y < h + blockSize; y += blockSize) 161 for (y = -blockSize; y < h + blockSize; y += blockSize)
162 { 162 {
163 for (i = 0; i < pointsPerBlock; i++) 163 for (i = 0; i < pointsPerBlock; i++)
164 { 164 {
165 double pX = x + (generator.NextDouble() * (double)blockSize); 165 double pX = x + (generator.NextDouble() * (double)blockSize);
166 double pY = y + (generator.NextDouble() * (double)blockSize); 166 double pY = y + (generator.NextDouble() * (double)blockSize);
167 167
168 points.Add(new Point2D(pX, pY)); 168 points.Add(new Point2D(pX, pY));
169 } 169 }
170 } 170 }
171 } 171 }
172 172
173 double[] distances = new double[points.Count]; 173 double[] distances = new double[points.Count];
174 174
175 // Calculate the distance each pixel is from an emitter 175 // Calculate the distance each pixel is from an emitter
176 for (x = 0; x < w; x++) 176 for (x = 0; x < w; x++)
177 { 177 {
178 for (y = 0; y < h; y++) 178 for (y = 0; y < h; y++)
179 { 179 {
180 for (i = 0; i < points.Count; i++) 180 for (i = 0; i < points.Count; i++)
181 { 181 {
182 double dx, dy; 182 double dx, dy;
183 dx = Math.Abs((double)x - points[i].x); 183 dx = Math.Abs((double)x - points[i].x);
184 dy = Math.Abs((double)y - points[i].y); 184 dy = Math.Abs((double)y - points[i].y);
185 185
186 distances[i] = (dx * dx + dy * dy); 186 distances[i] = (dx * dx + dy * dy);
187 } 187 }
188 188
189 //Array.Sort(distances); 189 //Array.Sort(distances);
190 190
191 double f = 0.0; 191 double f = 0.0;
192 192
193 double min = double.MaxValue; 193 double min = double.MaxValue;
194 for (int j = 0; j < distances.Length;j++ ) 194 for (int j = 0; j < distances.Length;j++ )
195 { 195 {
196 if (distances[j] < min) 196 if (distances[j] < min)
197 { 197 {
198 min = distances[j]; 198 min = distances[j];
199 f = j; 199 f = j;
200 } 200 }
201 } 201 }
202 202
203 // Multiply the distances with their 'c' counterpart 203 // Multiply the distances with their 'c' counterpart
204 // ordering the distances descending 204 // ordering the distances descending
205 205
206 map[x, y] = f; 206 map[x, y] = f;
207 } 207 }
208 } 208 }
209 209
210 // Normalise the result 210 // Normalise the result
211 Normalise(); 211 Normalise();
212 } 212 }
213 } 213 }
214} 214}
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Worms.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Worms.cs
index ce36daf..ba2fad6 100644
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Worms.cs
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Worms.cs
@@ -1,74 +1,74 @@
1/* 1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/ 2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders. 3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4* 4*
5* Redistribution and use in source and binary forms, with or without 5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met: 6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright 7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer. 8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright 9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the 10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution. 11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the 12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products 13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission. 14* derived from this software without specific prior written permission.
15* 15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY 16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26* 26*
27*/ 27*/
28 28
29using System; 29using System;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Text; 31using System.Text;
32 32
33namespace libTerrain 33namespace libTerrain
34{ 34{
35 partial class Channel 35 partial class Channel
36 { 36 {
37 /// <summary> 37 /// <summary>
38 /// Generates 'number' of worms which navigate randomly around the landscape creating terrain as they go. 38 /// Generates 'number' of worms which navigate randomly around the landscape creating terrain as they go.
39 /// </summary> 39 /// </summary>
40 /// <param name="number">The number of worms which will traverse the map</param> 40 /// <param name="number">The number of worms which will traverse the map</param>
41 /// <param name="rounds">The number of steps each worm will traverse</param> 41 /// <param name="rounds">The number of steps each worm will traverse</param>
42 /// <param name="movement">The maximum distance each worm will move each step</param> 42 /// <param name="movement">The maximum distance each worm will move each step</param>
43 /// <param name="size">The size of the area around the worm modified</param> 43 /// <param name="size">The size of the area around the worm modified</param>
44 /// <param name="centerspawn">Do worms start in the middle, or randomly?</param> 44 /// <param name="centerspawn">Do worms start in the middle, or randomly?</param>
45 public void Worms(int number, int rounds, double movement, double size, bool centerspawn) 45 public void Worms(int number, int rounds, double movement, double size, bool centerspawn)
46 { 46 {
47 SetDiff(); 47 SetDiff();
48 48
49 Random random = new Random(seed); 49 Random random = new Random(seed);
50 int i, j; 50 int i, j;
51 51
52 for (i = 0; i < number; i++) 52 for (i = 0; i < number; i++)
53 { 53 {
54 double rx, ry; 54 double rx, ry;
55 if (centerspawn) 55 if (centerspawn)
56 { 56 {
57 rx = w / 2.0; 57 rx = w / 2.0;
58 ry = h / 2.0; 58 ry = h / 2.0;
59 } 59 }
60 else 60 else
61 { 61 {
62 rx = random.NextDouble() * (w - 1); 62 rx = random.NextDouble() * (w - 1);
63 ry = random.NextDouble() * (h - 1); 63 ry = random.NextDouble() * (h - 1);
64 } 64 }
65 for (j = 0; j < rounds; j++) 65 for (j = 0; j < rounds; j++)
66 { 66 {
67 rx += (random.NextDouble() * movement) - (movement / 2.0); 67 rx += (random.NextDouble() * movement) - (movement / 2.0);
68 ry += (random.NextDouble() * movement) - (movement / 2.0); 68 ry += (random.NextDouble() * movement) - (movement / 2.0);
69 Raise(rx, ry, size, 1.0); 69 Raise(rx, ry, size, 1.0);
70 } 70 }
71 } 71 }
72 } 72 }
73 } 73 }
74} \ No newline at end of file 74} \ No newline at end of file
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Grid.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Grid.cs
index e6b18f4..18e40b5 100644
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Grid.cs
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Grid.cs
@@ -1,350 +1,350 @@
1/* 1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/ 2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders. 3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4* 4*
5* Redistribution and use in source and binary forms, with or without 5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met: 6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright 7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer. 8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright 9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the 10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution. 11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the 12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products 13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission. 14* derived from this software without specific prior written permission.
15* 15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY 16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26* 26*
27*/ 27*/
28 28
29using System; 29using System;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Text; 31using System.Text;
32 32
33namespace libTerrain 33namespace libTerrain
34{ 34{
35 partial class Channel 35 partial class Channel
36 { 36 {
37 public Channel Normalise() 37 public Channel Normalise()
38 { 38 {
39 SetDiff(); 39 SetDiff();
40 40
41 double max = FindMax(); 41 double max = FindMax();
42 double min = FindMin(); 42 double min = FindMin();
43 43
44 int x, y; 44 int x, y;
45 45
46 if (max != min) 46 if (max != min)
47 { 47 {
48 for (x = 0; x < w; x++) 48 for (x = 0; x < w; x++)
49 { 49 {
50 for (y = 0; y < h; y++) 50 for (y = 0; y < h; y++)
51 { 51 {
52 map[x, y] = (map[x, y] - min) * (1.0 / (max - min)); 52 map[x, y] = (map[x, y] - min) * (1.0 / (max - min));
53 } 53 }
54 } 54 }
55 } 55 }
56 else 56 else
57 { 57 {
58 this.Fill(0.5); 58 this.Fill(0.5);
59 } 59 }
60 60
61 return this; 61 return this;
62 } 62 }
63 63
64 public Channel Normalise(double minv, double maxv) 64 public Channel Normalise(double minv, double maxv)
65 { 65 {
66 SetDiff(); 66 SetDiff();
67 67
68 double max = FindMax(); 68 double max = FindMax();
69 double min = FindMin(); 69 double min = FindMin();
70 70
71 int x, y; 71 int x, y;
72 72
73 for (x = 0; x < w; x++) 73 for (x = 0; x < w; x++)
74 { 74 {
75 for (y = 0; y < h; y++) 75 for (y = 0; y < h; y++)
76 { 76 {
77 double val = (map[x, y] - min) * (1.0 / max - min); 77 double val = (map[x, y] - min) * (1.0 / max - min);
78 val *= maxv - minv; 78 val *= maxv - minv;
79 val += minv; 79 val += minv;
80 80
81 map[x, y] = val; 81 map[x, y] = val;
82 } 82 }
83 } 83 }
84 84
85 return this; 85 return this;
86 } 86 }
87 87
88 public Channel Clip() 88 public Channel Clip()
89 { 89 {
90 int x, y; 90 int x, y;
91 91
92 for (x = 0; x < w; x++) 92 for (x = 0; x < w; x++)
93 { 93 {
94 for (y = 0; y < h; y++) 94 for (y = 0; y < h; y++)
95 { 95 {
96 SetClip(x, y, map[x, y]); 96 SetClip(x, y, map[x, y]);
97 } 97 }
98 } 98 }
99 99
100 return this; 100 return this;
101 } 101 }
102 102
103 public Channel Clip(double min, double max) 103 public Channel Clip(double min, double max)
104 { 104 {
105 int x, y; 105 int x, y;
106 for (x = 0; x < w; x++) 106 for (x = 0; x < w; x++)
107 { 107 {
108 for (y = 0; y < h; y++) 108 for (y = 0; y < h; y++)
109 { 109 {
110 double val = map[x, y]; 110 double val = map[x, y];
111 if (val > max) val = max; 111 if (val > max) val = max;
112 if (val < min) val = min; 112 if (val < min) val = min;
113 113
114 Set(x, y, val); 114 Set(x, y, val);
115 } 115 }
116 } 116 }
117 return this; 117 return this;
118 } 118 }
119 119
120 public Channel Crop(int x1, int y1, int x2, int y2) 120 public Channel Crop(int x1, int y1, int x2, int y2)
121 { 121 {
122 int width = x1 - x2 + 1; 122 int width = x1 - x2 + 1;
123 int height = y1 - y2 + 1; 123 int height = y1 - y2 + 1;
124 Channel chan = new Channel(width, height); 124 Channel chan = new Channel(width, height);
125 125
126 int x, y; 126 int x, y;
127 int nx, ny; 127 int nx, ny;
128 128
129 nx = 0; 129 nx = 0;
130 for (x = x1; x < x2; x++) 130 for (x = x1; x < x2; x++)
131 { 131 {
132 ny = 0; 132 ny = 0;
133 for (y = y1; y < y2; y++) 133 for (y = y1; y < y2; y++)
134 { 134 {
135 chan.map[nx, ny] = map[x, y]; 135 chan.map[nx, ny] = map[x, y];
136 136
137 ny++; 137 ny++;
138 } 138 }
139 nx++; 139 nx++;
140 } 140 }
141 141
142 return this; 142 return this;
143 } 143 }
144 144
145 public Channel AddClip(Channel other) 145 public Channel AddClip(Channel other)
146 { 146 {
147 SetDiff(); 147 SetDiff();
148 148
149 int x, y; 149 int x, y;
150 for (x = 0; x < w; x++) 150 for (x = 0; x < w; x++)
151 { 151 {
152 for (y = 0; y < h; y++) 152 for (y = 0; y < h; y++)
153 { 153 {
154 map[x, y] = other.map[x, y]; 154 map[x, y] = other.map[x, y];
155 if (map[x, y] > 1) 155 if (map[x, y] > 1)
156 map[x, y] = 1; 156 map[x, y] = 1;
157 if (map[x, y] < 0) 157 if (map[x, y] < 0)
158 map[x, y] = 0; 158 map[x, y] = 0;
159 } 159 }
160 } 160 }
161 return this; 161 return this;
162 } 162 }
163 163
164 public void Smooth(double amount) 164 public void Smooth(double amount)
165 { 165 {
166 SetDiff(); 166 SetDiff();
167 167
168 double area = amount; 168 double area = amount;
169 double step = amount / 4.0; 169 double step = amount / 4.0;
170 170
171 double[,] manipulate = new double[w, h]; 171 double[,] manipulate = new double[w, h];
172 int x, y; 172 int x, y;
173 double n, l; 173 double n, l;
174 for (x = 0; x < w; x++) 174 for (x = 0; x < w; x++)
175 { 175 {
176 for (y = 0; y < h; y++) 176 for (y = 0; y < h; y++)
177 { 177 {
178 double average = 0.0; 178 double average = 0.0;
179 int avgsteps = 0; 179 int avgsteps = 0;
180 180
181 for (n = 0.0 - area; n < area; n += step) 181 for (n = 0.0 - area; n < area; n += step)
182 { 182 {
183 for (l = 0.0 - area; l < area; l += step) 183 for (l = 0.0 - area; l < area; l += step)
184 { 184 {
185 avgsteps++; 185 avgsteps++;
186 average += GetBilinearInterpolate(x + n, y + l); 186 average += GetBilinearInterpolate(x + n, y + l);
187 } 187 }
188 } 188 }
189 189
190 manipulate[x, y] = average / avgsteps; 190 manipulate[x, y] = average / avgsteps;
191 } 191 }
192 } 192 }
193 map = manipulate; 193 map = manipulate;
194 } 194 }
195 195
196 public void Pertubation(double amount) 196 public void Pertubation(double amount)
197 { 197 {
198 SetDiff(); 198 SetDiff();
199 199
200 // Simple pertubation filter 200 // Simple pertubation filter
201 double[,] manipulated = new double[w, h]; 201 double[,] manipulated = new double[w, h];
202 Random generator = new Random(seed); // Seeds FTW! 202 Random generator = new Random(seed); // Seeds FTW!
203 //double amount = 8.0; 203 //double amount = 8.0;
204 204
205 int x, y; 205 int x, y;
206 for (x = 0; x < w; x++) 206 for (x = 0; x < w; x++)
207 { 207 {
208 for (y = 0; y < h; y++) 208 for (y = 0; y < h; y++)
209 { 209 {
210 double offset_x = (double)x + (generator.NextDouble() * amount) - (amount / 2.0); 210 double offset_x = (double)x + (generator.NextDouble() * amount) - (amount / 2.0);
211 double offset_y = (double)y + (generator.NextDouble() * amount) - (amount / 2.0); 211 double offset_y = (double)y + (generator.NextDouble() * amount) - (amount / 2.0);
212 double p = GetBilinearInterpolate(offset_x, offset_y); 212 double p = GetBilinearInterpolate(offset_x, offset_y);
213 manipulated[x, y] = p; 213 manipulated[x, y] = p;
214 } 214 }
215 } 215 }
216 map = manipulated; 216 map = manipulated;
217 } 217 }
218 218
219 public void PertubationMask(Channel mask) 219 public void PertubationMask(Channel mask)
220 { 220 {
221 // Simple pertubation filter 221 // Simple pertubation filter
222 double[,] manipulated = new double[w, h]; 222 double[,] manipulated = new double[w, h];
223 Random generator = new Random(seed); // Seeds FTW! 223 Random generator = new Random(seed); // Seeds FTW!
224 //double amount = 8.0; 224 //double amount = 8.0;
225 225
226 double amount; 226 double amount;
227 227
228 int x, y; 228 int x, y;
229 for (x = 0; x < w; x++) 229 for (x = 0; x < w; x++)
230 { 230 {
231 for (y = 0; y < h; y++) 231 for (y = 0; y < h; y++)
232 { 232 {
233 amount = mask.map[x, y]; 233 amount = mask.map[x, y];
234 double offset_x = (double)x + (generator.NextDouble() * amount) - (amount / 2.0); 234 double offset_x = (double)x + (generator.NextDouble() * amount) - (amount / 2.0);
235 double offset_y = (double)y + (generator.NextDouble() * amount) - (amount / 2.0); 235 double offset_y = (double)y + (generator.NextDouble() * amount) - (amount / 2.0);
236 236
237 if (offset_x > w) 237 if (offset_x > w)
238 offset_x = w - 1; 238 offset_x = w - 1;
239 if (offset_y > h) 239 if (offset_y > h)
240 offset_y = h - 1; 240 offset_y = h - 1;
241 if (offset_y < 0) 241 if (offset_y < 0)
242 offset_y = 0; 242 offset_y = 0;
243 if (offset_x < 0) 243 if (offset_x < 0)
244 offset_x = 0; 244 offset_x = 0;
245 245
246 double p = GetBilinearInterpolate(offset_x, offset_y); 246 double p = GetBilinearInterpolate(offset_x, offset_y);
247 manipulated[x, y] = p; 247 manipulated[x, y] = p;
248 SetDiff(x, y); 248 SetDiff(x, y);
249 } 249 }
250 } 250 }
251 map = manipulated; 251 map = manipulated;
252 } 252 }
253 253
254 public void Distort(Channel mask, double str) 254 public void Distort(Channel mask, double str)
255 { 255 {
256 // Simple pertubation filter 256 // Simple pertubation filter
257 double[,] manipulated = new double[w, h]; 257 double[,] manipulated = new double[w, h];
258 258
259 double amount; 259 double amount;
260 260
261 int x, y; 261 int x, y;
262 for (x = 0; x < w; x++) 262 for (x = 0; x < w; x++)
263 { 263 {
264 for (y = 0; y < h; y++) 264 for (y = 0; y < h; y++)
265 { 265 {
266 amount = mask.map[x, y]; 266 amount = mask.map[x, y];
267 double offset_x = (double)x + (amount * str) - (0.5 * str); 267 double offset_x = (double)x + (amount * str) - (0.5 * str);
268 double offset_y = (double)y + (amount * str) - (0.5 * str); 268 double offset_y = (double)y + (amount * str) - (0.5 * str);
269 269
270 if (offset_x > w) 270 if (offset_x > w)
271 offset_x = w - 1; 271 offset_x = w - 1;
272 if (offset_y > h) 272 if (offset_y > h)
273 offset_y = h - 1; 273 offset_y = h - 1;
274 if (offset_y < 0) 274 if (offset_y < 0)
275 offset_y = 0; 275 offset_y = 0;
276 if (offset_x < 0) 276 if (offset_x < 0)
277 offset_x = 0; 277 offset_x = 0;
278 278
279 double p = GetBilinearInterpolate(offset_x, offset_y); 279 double p = GetBilinearInterpolate(offset_x, offset_y);
280 manipulated[x, y] = p; 280 manipulated[x, y] = p;
281 SetDiff(x, y); 281 SetDiff(x, y);
282 } 282 }
283 } 283 }
284 map = manipulated; 284 map = manipulated;
285 285
286 } 286 }
287 287
288 public void Distort(Channel mask, Channel mask2, double str) 288 public void Distort(Channel mask, Channel mask2, double str)
289 { 289 {
290 // Simple pertubation filter 290 // Simple pertubation filter
291 double[,] manipulated = new double[w, h]; 291 double[,] manipulated = new double[w, h];
292 292
293 double amountX; 293 double amountX;
294 double amountY; 294 double amountY;
295 295
296 int x, y; 296 int x, y;
297 for (x = 0; x < w; x++) 297 for (x = 0; x < w; x++)
298 { 298 {
299 for (y = 0; y < h; y++) 299 for (y = 0; y < h; y++)
300 { 300 {
301 amountX = mask.map[x, y]; 301 amountX = mask.map[x, y];
302 amountY = mask2.map[x, y]; 302 amountY = mask2.map[x, y];
303 double offset_x = (double)x + (amountX * str) - (0.5 * str); 303 double offset_x = (double)x + (amountX * str) - (0.5 * str);
304 double offset_y = (double)y + (amountY * str) - (0.5 * str); 304 double offset_y = (double)y + (amountY * str) - (0.5 * str);
305 305
306 if (offset_x > w) 306 if (offset_x > w)
307 offset_x = w - 1; 307 offset_x = w - 1;
308 if (offset_y > h) 308 if (offset_y > h)
309 offset_y = h - 1; 309 offset_y = h - 1;
310 if (offset_y < 0) 310 if (offset_y < 0)
311 offset_y = 0; 311 offset_y = 0;
312 if (offset_x < 0) 312 if (offset_x < 0)
313 offset_x = 0; 313 offset_x = 0;
314 314
315 double p = GetBilinearInterpolate(offset_x, offset_y); 315 double p = GetBilinearInterpolate(offset_x, offset_y);
316 manipulated[x, y] = p; 316 manipulated[x, y] = p;
317 SetDiff(x, y); 317 SetDiff(x, y);
318 } 318 }
319 } 319 }
320 map = manipulated; 320 map = manipulated;
321 321
322 } 322 }
323 323
324 public Channel Blend(Channel other, double amount) 324 public Channel Blend(Channel other, double amount)
325 { 325 {
326 int x, y; 326 int x, y;
327 for (x = 0; x < w; x++) 327 for (x = 0; x < w; x++)
328 { 328 {
329 for (y = 0; y < h; y++) 329 for (y = 0; y < h; y++)
330 { 330 {
331 Set(x, y, Tools.linearInterpolate(map[x, y], other.map[x, y], amount)); 331 Set(x, y, Tools.linearInterpolate(map[x, y], other.map[x, y], amount));
332 } 332 }
333 } 333 }
334 return this; 334 return this;
335 } 335 }
336 336
337 public Channel Blend(Channel other, Channel amount) 337 public Channel Blend(Channel other, Channel amount)
338 { 338 {
339 int x, y; 339 int x, y;
340 for (x = 0; x < w; x++) 340 for (x = 0; x < w; x++)
341 { 341 {
342 for (y = 0; y < h; y++) 342 for (y = 0; y < h; y++)
343 { 343 {
344 Set(x, y, Tools.linearInterpolate(map[x, y], other.map[x, y], amount.map[x, y])); 344 Set(x, y, Tools.linearInterpolate(map[x, y], other.map[x, y], amount.map[x, y]));
345 } 345 }
346 } 346 }
347 return this; 347 return this;
348 } 348 }
349 } 349 }
350} 350}
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/AerobicErosion.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/AerobicErosion.cs
index 589d360..5d2b4d4 100644
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/AerobicErosion.cs
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/AerobicErosion.cs
@@ -1,213 +1,213 @@
1/* 1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/ 2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders. 3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4* 4*
5* Redistribution and use in source and binary forms, with or without 5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met: 6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright 7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer. 8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright 9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the 10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution. 11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the 12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products 13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission. 14* derived from this software without specific prior written permission.
15* 15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY 16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26* 26*
27*/ 27*/
28 28
29using System; 29using System;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Text; 31using System.Text;
32 32
33namespace libTerrain 33namespace libTerrain
34{ 34{
35 partial class Channel 35 partial class Channel
36 { 36 {
37 // Ideas for Aerobic erosion 37 // Ideas for Aerobic erosion
38 // 38 //
39 // Unlike thermal (gravity) and hydraulic (water suspension) 39 // Unlike thermal (gravity) and hydraulic (water suspension)
40 // aerobic erosion should displace mass by moving sediment 40 // aerobic erosion should displace mass by moving sediment
41 // in "hops". The length of the hop being dictated by the 41 // in "hops". The length of the hop being dictated by the
42 // presence of sharp cliffs and wind speed. 42 // presence of sharp cliffs and wind speed.
43 43
44 // The ability to pickup sediment is defined by the total 44 // The ability to pickup sediment is defined by the total
45 // surface area, such that: 45 // surface area, such that:
46 // 0 0 0 46 // 0 0 0
47 // 0 1 0 47 // 0 1 0
48 // 0 0 0 48 // 0 0 0
49 // Would be the best possible value for sediment to be 49 // Would be the best possible value for sediment to be
50 // picked up (total difference = 8) and flatter land 50 // picked up (total difference = 8) and flatter land
51 // will erode less quickly. 51 // will erode less quickly.
52 52
53 // Suspended particles assist the erosion process by hitting 53 // Suspended particles assist the erosion process by hitting
54 // the surface and chiselling additional particles off faster 54 // the surface and chiselling additional particles off faster
55 // than alone. 55 // than alone.
56 56
57 // Particles are deposited when one of two conditions is met 57 // Particles are deposited when one of two conditions is met
58 // First: 58 // First:
59 // When particles hit a wall - such that the 59 // When particles hit a wall - such that the
60 // wind direction points at a difference >= the 60 // wind direction points at a difference >= the
61 // deposition mininum talus. 61 // deposition mininum talus.
62 // Second: 62 // Second:
63 // When wind speed is lowered to below the minimum 63 // When wind speed is lowered to below the minimum
64 // required for transit. An idea for this is to 64 // required for transit. An idea for this is to
65 // use the navier-stokes algorithms for simulating 65 // use the navier-stokes algorithms for simulating
66 // pressure across the terrain. 66 // pressure across the terrain.
67 67
68 /// <summary> 68 /// <summary>
69 /// An experimental erosion algorithm developed by Adam. Moves sediment by factoring the surface area of each height point. 69 /// An experimental erosion algorithm developed by Adam. Moves sediment by factoring the surface area of each height point.
70 /// </summary> 70 /// </summary>
71 /// <param name="windspeed">0..1 The speed of the wind</param> 71 /// <param name="windspeed">0..1 The speed of the wind</param>
72 /// <param name="pickup_talus_minimum">The minimum angle at which rock is eroded 0..1 (recommended: <= 0.30)</param> 72 /// <param name="pickup_talus_minimum">The minimum angle at which rock is eroded 0..1 (recommended: <= 0.30)</param>
73 /// <param name="drop_talus_minimum">The minimum angle at which rock is dropped 0..1 (recommended: >= 0.00)</param> 73 /// <param name="drop_talus_minimum">The minimum angle at which rock is dropped 0..1 (recommended: >= 0.00)</param>
74 /// <param name="carry">The percentage of rock which can be picked up to pickup 0..1</param> 74 /// <param name="carry">The percentage of rock which can be picked up to pickup 0..1</param>
75 /// <param name="rounds">The number of erosion rounds (recommended: 25+)</param> 75 /// <param name="rounds">The number of erosion rounds (recommended: 25+)</param>
76 /// <param name="lowest">Drop sediment at the lowest point?</param> 76 /// <param name="lowest">Drop sediment at the lowest point?</param>
77 public void AerobicErosion(double windspeed, double pickupTalusMinimum, double dropTalusMinimum, double carry, int rounds, bool lowest, bool usingFluidDynamics) 77 public void AerobicErosion(double windspeed, double pickupTalusMinimum, double dropTalusMinimum, double carry, int rounds, bool lowest, bool usingFluidDynamics)
78 { 78 {
79 bool debugImages = false; 79 bool debugImages = false;
80 80
81 Channel wind = new Channel(w, h) ; 81 Channel wind = new Channel(w, h) ;
82 Channel sediment = new Channel(w, h); 82 Channel sediment = new Channel(w, h);
83 int x, y, i, j; 83 int x, y, i, j;
84 84
85 this.Normalise(); 85 this.Normalise();
86 86
87 wind = this.Copy(); 87 wind = this.Copy();
88 wind.Noise(); 88 wind.Noise();
89 89
90 if (debugImages) 90 if (debugImages)
91 wind.SaveImage("testimg/wind_start.png"); 91 wind.SaveImage("testimg/wind_start.png");
92 92
93 if (usingFluidDynamics) 93 if (usingFluidDynamics)
94 { 94 {
95 wind.navierStokes(20, 0.1, 0.0, 0.0); 95 wind.navierStokes(20, 0.1, 0.0, 0.0);
96 } 96 }
97 else 97 else
98 { 98 {
99 wind.Pertubation(30); 99 wind.Pertubation(30);
100 } 100 }
101 101
102 if (debugImages) 102 if (debugImages)
103 wind.SaveImage("testimg/wind_begin.png"); 103 wind.SaveImage("testimg/wind_begin.png");
104 104
105 for (i = 0; i < rounds; i++) 105 for (i = 0; i < rounds; i++)
106 { 106 {
107 // Convert some rocks to sand 107 // Convert some rocks to sand
108 for (x = 1; x < w - 1; x++) 108 for (x = 1; x < w - 1; x++)
109 { 109 {
110 for (y = 1; y < h - 1; y++) 110 for (y = 1; y < h - 1; y++)
111 { 111 {
112 double me = Get(x, y); 112 double me = Get(x, y);
113 double surfacearea = 0.3; // Everything will erode even if it's flat. Just slower. 113 double surfacearea = 0.3; // Everything will erode even if it's flat. Just slower.
114 114
115 for (j = 0; j < 9; j++) 115 for (j = 0; j < 9; j++)
116 { 116 {
117 int[] coords = Neighbours(NeighbourSystem.Moore, j); 117 int[] coords = Neighbours(NeighbourSystem.Moore, j);
118 double target = Get(x + coords[0], y + coords[1]); 118 double target = Get(x + coords[0], y + coords[1]);
119 119
120 surfacearea += Math.Abs(target - me); 120 surfacearea += Math.Abs(target - me);
121 } 121 }
122 122
123 double amount = surfacearea * wind.map[x, y] * carry; 123 double amount = surfacearea * wind.map[x, y] * carry;
124 124
125 if (amount < 0) 125 if (amount < 0)
126 amount = 0; 126 amount = 0;
127 127
128 if (surfacearea > pickupTalusMinimum) 128 if (surfacearea > pickupTalusMinimum)
129 { 129 {
130 Set(x, y, map[x, y] - amount); 130 Set(x, y, map[x, y] - amount);
131 sediment.map[x, y] += amount; 131 sediment.map[x, y] += amount;
132 } 132 }
133 } 133 }
134 } 134 }
135 135
136 if (usingFluidDynamics) 136 if (usingFluidDynamics)
137 { 137 {
138 sediment.navierStokes(7, 0.1, 0.0, 0.1); 138 sediment.navierStokes(7, 0.1, 0.0, 0.1);
139 139
140 Channel noiseChan = new Channel(w, h); 140 Channel noiseChan = new Channel(w, h);
141 noiseChan.Noise(); 141 noiseChan.Noise();
142 wind.Blend(noiseChan, 0.01); 142 wind.Blend(noiseChan, 0.01);
143 143
144 wind.navierStokes(10, 0.1, 0.01, 0.01); 144 wind.navierStokes(10, 0.1, 0.01, 0.01);
145 145
146 sediment.Distort(wind, windspeed); 146 sediment.Distort(wind, windspeed);
147 } 147 }
148 else 148 else
149 { 149 {
150 wind.Pertubation(15); // Can do better later 150 wind.Pertubation(15); // Can do better later
151 wind.seed++; 151 wind.seed++;
152 sediment.Pertubation(10); // Sediment is blown around a bit 152 sediment.Pertubation(10); // Sediment is blown around a bit
153 sediment.seed++; 153 sediment.seed++;
154 } 154 }
155 155
156 if (debugImages) 156 if (debugImages)
157 wind.SaveImage("testimg/wind_" + i.ToString() + ".png"); 157 wind.SaveImage("testimg/wind_" + i.ToString() + ".png");
158 158
159 // Convert some sand to rock 159 // Convert some sand to rock
160 for (x = 1; x < w - 1; x++) 160 for (x = 1; x < w - 1; x++)
161 { 161 {
162 for (y = 1; y < h - 1; y++) 162 for (y = 1; y < h - 1; y++)
163 { 163 {
164 double me = Get(x, y); 164 double me = Get(x, y);
165 double surfacearea = 0.01; // Flat land does not get deposition 165 double surfacearea = 0.01; // Flat land does not get deposition
166 double min = double.MaxValue; 166 double min = double.MaxValue;
167 int[] minside = new int[2]; 167 int[] minside = new int[2];
168 168
169 for (j = 0; j < 9; j++) 169 for (j = 0; j < 9; j++)
170 { 170 {
171 int[] coords = Neighbours(NeighbourSystem.Moore, j); 171 int[] coords = Neighbours(NeighbourSystem.Moore, j);
172 double target = Get(x + coords[0], y + coords[1]); 172 double target = Get(x + coords[0], y + coords[1]);
173 173
174 surfacearea += Math.Abs(target - me); 174 surfacearea += Math.Abs(target - me);
175 175
176 if (target < min && lowest) 176 if (target < min && lowest)
177 { 177 {
178 minside = (int[])coords.Clone(); 178 minside = (int[])coords.Clone();
179 min = target; 179 min = target;
180 } 180 }
181 } 181 }
182 182
183 double amount = surfacearea * (1.0 - wind.map[x, y]) * carry; 183 double amount = surfacearea * (1.0 - wind.map[x, y]) * carry;
184 184
185 if (amount < 0) 185 if (amount < 0)
186 amount = 0; 186 amount = 0;
187 187
188 if (surfacearea > dropTalusMinimum) 188 if (surfacearea > dropTalusMinimum)
189 { 189 {
190 Set(x + minside[0], y + minside[1], map[x + minside[0], y + minside[1]] + amount); 190 Set(x + minside[0], y + minside[1], map[x + minside[0], y + minside[1]] + amount);
191 sediment.map[x, y] -= amount; 191 sediment.map[x, y] -= amount;
192 } 192 }
193 } 193 }
194 } 194 }
195 195
196 if (debugImages) 196 if (debugImages)
197 sediment.SaveImage("testimg/sediment_" + i.ToString() + ".png"); 197 sediment.SaveImage("testimg/sediment_" + i.ToString() + ".png");
198 198
199 wind.Normalise(); 199 wind.Normalise();
200 wind *= windspeed; 200 wind *= windspeed;
201 201
202 this.Normalise(); 202 this.Normalise();
203 } 203 }
204 204
205 Channel myself = this; 205 Channel myself = this;
206 myself += sediment; 206 myself += sediment;
207 myself.Normalise(); 207 myself.Normalise();
208 208
209 if (debugImages) 209 if (debugImages)
210 this.SaveImage("testimg/output.png"); 210 this.SaveImage("testimg/output.png");
211 } 211 }
212 } 212 }
213} \ No newline at end of file 213} \ No newline at end of file
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/HydraulicErosion.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/HydraulicErosion.cs
index 36da77c..fb9e21e 100644
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/HydraulicErosion.cs
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/HydraulicErosion.cs
@@ -1,146 +1,146 @@
1/* 1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/ 2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders. 3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4* 4*
5* Redistribution and use in source and binary forms, with or without 5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met: 6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright 7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer. 8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright 9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the 10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution. 11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the 12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products 13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission. 14* derived from this software without specific prior written permission.
15* 15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY 16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26* 26*
27*/ 27*/
28 28
29using System; 29using System;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Text; 31using System.Text;
32 32
33namespace libTerrain 33namespace libTerrain
34{ 34{
35 partial class Channel 35 partial class Channel
36 { 36 {
37 public void HydraulicErosion(Channel rain, double evaporation, double solubility, int frequency, int rounds) 37 public void HydraulicErosion(Channel rain, double evaporation, double solubility, int frequency, int rounds)
38 { 38 {
39 SetDiff(); 39 SetDiff();
40 40
41 Channel water = new Channel(w, h); 41 Channel water = new Channel(w, h);
42 Channel sediment = new Channel(w, h); 42 Channel sediment = new Channel(w, h);
43 Channel terrain = this; 43 Channel terrain = this;
44 Channel waterFlow = new Channel(w, h); 44 Channel waterFlow = new Channel(w, h);
45 45
46 NeighbourSystem type = NeighbourSystem.Moore; 46 NeighbourSystem type = NeighbourSystem.Moore;
47 int NEIGHBOUR_ME = 4; 47 int NEIGHBOUR_ME = 4;
48 48
49 int NEIGHBOUR_MAX = type == NeighbourSystem.Moore ? 9 : 5; 49 int NEIGHBOUR_MAX = type == NeighbourSystem.Moore ? 9 : 5;
50 50
51 for (int i = 0; i < rounds; i++) 51 for (int i = 0; i < rounds; i++)
52 { 52 {
53 water += rain; 53 water += rain;
54 54
55 sediment = terrain * water; 55 sediment = terrain * water;
56 terrain -= sediment; 56 terrain -= sediment;
57 57
58 for (int x = 1; x < w - 1; x++) 58 for (int x = 1; x < w - 1; x++)
59 { 59 {
60 for (int y = 1; y < h - 1; y++) 60 for (int y = 1; y < h - 1; y++)
61 { 61 {
62 double[] heights = new double[NEIGHBOUR_MAX]; 62 double[] heights = new double[NEIGHBOUR_MAX];
63 double[] diffs = new double[NEIGHBOUR_MAX]; 63 double[] diffs = new double[NEIGHBOUR_MAX];
64 64
65 double heightCenter = map[x, y]; 65 double heightCenter = map[x, y];
66 66
67 for (int j = 0; j < NEIGHBOUR_MAX; j++) 67 for (int j = 0; j < NEIGHBOUR_MAX; j++)
68 { 68 {
69 if (j != NEIGHBOUR_ME) 69 if (j != NEIGHBOUR_ME)
70 { 70 {
71 int[] coords = Neighbours(type, j); 71 int[] coords = Neighbours(type, j);
72 coords[0] += x; 72 coords[0] += x;
73 coords[1] += y; 73 coords[1] += y;
74 74
75 heights[j] = map[coords[0], coords[1]] + water.map[coords[0], coords[1]] + sediment.map[coords[0], coords[1]]; 75 heights[j] = map[coords[0], coords[1]] + water.map[coords[0], coords[1]] + sediment.map[coords[0], coords[1]];
76 diffs[j] = heightCenter - heights[j]; 76 diffs[j] = heightCenter - heights[j];
77 } 77 }
78 } 78 }
79 79
80 double totalHeight = 0; 80 double totalHeight = 0;
81 double totalHeightDiff = 0; 81 double totalHeightDiff = 0;
82 int totalCellsCounted = 1; 82 int totalCellsCounted = 1;
83 83
84 for (int j = 0; j < NEIGHBOUR_MAX; j++) 84 for (int j = 0; j < NEIGHBOUR_MAX; j++)
85 { 85 {
86 if (j != NEIGHBOUR_ME) 86 if (j != NEIGHBOUR_ME)
87 { 87 {
88 if (diffs[j] > 0) 88 if (diffs[j] > 0)
89 { 89 {
90 totalHeight += heights[j]; 90 totalHeight += heights[j];
91 totalHeightDiff += diffs[j]; 91 totalHeightDiff += diffs[j];
92 totalCellsCounted++; 92 totalCellsCounted++;
93 } 93 }
94 } 94 }
95 } 95 }
96 96
97 if (totalCellsCounted == 1) 97 if (totalCellsCounted == 1)
98 continue; 98 continue;
99 99
100 double averageHeight = totalHeight / totalCellsCounted; 100 double averageHeight = totalHeight / totalCellsCounted;
101 double waterAmount = Math.Min(water.map[x, y], heightCenter - averageHeight); 101 double waterAmount = Math.Min(water.map[x, y], heightCenter - averageHeight);
102 102
103 // TODO: Check this. 103 // TODO: Check this.
104 waterFlow.map[x, y] += waterFlow.map[x, y] - waterAmount; 104 waterFlow.map[x, y] += waterFlow.map[x, y] - waterAmount;
105 105
106 double totalInverseDiff = waterAmount / totalHeightDiff; 106 double totalInverseDiff = waterAmount / totalHeightDiff;
107 107
108 for (int j = 0; j < NEIGHBOUR_MAX; j++) 108 for (int j = 0; j < NEIGHBOUR_MAX; j++)
109 { 109 {
110 if (j != NEIGHBOUR_ME) 110 if (j != NEIGHBOUR_ME)
111 { 111 {
112 int[] coords = Neighbours(type, j); 112 int[] coords = Neighbours(type, j);
113 coords[0] += x; 113 coords[0] += x;
114 coords[1] += y; 114 coords[1] += y;
115 115
116 if (diffs[j] > 0) 116 if (diffs[j] > 0)
117 { 117 {
118 waterFlow.SetWrap(coords[0], coords[1], waterFlow.map[coords[0], coords[1]] + diffs[j] * totalInverseDiff); 118 waterFlow.SetWrap(coords[0], coords[1], waterFlow.map[coords[0], coords[1]] + diffs[j] * totalInverseDiff);
119 } 119 }
120 } 120 }
121 } 121 }
122 } 122 }
123 } 123 }
124 124
125 water += waterFlow; 125 water += waterFlow;
126 waterFlow.Fill(0); 126 waterFlow.Fill(0);
127 127
128 water *= evaporation; 128 water *= evaporation;
129 129
130 for (int x = 0; x < w; x++) 130 for (int x = 0; x < w; x++)
131 { 131 {
132 for (int y = 0; y < h; y++) 132 for (int y = 0; y < h; y++)
133 { 133 {
134 double deposition = sediment.map[x, y] - water.map[x, y] * solubility; 134 double deposition = sediment.map[x, y] - water.map[x, y] * solubility;
135 if (deposition > 0) 135 if (deposition > 0)
136 { 136 {
137 sediment.map[x, y] -= deposition; 137 sediment.map[x, y] -= deposition;
138 terrain.map[x, y] += deposition; 138 terrain.map[x, y] += deposition;
139 } 139 }
140 } 140 }
141 } 141 }
142 142
143 } 143 }
144 } 144 }
145 } 145 }
146} \ No newline at end of file 146} \ No newline at end of file
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/NavierStokes.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/NavierStokes.cs
index 8a111ed..1cd213b 100644
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/NavierStokes.cs
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/NavierStokes.cs
@@ -1,307 +1,307 @@
1/* 1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/ 2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders. 3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4* 4*
5* Redistribution and use in source and binary forms, with or without 5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met: 6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright 7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer. 8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright 9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the 10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution. 11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the 12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products 13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission. 14* derived from this software without specific prior written permission.
15* 15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY 16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26* 26*
27*/ 27*/
28 28
29using System; 29using System;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Text; 31using System.Text;
32 32
33namespace libTerrain 33namespace libTerrain
34{ 34{
35 partial class Channel 35 partial class Channel
36 { 36 {
37 // Navier Stokes Algorithms ported from 37 // Navier Stokes Algorithms ported from
38 // "Real-Time Fluid Dynamics for Games" by Jos Stam. 38 // "Real-Time Fluid Dynamics for Games" by Jos Stam.
39 // presented at GDC 2003. 39 // presented at GDC 2003.
40 40
41 // Poorly ported from C++. (I gave up making it properly native somewhere after nsSetBnd) 41 // Poorly ported from C++. (I gave up making it properly native somewhere after nsSetBnd)
42 42
43 private static int nsIX(int i, int j, int N) 43 private static int nsIX(int i, int j, int N)
44 { 44 {
45 return ((i) + (N + 2) * (j)); 45 return ((i) + (N + 2) * (j));
46 } 46 }
47 47
48 private static void nsSwap(ref double x0, ref double x) 48 private static void nsSwap(ref double x0, ref double x)
49 { 49 {
50 double tmp = x0; 50 double tmp = x0;
51 x0 = x; 51 x0 = x;
52 x = tmp; 52 x = tmp;
53 } 53 }
54 54
55 private static void nsSwap(ref double[] x0, ref double[] x) 55 private static void nsSwap(ref double[] x0, ref double[] x)
56 { 56 {
57 double[] tmp = x0; 57 double[] tmp = x0;
58 x0 = x; 58 x0 = x;
59 x = tmp; 59 x = tmp;
60 } 60 }
61 61
62 private void nsAddSource(int N, ref double[] x, ref double[] s, double dt) 62 private void nsAddSource(int N, ref double[] x, ref double[] s, double dt)
63 { 63 {
64 int i; 64 int i;
65 int size = (N + 2) * (N + 2); 65 int size = (N + 2) * (N + 2);
66 for (i = 0; i < size; i++) 66 for (i = 0; i < size; i++)
67 { 67 {
68 x[i] += dt * s[i]; 68 x[i] += dt * s[i];
69 } 69 }
70 } 70 }
71 71
72 private void nsSetBnd(int N, int b, ref double[] x) 72 private void nsSetBnd(int N, int b, ref double[] x)
73 { 73 {
74 int i; 74 int i;
75 for (i = 0; i <= N; i++) 75 for (i = 0; i <= N; i++)
76 { 76 {
77 x[nsIX(0, i, N)] = b == 1 ? -x[nsIX(1, i, N)] : x[nsIX(1, i, N)]; 77 x[nsIX(0, i, N)] = b == 1 ? -x[nsIX(1, i, N)] : x[nsIX(1, i, N)];
78 x[nsIX(0, N + 1, N)] = b == 1 ? -x[nsIX(N, i, N)] : x[nsIX(N, i, N)]; 78 x[nsIX(0, N + 1, N)] = b == 1 ? -x[nsIX(N, i, N)] : x[nsIX(N, i, N)];
79 x[nsIX(i, 0, N)] = b == 2 ? -x[nsIX(i, 1, N)] : x[nsIX(i, 1, N)]; 79 x[nsIX(i, 0, N)] = b == 2 ? -x[nsIX(i, 1, N)] : x[nsIX(i, 1, N)];
80 x[nsIX(i, N + 1, N)] = b == 2 ? -x[nsIX(i, N, N)] : x[nsIX(i, N, N)]; 80 x[nsIX(i, N + 1, N)] = b == 2 ? -x[nsIX(i, N, N)] : x[nsIX(i, N, N)];
81 } 81 }
82 x[nsIX(0, 0, N)] = 0.5f * (x[nsIX(1, 0, N)] + x[nsIX(0, 1, N)]); 82 x[nsIX(0, 0, N)] = 0.5f * (x[nsIX(1, 0, N)] + x[nsIX(0, 1, N)]);
83 x[nsIX(0, N + 1, N)] = 0.5f * (x[nsIX(1, N + 1, N)] + x[nsIX(0, N, N)]); 83 x[nsIX(0, N + 1, N)] = 0.5f * (x[nsIX(1, N + 1, N)] + x[nsIX(0, N, N)]);
84 x[nsIX(N + 1, 0, N)] = 0.5f * (x[nsIX(N, 0, N)] + x[nsIX(N + 1, 1, N)]); 84 x[nsIX(N + 1, 0, N)] = 0.5f * (x[nsIX(N, 0, N)] + x[nsIX(N + 1, 1, N)]);
85 x[nsIX(N + 1, N + 1, N)] = 0.5f * (x[nsIX(N, N + 1, N)] + x[nsIX(N + 1, N, N)]); 85 x[nsIX(N + 1, N + 1, N)] = 0.5f * (x[nsIX(N, N + 1, N)] + x[nsIX(N + 1, N, N)]);
86 } 86 }
87 87
88 private void nsLinSolve(int N, int b, ref double[] x, ref double[] x0, double a, double c) 88 private void nsLinSolve(int N, int b, ref double[] x, ref double[] x0, double a, double c)
89 { 89 {
90 int i, j; 90 int i, j;
91 for (i = 1; i <= N; i++) 91 for (i = 1; i <= N; i++)
92 { 92 {
93 for (j = 1; j <= N; j++) 93 for (j = 1; j <= N; j++)
94 { 94 {
95 x[nsIX(i, j, N)] = (x0[nsIX(i, j, N)] + a * 95 x[nsIX(i, j, N)] = (x0[nsIX(i, j, N)] + a *
96 (x[nsIX(i - 1, j, N)] + 96 (x[nsIX(i - 1, j, N)] +
97 x[nsIX(i + 1, j, N)] + 97 x[nsIX(i + 1, j, N)] +
98 x[nsIX(i, j - 1, N)] + x[nsIX(i, j + 1, N)]) 98 x[nsIX(i, j - 1, N)] + x[nsIX(i, j + 1, N)])
99 ) / c; 99 ) / c;
100 } 100 }
101 } 101 }
102 102
103 nsSetBnd(N, b, ref x); 103 nsSetBnd(N, b, ref x);
104 } 104 }
105 105
106 private void nsDiffuse(int N, int b, ref double[] x, ref double[] x0, double diff, double dt) 106 private void nsDiffuse(int N, int b, ref double[] x, ref double[] x0, double diff, double dt)
107 { 107 {
108 double a = dt * diff * N * N; 108 double a = dt * diff * N * N;
109 nsLinSolve(N, b, ref x, ref x0, a, 1 + 4 * a); 109 nsLinSolve(N, b, ref x, ref x0, a, 1 + 4 * a);
110 } 110 }
111 111
112 private void nsAdvect(int N, int b, ref double[] d, ref double[] d0, ref double[] u, ref double[] v, double dt) 112 private void nsAdvect(int N, int b, ref double[] d, ref double[] d0, ref double[] u, ref double[] v, double dt)
113 { 113 {
114 int i, j, i0, j0, i1, j1; 114 int i, j, i0, j0, i1, j1;
115 double x, y, s0, t0, s1, t1, dt0; 115 double x, y, s0, t0, s1, t1, dt0;
116 116
117 dt0 = dt * N; 117 dt0 = dt * N;
118 118
119 for (i = 1; i <= N; i++) 119 for (i = 1; i <= N; i++)
120 { 120 {
121 for (j = 1; j <= N; j++) 121 for (j = 1; j <= N; j++)
122 { 122 {
123 x = i - dt0 * u[nsIX(i, j, N)]; 123 x = i - dt0 * u[nsIX(i, j, N)];
124 y = j - dt0 * v[nsIX(i, j, N)]; 124 y = j - dt0 * v[nsIX(i, j, N)];
125 125
126 if (x < 0.5) 126 if (x < 0.5)
127 x = 0.5; 127 x = 0.5;
128 if (x > N + 0.5) 128 if (x > N + 0.5)
129 x = N + 0.5; 129 x = N + 0.5;
130 i0 = (int)x; 130 i0 = (int)x;
131 i1 = i0 + 1; 131 i1 = i0 + 1;
132 132
133 if (y < 0.5) 133 if (y < 0.5)
134 y = 0.5; 134 y = 0.5;
135 if (y > N + 0.5) 135 if (y > N + 0.5)
136 y = N + 0.5; 136 y = N + 0.5;
137 j0 = (int)y; 137 j0 = (int)y;
138 j1 = j0 + 1; 138 j1 = j0 + 1;
139 139
140 s1 = x - i0; 140 s1 = x - i0;
141 s0 = 1 - s1; 141 s0 = 1 - s1;
142 t1 = y - j0; 142 t1 = y - j0;
143 t0 = 1 - t1; 143 t0 = 1 - t1;
144 144
145 d[nsIX(i, j, N)] = s0 * (t0 * d0[nsIX(i0, j0, N)] + t1 * d0[nsIX(i0, j1, N)]) + 145 d[nsIX(i, j, N)] = s0 * (t0 * d0[nsIX(i0, j0, N)] + t1 * d0[nsIX(i0, j1, N)]) +
146 s1 * (t0 * d0[nsIX(i1, j0, N)] + t1 * d0[nsIX(i1, j1, N)]); 146 s1 * (t0 * d0[nsIX(i1, j0, N)] + t1 * d0[nsIX(i1, j1, N)]);
147 } 147 }
148 } 148 }
149 149
150 nsSetBnd(N, b, ref d); 150 nsSetBnd(N, b, ref d);
151 } 151 }
152 152
153 public void nsProject(int N, ref double[] u, ref double[] v, ref double[] p, ref double[] div) 153 public void nsProject(int N, ref double[] u, ref double[] v, ref double[] p, ref double[] div)
154 { 154 {
155 int i, j; 155 int i, j;
156 156
157 for (i = 1; i <= N; i++) 157 for (i = 1; i <= N; i++)
158 { 158 {
159 for (j = 1; j <= N; j++) 159 for (j = 1; j <= N; j++)
160 { 160 {
161 div[nsIX(i, j, N)] = -0.5 * (u[nsIX(i + 1, j, N)] - u[nsIX(i - 1, j, N)] + v[nsIX(i, j + 1, N)] - v[nsIX(i, j - 1, N)]) / N; 161 div[nsIX(i, j, N)] = -0.5 * (u[nsIX(i + 1, j, N)] - u[nsIX(i - 1, j, N)] + v[nsIX(i, j + 1, N)] - v[nsIX(i, j - 1, N)]) / N;
162 p[nsIX(i, j, N)] = 0; 162 p[nsIX(i, j, N)] = 0;
163 } 163 }
164 } 164 }
165 165
166 nsSetBnd(N, 0, ref div); 166 nsSetBnd(N, 0, ref div);
167 nsSetBnd(N, 0, ref p); 167 nsSetBnd(N, 0, ref p);
168 168
169 nsLinSolve(N, 0, ref p, ref div, 1, 4); 169 nsLinSolve(N, 0, ref p, ref div, 1, 4);
170 170
171 for (i = 1; i <= N; i++) 171 for (i = 1; i <= N; i++)
172 { 172 {
173 for (j = 1; j <= N; j++) 173 for (j = 1; j <= N; j++)
174 { 174 {
175 u[nsIX(i, j, N)] -= 0.5 * N * (p[nsIX(i + 1, j, N)] - p[nsIX(i - 1, j, N)]); 175 u[nsIX(i, j, N)] -= 0.5 * N * (p[nsIX(i + 1, j, N)] - p[nsIX(i - 1, j, N)]);
176 v[nsIX(i, j, N)] -= 0.5 * N * (p[nsIX(i, j + 1, N)] - p[nsIX(i, j - 1, N)]); 176 v[nsIX(i, j, N)] -= 0.5 * N * (p[nsIX(i, j + 1, N)] - p[nsIX(i, j - 1, N)]);
177 } 177 }
178 } 178 }
179 179
180 nsSetBnd(N, 1, ref u); 180 nsSetBnd(N, 1, ref u);
181 nsSetBnd(N, 2, ref v); 181 nsSetBnd(N, 2, ref v);
182 } 182 }
183 183
184 private void nsDensStep(int N, ref double[] x, ref double[] x0, ref double[] u, ref double[] v, double diff, double dt) 184 private void nsDensStep(int N, ref double[] x, ref double[] x0, ref double[] u, ref double[] v, double diff, double dt)
185 { 185 {
186 nsAddSource(N, ref x, ref x0, dt); 186 nsAddSource(N, ref x, ref x0, dt);
187 nsSwap(ref x0, ref x); 187 nsSwap(ref x0, ref x);
188 nsDiffuse(N, 0, ref x, ref x0, diff, dt); 188 nsDiffuse(N, 0, ref x, ref x0, diff, dt);
189 nsSwap(ref x0, ref x); 189 nsSwap(ref x0, ref x);
190 nsAdvect(N, 0, ref x, ref x0, ref u, ref v, dt); 190 nsAdvect(N, 0, ref x, ref x0, ref u, ref v, dt);
191 } 191 }
192 192
193 private void nsVelStep(int N, ref double[] u, ref double[] v, ref double[] u0, ref double[] v0, double visc, double dt) 193 private void nsVelStep(int N, ref double[] u, ref double[] v, ref double[] u0, ref double[] v0, double visc, double dt)
194 { 194 {
195 nsAddSource(N, ref u, ref u0, dt); 195 nsAddSource(N, ref u, ref u0, dt);
196 nsAddSource(N, ref v, ref v0, dt); 196 nsAddSource(N, ref v, ref v0, dt);
197 nsSwap(ref u0, ref u); 197 nsSwap(ref u0, ref u);
198 nsDiffuse(N, 1, ref u, ref u0, visc, dt); 198 nsDiffuse(N, 1, ref u, ref u0, visc, dt);
199 nsSwap(ref v0, ref v); 199 nsSwap(ref v0, ref v);
200 nsDiffuse(N, 2, ref v, ref v0, visc, dt); 200 nsDiffuse(N, 2, ref v, ref v0, visc, dt);
201 nsProject(N, ref u, ref v, ref u0, ref v0); 201 nsProject(N, ref u, ref v, ref u0, ref v0);
202 nsSwap(ref u0, ref u); 202 nsSwap(ref u0, ref u);
203 nsSwap(ref v0, ref v); 203 nsSwap(ref v0, ref v);
204 nsAdvect(N, 1, ref u, ref u0, ref u0, ref v0, dt); 204 nsAdvect(N, 1, ref u, ref u0, ref u0, ref v0, dt);
205 nsAdvect(N, 2, ref v, ref v0, ref u0, ref v0, dt); 205 nsAdvect(N, 2, ref v, ref v0, ref u0, ref v0, dt);
206 nsProject(N, ref u, ref v, ref u0, ref v0); 206 nsProject(N, ref u, ref v, ref u0, ref v0);
207 } 207 }
208 208
209 private void nsBufferToDoubles(ref double[] dens, int N, ref double[,] doubles) 209 private void nsBufferToDoubles(ref double[] dens, int N, ref double[,] doubles)
210 { 210 {
211 int i; 211 int i;
212 int j; 212 int j;
213 213
214 for (i = 1; i <= N; i++) 214 for (i = 1; i <= N; i++)
215 { 215 {
216 for (j = 1; j <= N; j++) 216 for (j = 1; j <= N; j++)
217 { 217 {
218 doubles[i - 1, j - 1] = dens[nsIX(i, j, N)]; 218 doubles[i - 1, j - 1] = dens[nsIX(i, j, N)];
219 } 219 }
220 } 220 }
221 } 221 }
222 222
223 private void nsDoublesToBuffer(double[,] doubles, int N, ref double[] dens) 223 private void nsDoublesToBuffer(double[,] doubles, int N, ref double[] dens)
224 { 224 {
225 int i; 225 int i;
226 int j; 226 int j;
227 227
228 for (i = 1; i <= N; i++) 228 for (i = 1; i <= N; i++)
229 { 229 {
230 for (j = 1; j <= N; j++) 230 for (j = 1; j <= N; j++)
231 { 231 {
232 dens[nsIX(i, j, N)] = doubles[i - 1, j - 1]; 232 dens[nsIX(i, j, N)] = doubles[i - 1, j - 1];
233 } 233 }
234 } 234 }
235 } 235 }
236 236
237 private void nsSimulate(int N, int rounds, double dt, double diff, double visc) 237 private void nsSimulate(int N, int rounds, double dt, double diff, double visc)
238 { 238 {
239 int size = (N * 2) * (N * 2); 239 int size = (N * 2) * (N * 2);
240 240
241 double[] u = new double[size]; // Force, X axis 241 double[] u = new double[size]; // Force, X axis
242 double[] v = new double[size]; // Force, Y axis 242 double[] v = new double[size]; // Force, Y axis
243 double[] u_prev = new double[size]; 243 double[] u_prev = new double[size];
244 double[] v_prev = new double[size]; 244 double[] v_prev = new double[size];
245 double[] dens = new double[size]; 245 double[] dens = new double[size];
246 double[] dens_prev = new double[size]; 246 double[] dens_prev = new double[size];
247 247
248 nsDoublesToBuffer(this.map, N, ref dens); 248 nsDoublesToBuffer(this.map, N, ref dens);
249 nsDoublesToBuffer(this.map, N, ref dens_prev); 249 nsDoublesToBuffer(this.map, N, ref dens_prev);
250 250
251 for (int i = 0; i < rounds; i++) 251 for (int i = 0; i < rounds; i++)
252 { 252 {
253 u_prev = u; 253 u_prev = u;
254 v_prev = v; 254 v_prev = v;
255 dens_prev = dens; 255 dens_prev = dens;
256 256
257 nsVelStep(N, ref u, ref v, ref u_prev, ref v_prev, visc, dt); 257 nsVelStep(N, ref u, ref v, ref u_prev, ref v_prev, visc, dt);
258 nsDensStep(N, ref dens, ref dens_prev, ref u, ref v, diff, dt); 258 nsDensStep(N, ref dens, ref dens_prev, ref u, ref v, diff, dt);
259 } 259 }
260 260
261 nsBufferToDoubles(ref dens, N, ref this.map); 261 nsBufferToDoubles(ref dens, N, ref this.map);
262 } 262 }
263 263
264 /// <summary> 264 /// <summary>
265 /// Performs computational fluid dynamics on a channel 265 /// Performs computational fluid dynamics on a channel
266 /// </summary> 266 /// </summary>
267 /// <param name="rounds">The number of steps to perform (Recommended: 20)</param> 267 /// <param name="rounds">The number of steps to perform (Recommended: 20)</param>
268 /// <param name="dt">Delta Time - The time between steps (Recommended: 0.1)</param> 268 /// <param name="dt">Delta Time - The time between steps (Recommended: 0.1)</param>
269 /// <param name="diff">Fluid diffusion rate (Recommended: 0.0)</param> 269 /// <param name="diff">Fluid diffusion rate (Recommended: 0.0)</param>
270 /// <param name="visc">Fluid viscosity (Recommended: 0.0)</param> 270 /// <param name="visc">Fluid viscosity (Recommended: 0.0)</param>
271 public void navierStokes(int rounds, double dt, double diff, double visc) 271 public void navierStokes(int rounds, double dt, double diff, double visc)
272 { 272 {
273 nsSimulate(this.h, rounds, dt, diff, visc); 273 nsSimulate(this.h, rounds, dt, diff, visc);
274 } 274 }
275 275
276 public void navierStokes(int rounds, double dt, double diff, double visc, ref double[,] uret, ref double[,] vret) 276 public void navierStokes(int rounds, double dt, double diff, double visc, ref double[,] uret, ref double[,] vret)
277 { 277 {
278 int N = this.h; 278 int N = this.h;
279 279
280 int size = (N * 2) * (N * 2); 280 int size = (N * 2) * (N * 2);
281 281
282 double[] u = new double[size]; // Force, X axis 282 double[] u = new double[size]; // Force, X axis
283 double[] v = new double[size]; // Force, Y axis 283 double[] v = new double[size]; // Force, Y axis
284 double[] u_prev = new double[size]; 284 double[] u_prev = new double[size];
285 double[] v_prev = new double[size]; 285 double[] v_prev = new double[size];
286 double[] dens = new double[size]; 286 double[] dens = new double[size];
287 double[] dens_prev = new double[size]; 287 double[] dens_prev = new double[size];
288 288
289 nsDoublesToBuffer(this.map, N, ref dens); 289 nsDoublesToBuffer(this.map, N, ref dens);
290 nsDoublesToBuffer(this.map, N, ref dens_prev); 290 nsDoublesToBuffer(this.map, N, ref dens_prev);
291 291
292 for (int i = 0; i < rounds; i++) 292 for (int i = 0; i < rounds; i++)
293 { 293 {
294 u_prev = u; 294 u_prev = u;
295 v_prev = v; 295 v_prev = v;
296 dens_prev = dens; 296 dens_prev = dens;
297 297
298 nsVelStep(N, ref u, ref v, ref u_prev, ref v_prev, visc, dt); 298 nsVelStep(N, ref u, ref v, ref u_prev, ref v_prev, visc, dt);
299 nsDensStep(N, ref dens, ref dens_prev, ref u, ref v, diff, dt); 299 nsDensStep(N, ref dens, ref dens_prev, ref u, ref v, diff, dt);
300 } 300 }
301 301
302 nsBufferToDoubles(ref u, N, ref uret); 302 nsBufferToDoubles(ref u, N, ref uret);
303 nsBufferToDoubles(ref v, N, ref vret); 303 nsBufferToDoubles(ref v, N, ref vret);
304 nsBufferToDoubles(ref dens, N, ref this.map); 304 nsBufferToDoubles(ref dens, N, ref this.map);
305 } 305 }
306 } 306 }
307} \ No newline at end of file 307} \ No newline at end of file
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/ThermalWeathering.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/ThermalWeathering.cs
index 07c7d66..695d501 100644
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/ThermalWeathering.cs
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/ThermalWeathering.cs
@@ -1,112 +1,112 @@
1/* 1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/ 2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders. 3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4* 4*
5* Redistribution and use in source and binary forms, with or without 5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met: 6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright 7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer. 8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright 9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the 10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution. 11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the 12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products 13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission. 14* derived from this software without specific prior written permission.
15* 15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY 16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26* 26*
27*/ 27*/
28 28
29using System; 29using System;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Text; 31using System.Text;
32 32
33namespace libTerrain 33namespace libTerrain
34{ 34{
35 partial class Channel 35 partial class Channel
36 { 36 {
37 /// <summary> 37 /// <summary>
38 /// A thermal weathering implementation based on Musgrave's original 1989 algorithm. This is Adam's custom implementation which may differ slightly from the original. 38 /// A thermal weathering implementation based on Musgrave's original 1989 algorithm. This is Adam's custom implementation which may differ slightly from the original.
39 /// </summary> 39 /// </summary>
40 /// <param name="talus">The rock angle (represented as a dy/dx ratio) at which point it will be succeptible to breakage</param> 40 /// <param name="talus">The rock angle (represented as a dy/dx ratio) at which point it will be succeptible to breakage</param>
41 /// <param name="rounds">The number of erosion rounds</param> 41 /// <param name="rounds">The number of erosion rounds</param>
42 /// <param name="c">The amount of rock to carry each round</param> 42 /// <param name="c">The amount of rock to carry each round</param>
43 public Channel ThermalWeathering(double talus, int rounds, double c) 43 public Channel ThermalWeathering(double talus, int rounds, double c)
44 { 44 {
45 SetDiff(); 45 SetDiff();
46 46
47 double[,] lastFrame; 47 double[,] lastFrame;
48 double[,] thisFrame; 48 double[,] thisFrame;
49 49
50 lastFrame = (double[,])map.Clone(); 50 lastFrame = (double[,])map.Clone();
51 thisFrame = (double[,])map.Clone(); 51 thisFrame = (double[,])map.Clone();
52 52
53 NeighbourSystem type = NeighbourSystem.Moore; // Using moore neighbourhood (twice as computationally expensive) 53 NeighbourSystem type = NeighbourSystem.Moore; // Using moore neighbourhood (twice as computationally expensive)
54 int NEIGHBOUR_ME = 4; // I am always 4 in both systems. 54 int NEIGHBOUR_ME = 4; // I am always 4 in both systems.
55 55
56 int NEIGHBOUR_MAX = type == NeighbourSystem.Moore ? 9 : 5; 56 int NEIGHBOUR_MAX = type == NeighbourSystem.Moore ? 9 : 5;
57 57
58 int frames = rounds; // Number of thermal erosion iterations to run 58 int frames = rounds; // Number of thermal erosion iterations to run
59 int i, j; 59 int i, j;
60 int x, y; 60 int x, y;
61 61
62 for (i = 0; i < frames; i++) 62 for (i = 0; i < frames; i++)
63 { 63 {
64 for (x = 0; x < w; x++) 64 for (x = 0; x < w; x++)
65 { 65 {
66 for (y = 0; y < h; y++) 66 for (y = 0; y < h; y++)
67 { 67 {
68 for (j = 0; j < NEIGHBOUR_MAX; j++) 68 for (j = 0; j < NEIGHBOUR_MAX; j++)
69 { 69 {
70 if (j != NEIGHBOUR_ME) 70 if (j != NEIGHBOUR_ME)
71 { 71 {
72 int[] coords = Neighbours(type, j); 72 int[] coords = Neighbours(type, j);
73 73
74 coords[0] += x; 74 coords[0] += x;
75 coords[1] += y; 75 coords[1] += y;
76 76
77 if (coords[0] > w - 1) 77 if (coords[0] > w - 1)
78 coords[0] = w - 1; 78 coords[0] = w - 1;
79 if (coords[1] > h - 1) 79 if (coords[1] > h - 1)
80 coords[1] = h - 1; 80 coords[1] = h - 1;
81 if (coords[0] < 0) 81 if (coords[0] < 0)
82 coords[0] = 0; 82 coords[0] = 0;
83 if (coords[1] < 0) 83 if (coords[1] < 0)
84 coords[1] = 0; 84 coords[1] = 0;
85 85
86 double heightF = thisFrame[x, y]; 86 double heightF = thisFrame[x, y];
87 double target = thisFrame[coords[0], coords[1]]; 87 double target = thisFrame[coords[0], coords[1]];
88 88
89 if (target > heightF + talus) 89 if (target > heightF + talus)
90 { 90 {
91 double calc = c * ((target - heightF) - talus); 91 double calc = c * ((target - heightF) - talus);
92 heightF += calc; 92 heightF += calc;
93 target -= calc; 93 target -= calc;
94 } 94 }
95 95
96 thisFrame[x, y] = heightF; 96 thisFrame[x, y] = heightF;
97 thisFrame[coords[0], coords[1]] = target; 97 thisFrame[coords[0], coords[1]] = target;
98 98
99 } 99 }
100 } 100 }
101 } 101 }
102 } 102 }
103 lastFrame = (double[,])thisFrame.Clone(); 103 lastFrame = (double[,])thisFrame.Clone();
104 } 104 }
105 105
106 map = thisFrame; 106 map = thisFrame;
107 107
108 Normalise(); // Just to guaruntee a smooth 0..1 value 108 Normalise(); // Just to guaruntee a smooth 0..1 value
109 return this; 109 return this;
110 } 110 }
111 } 111 }
112} 112}
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Neighbours.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Neighbours.cs
index 6dc2e30..da03871 100644
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Neighbours.cs
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Neighbours.cs
@@ -1,141 +1,141 @@
1/* 1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/ 2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders. 3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4* 4*
5* Redistribution and use in source and binary forms, with or without 5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met: 6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright 7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer. 8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright 9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the 10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution. 11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the 12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products 13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission. 14* derived from this software without specific prior written permission.
15* 15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY 16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26* 26*
27*/ 27*/
28 28
29using System; 29using System;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Text; 31using System.Text;
32 32
33namespace libTerrain 33namespace libTerrain
34{ 34{
35 partial class Channel 35 partial class Channel
36 { 36 {
37 enum NeighbourSystem 37 enum NeighbourSystem
38 { 38 {
39 Moore, 39 Moore,
40 VonNeumann 40 VonNeumann
41 }; 41 };
42 42
43 private int[] Neighbours(NeighbourSystem type, int index) 43 private int[] Neighbours(NeighbourSystem type, int index)
44 { 44 {
45 int[] coord = new int[2]; 45 int[] coord = new int[2];
46 46
47 index++; 47 index++;
48 48
49 switch (type) 49 switch (type)
50 { 50 {
51 case NeighbourSystem.Moore: 51 case NeighbourSystem.Moore:
52 switch (index) 52 switch (index)
53 { 53 {
54 case 1: 54 case 1:
55 coord[0] = -1; 55 coord[0] = -1;
56 coord[1] = -1; 56 coord[1] = -1;
57 break; 57 break;
58 58
59 case 2: 59 case 2:
60 coord[0] = -0; 60 coord[0] = -0;
61 coord[1] = -1; 61 coord[1] = -1;
62 break; 62 break;
63 63
64 case 3: 64 case 3:
65 coord[0] = +1; 65 coord[0] = +1;
66 coord[1] = -1; 66 coord[1] = -1;
67 break; 67 break;
68 68
69 case 4: 69 case 4:
70 coord[0] = -1; 70 coord[0] = -1;
71 coord[1] = -0; 71 coord[1] = -0;
72 break; 72 break;
73 73
74 case 5: 74 case 5:
75 coord[0] = -0; 75 coord[0] = -0;
76 coord[1] = -0; 76 coord[1] = -0;
77 break; 77 break;
78 78
79 case 6: 79 case 6:
80 coord[0] = +1; 80 coord[0] = +1;
81 coord[1] = -0; 81 coord[1] = -0;
82 break; 82 break;
83 83
84 case 7: 84 case 7:
85 coord[0] = -1; 85 coord[0] = -1;
86 coord[1] = +1; 86 coord[1] = +1;
87 break; 87 break;
88 88
89 case 8: 89 case 8:
90 coord[0] = -0; 90 coord[0] = -0;
91 coord[1] = +1; 91 coord[1] = +1;
92 break; 92 break;
93 93
94 case 9: 94 case 9:
95 coord[0] = +1; 95 coord[0] = +1;
96 coord[1] = +1; 96 coord[1] = +1;
97 break; 97 break;
98 98
99 default: 99 default:
100 break; 100 break;
101 } 101 }
102 break; 102 break;
103 103
104 case NeighbourSystem.VonNeumann: 104 case NeighbourSystem.VonNeumann:
105 switch (index) 105 switch (index)
106 { 106 {
107 case 1: 107 case 1:
108 coord[0] = 0; 108 coord[0] = 0;
109 coord[1] = -1; 109 coord[1] = -1;
110 break; 110 break;
111 111
112 case 2: 112 case 2:
113 coord[0] = -1; 113 coord[0] = -1;
114 coord[1] = 0; 114 coord[1] = 0;
115 break; 115 break;
116 116
117 case 3: 117 case 3:
118 coord[0] = +1; 118 coord[0] = +1;
119 coord[1] = 0; 119 coord[1] = 0;
120 break; 120 break;
121 121
122 case 4: 122 case 4:
123 coord[0] = 0; 123 coord[0] = 0;
124 coord[1] = +1; 124 coord[1] = +1;
125 break; 125 break;
126 126
127 case 5: 127 case 5:
128 coord[0] = -0; 128 coord[0] = -0;
129 coord[1] = -0; 129 coord[1] = -0;
130 break; 130 break;
131 131
132 default: 132 default:
133 break; 133 break;
134 } 134 }
135 break; 135 break;
136 } 136 }
137 137
138 return coord; 138 return coord;
139 } 139 }
140 } 140 }
141} 141}
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Operators.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Operators.cs
index 3199ddc..8184f06 100644
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Operators.cs
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Operators.cs
@@ -1,243 +1,243 @@
1/* 1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/ 2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders. 3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4* 4*
5* Redistribution and use in source and binary forms, with or without 5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met: 6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright 7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer. 8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright 9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the 10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution. 11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the 12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products 13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission. 14* derived from this software without specific prior written permission.
15* 15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY 16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26* 26*
27*/ 27*/
28 28
29using System; 29using System;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Text; 31using System.Text;
32 32
33namespace libTerrain 33namespace libTerrain
34{ 34{
35 partial class Channel 35 partial class Channel
36 { 36 {
37 /* Operator combination of channel datatypes */ 37 /* Operator combination of channel datatypes */
38 38
39 public static Channel operator +(Channel A, Channel B) 39 public static Channel operator +(Channel A, Channel B)
40 { 40 {
41 if (A.h != B.h) 41 if (A.h != B.h)
42 throw new Exception("Cannot add heightmaps, of different height."); 42 throw new Exception("Cannot add heightmaps, of different height.");
43 if (A.w != B.w) 43 if (A.w != B.w)
44 throw new Exception("Cannot add heightmaps, of different width."); 44 throw new Exception("Cannot add heightmaps, of different width.");
45 45
46 int x, y; 46 int x, y;
47 47
48 for (x = 0; x < A.w; x++) 48 for (x = 0; x < A.w; x++)
49 { 49 {
50 for (y = 0; y < A.h; y++) 50 for (y = 0; y < A.h; y++)
51 { 51 {
52 if (B.map[x, y] != 0) 52 if (B.map[x, y] != 0)
53 A.SetDiff(x, y); 53 A.SetDiff(x, y);
54 54
55 A.map[x, y] += B.map[x, y]; 55 A.map[x, y] += B.map[x, y];
56 } 56 }
57 } 57 }
58 58
59 return A; 59 return A;
60 } 60 }
61 61
62 public static Channel operator *(Channel A, Channel B) 62 public static Channel operator *(Channel A, Channel B)
63 { 63 {
64 if (A.h != B.h) 64 if (A.h != B.h)
65 throw new Exception("Cannot multiply heightmaps, of different height."); 65 throw new Exception("Cannot multiply heightmaps, of different height.");
66 if (A.w != B.w) 66 if (A.w != B.w)
67 throw new Exception("Cannot multiply heightmaps, of different width."); 67 throw new Exception("Cannot multiply heightmaps, of different width.");
68 68
69 int x, y; 69 int x, y;
70 70
71 for (x = 0; x < A.w; x++) 71 for (x = 0; x < A.w; x++)
72 { 72 {
73 for (y = 0; y < A.h; y++) 73 for (y = 0; y < A.h; y++)
74 { 74 {
75 A.map[x, y] *= B.map[x, y]; 75 A.map[x, y] *= B.map[x, y];
76 } 76 }
77 } 77 }
78 78
79 A.SetDiff(); 79 A.SetDiff();
80 80
81 return A; 81 return A;
82 } 82 }
83 83
84 public static Channel operator -(Channel A, Channel B) 84 public static Channel operator -(Channel A, Channel B)
85 { 85 {
86 if (A.h != B.h) 86 if (A.h != B.h)
87 throw new Exception("Cannot subtract heightmaps, of different height."); 87 throw new Exception("Cannot subtract heightmaps, of different height.");
88 if (A.w != B.w) 88 if (A.w != B.w)
89 throw new Exception("Cannot subtract heightmaps, of different width."); 89 throw new Exception("Cannot subtract heightmaps, of different width.");
90 90
91 int x, y; 91 int x, y;
92 92
93 for (x = 0; x < A.w; x++) 93 for (x = 0; x < A.w; x++)
94 { 94 {
95 for (y = 0; y < A.h; y++) 95 for (y = 0; y < A.h; y++)
96 { 96 {
97 if (B.map[x, y] != 0) 97 if (B.map[x, y] != 0)
98 A.SetDiff(x, y); 98 A.SetDiff(x, y);
99 A.map[x, y] -= B.map[x, y]; 99 A.map[x, y] -= B.map[x, y];
100 } 100 }
101 } 101 }
102 102
103 return A; 103 return A;
104 } 104 }
105 105
106 public static Channel operator /(Channel A, Channel B) 106 public static Channel operator /(Channel A, Channel B)
107 { 107 {
108 if (A.h != B.h) 108 if (A.h != B.h)
109 throw new Exception("Cannot divide heightmaps, of different height."); 109 throw new Exception("Cannot divide heightmaps, of different height.");
110 if (A.w != B.w) 110 if (A.w != B.w)
111 throw new Exception("Cannot divide heightmaps, of different width."); 111 throw new Exception("Cannot divide heightmaps, of different width.");
112 112
113 int x, y; 113 int x, y;
114 114
115 for (x = 0; x < A.w; x++) 115 for (x = 0; x < A.w; x++)
116 { 116 {
117 for (y = 0; y < A.h; y++) 117 for (y = 0; y < A.h; y++)
118 { 118 {
119 A.map[x, y] /= B.map[x, y]; 119 A.map[x, y] /= B.map[x, y];
120 } 120 }
121 } 121 }
122 122
123 A.SetDiff(); 123 A.SetDiff();
124 124
125 return A; 125 return A;
126 } 126 }
127 127
128 public static Channel operator ^(Channel A, Channel B) 128 public static Channel operator ^(Channel A, Channel B)
129 { 129 {
130 if (A.h != B.h) 130 if (A.h != B.h)
131 throw new Exception("Cannot divide heightmaps, of different height."); 131 throw new Exception("Cannot divide heightmaps, of different height.");
132 if (A.w != B.w) 132 if (A.w != B.w)
133 throw new Exception("Cannot divide heightmaps, of different width."); 133 throw new Exception("Cannot divide heightmaps, of different width.");
134 134
135 int x, y; 135 int x, y;
136 136
137 for (x = 0; x < A.w; x++) 137 for (x = 0; x < A.w; x++)
138 { 138 {
139 for (y = 0; y < A.h; y++) 139 for (y = 0; y < A.h; y++)
140 { 140 {
141 A.map[x, y] = Math.Pow(A.map[x,y],B.map[x, y]); 141 A.map[x, y] = Math.Pow(A.map[x,y],B.map[x, y]);
142 } 142 }
143 } 143 }
144 144
145 A.SetDiff(); 145 A.SetDiff();
146 146
147 return A; 147 return A;
148 } 148 }
149 149
150 150
151 /* Operator combination of channel and double datatypes */ 151 /* Operator combination of channel and double datatypes */
152 152
153 public static Channel operator +(Channel A, double B) 153 public static Channel operator +(Channel A, double B)
154 { 154 {
155 int x, y; 155 int x, y;
156 156
157 for (x = 0; x < A.w; x++) 157 for (x = 0; x < A.w; x++)
158 { 158 {
159 for (y = 0; y < A.h; y++) 159 for (y = 0; y < A.h; y++)
160 { 160 {
161 A.map[x, y] += B; 161 A.map[x, y] += B;
162 } 162 }
163 } 163 }
164 164
165 if (B != 0) 165 if (B != 0)
166 A.SetDiff(); 166 A.SetDiff();
167 167
168 return A; 168 return A;
169 } 169 }
170 170
171 public static Channel operator -(Channel A, double B) 171 public static Channel operator -(Channel A, double B)
172 { 172 {
173 int x, y; 173 int x, y;
174 174
175 for (x = 0; x < A.w; x++) 175 for (x = 0; x < A.w; x++)
176 { 176 {
177 for (y = 0; y < A.h; y++) 177 for (y = 0; y < A.h; y++)
178 { 178 {
179 A.map[x, y] -= B; 179 A.map[x, y] -= B;
180 } 180 }
181 } 181 }
182 182
183 if (B != 0) 183 if (B != 0)
184 A.SetDiff(); 184 A.SetDiff();
185 185
186 return A; 186 return A;
187 } 187 }
188 188
189 public static Channel operator *(Channel A, double B) 189 public static Channel operator *(Channel A, double B)
190 { 190 {
191 int x, y; 191 int x, y;
192 192
193 for (x = 0; x < A.w; x++) 193 for (x = 0; x < A.w; x++)
194 { 194 {
195 for (y = 0; y < A.h; y++) 195 for (y = 0; y < A.h; y++)
196 { 196 {
197 A.map[x, y] *= B; 197 A.map[x, y] *= B;
198 } 198 }
199 } 199 }
200 200
201 if (B != 1) 201 if (B != 1)
202 A.SetDiff(); 202 A.SetDiff();
203 203
204 return A; 204 return A;
205 } 205 }
206 206
207 public static Channel operator /(Channel A, double B) 207 public static Channel operator /(Channel A, double B)
208 { 208 {
209 int x, y; 209 int x, y;
210 210
211 for (x = 0; x < A.w; x++) 211 for (x = 0; x < A.w; x++)
212 { 212 {
213 for (y = 0; y < A.h; y++) 213 for (y = 0; y < A.h; y++)
214 { 214 {
215 A.map[x, y] /= B; 215 A.map[x, y] /= B;
216 } 216 }
217 } 217 }
218 218
219 if (B != 1) 219 if (B != 1)
220 A.SetDiff(); 220 A.SetDiff();
221 221
222 return A; 222 return A;
223 } 223 }
224 224
225 public static Channel operator ^(Channel A, double B) 225 public static Channel operator ^(Channel A, double B)
226 { 226 {
227 int x, y; 227 int x, y;
228 228
229 for (x = 0; x < A.w; x++) 229 for (x = 0; x < A.w; x++)
230 { 230 {
231 for (y = 0; y < A.h; y++) 231 for (y = 0; y < A.h; y++)
232 { 232 {
233 A.map[x, y] = Math.Pow(A.map[x,y],B); 233 A.map[x, y] = Math.Pow(A.map[x,y],B);
234 } 234 }
235 } 235 }
236 236
237 A.SetDiff(); 237 A.SetDiff();
238 238
239 return A; 239 return A;
240 } 240 }
241 241
242 } 242 }
243} 243}
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Tools/Point2D.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Tools/Point2D.cs
index 69c1148..785ba0d 100644
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Tools/Point2D.cs
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Tools/Point2D.cs
@@ -1,49 +1,49 @@
1/* 1/*
2Redistribution and use in source and binary forms, with or without 2Redistribution and use in source and binary forms, with or without
3modification, are permitted provided that the following conditions are 3modification, are permitted provided that the following conditions are
4met: 4met:
5 5
6 * Redistributions of source code must retain the above copyright 6 * Redistributions of source code must retain the above copyright
7 notice, this list of conditions and the following disclaimer. 7 notice, this list of conditions and the following disclaimer.
8 8
9 * Redistributions in binary form must reproduce the above 9 * Redistributions in binary form must reproduce the above
10 copyright notice, this list of conditions and the following 10 copyright notice, this list of conditions and the following
11 disclaimer in the documentation and/or other materials provided 11 disclaimer in the documentation and/or other materials provided
12 with the distribution. 12 with the distribution.
13 13
14 * Neither the name of libTerrain nor the names of 14 * Neither the name of libTerrain nor the names of
15 its contributors may be used to endorse or promote products 15 its contributors may be used to endorse or promote products
16 derived from this software without specific prior written 16 derived from this software without specific prior written
17 permission. 17 permission.
18 18
19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30*/ 30*/
31 31
32using System; 32using System;
33using System.Collections.Generic; 33using System.Collections.Generic;
34using System.Text; 34using System.Text;
35 35
36namespace libTerrain 36namespace libTerrain
37{ 37{
38 public class Point2D 38 public class Point2D
39 { 39 {
40 public double x; 40 public double x;
41 public double y; 41 public double y;
42 42
43 public Point2D(double X, double Y) 43 public Point2D(double X, double Y)
44 { 44 {
45 x = X; 45 x = X;
46 y = Y; 46 y = Y;
47 } 47 }
48 } 48 }
49} 49}