diff options
Diffstat (limited to 'OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Common.cs')
-rw-r--r-- | OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Common.cs | 554 |
1 files changed, 277 insertions, 277 deletions
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 | ||
30 | using System; | 30 | using System; |
31 | using System.Collections.Generic; | 31 | using System.Collections.Generic; |
32 | using System.Text; | 32 | using System.Text; |
33 | 33 | ||
34 | namespace libTerrain | 34 | namespace 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 | } |