diff options
Diffstat (limited to 'OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Common.cs')
-rw-r--r-- | OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Common.cs | 281 |
1 files changed, 0 insertions, 281 deletions
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Common.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Common.cs deleted file mode 100644 index 0c71ed8..0000000 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Common.cs +++ /dev/null | |||
@@ -1,281 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
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 | ||
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 | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | |||
30 | namespace libTerrain | ||
31 | { | ||
32 | public partial class Channel | ||
33 | { | ||
34 | public int GetWidth() | ||
35 | { | ||
36 | return w; | ||
37 | } | ||
38 | |||
39 | public int GetHeight() | ||
40 | { | ||
41 | return h; | ||
42 | } | ||
43 | |||
44 | public Channel Copy() | ||
45 | { | ||
46 | Channel x = new Channel(w, h); | ||
47 | x.map = (double[,]) map.Clone(); | ||
48 | return x; | ||
49 | } | ||
50 | |||
51 | public void SetDiff() | ||
52 | { | ||
53 | SetDiff(1); | ||
54 | } | ||
55 | |||
56 | public void SetDiff(int val) | ||
57 | { | ||
58 | for (int x = 0; x < w/16; x++) | ||
59 | { | ||
60 | for (int y = 0; y < h/16; y++) | ||
61 | { | ||
62 | diff[x, y] = val; | ||
63 | } | ||
64 | } | ||
65 | } | ||
66 | |||
67 | public void SetDiff(int x, int y) | ||
68 | { | ||
69 | diff[x/16, y/16]++; | ||
70 | } | ||
71 | |||
72 | public void Set(int x, int y, double val) | ||
73 | { | ||
74 | if (x >= w) | ||
75 | throw new Exception("Bounds error while setting pixel (width)"); | ||
76 | if (y >= h) | ||
77 | throw new Exception("Bounds error while setting pixel (height)"); | ||
78 | if (x < 0) | ||
79 | throw new Exception("Bounds error while setting pixel (width)"); | ||
80 | if (y < 0) | ||
81 | throw new Exception("Bounds error while setting pixel (height)"); | ||
82 | |||
83 | if (map[x, y] != val) | ||
84 | { | ||
85 | SetDiff(x, y); | ||
86 | |||
87 | map[x, y] = val; | ||
88 | } | ||
89 | } | ||
90 | |||
91 | public void SetClip(int x, int y, double val) | ||
92 | { | ||
93 | SetDiff(x, y); | ||
94 | |||
95 | if (x >= w) | ||
96 | throw new Exception("Bounds error while setting pixel (width)"); | ||
97 | if (y >= h) | ||
98 | throw new Exception("Bounds error while setting pixel (height)"); | ||
99 | if (x < 0) | ||
100 | throw new Exception("Bounds error while setting pixel (width)"); | ||
101 | if (y < 0) | ||
102 | throw new Exception("Bounds error while setting pixel (height)"); | ||
103 | |||
104 | if (val > 1.0) | ||
105 | val = 1.0; | ||
106 | if (val < 0.0) | ||
107 | val = 0.0; | ||
108 | |||
109 | map[x, y] = val; | ||
110 | } | ||
111 | |||
112 | private double GetBilinearInterpolate(double x, double y) | ||
113 | { | ||
114 | if (x > w - 2.0) | ||
115 | x = w - 2.0; | ||
116 | if (y > h - 2.0) | ||
117 | y = h - 2.0; | ||
118 | if (x < 0.0) | ||
119 | x = 0.0; | ||
120 | if (y < 0.0) | ||
121 | y = 0.0; | ||
122 | |||
123 | int stepSize = 1; | ||
124 | double h00 = Get((int) x, (int) y); | ||
125 | double h10 = Get((int) x + stepSize, (int) y); | ||
126 | double h01 = Get((int) x, (int) y + stepSize); | ||
127 | double h11 = Get((int) x + stepSize, (int) y + stepSize); | ||
128 | double h1 = h00; | ||
129 | double h2 = h10; | ||
130 | double h3 = h01; | ||
131 | double h4 = h11; | ||
132 | double a00 = h1; | ||
133 | double a10 = h2 - h1; | ||
134 | double a01 = h3 - h1; | ||
135 | double a11 = h1 - h2 - h3 + h4; | ||
136 | double partialx = x - (int) x; | ||
137 | double partialz = y - (int) y; | ||
138 | double hi = a00 + (a10*partialx) + (a01*partialz) + (a11*partialx*partialz); | ||
139 | return hi; | ||
140 | } | ||
141 | |||
142 | public double Get(int x, int y) | ||
143 | { | ||
144 | try | ||
145 | { | ||
146 | return map[x, y]; | ||
147 | } | ||
148 | catch (IndexOutOfRangeException) | ||
149 | { | ||
150 | if (x >= w) | ||
151 | x = w - 1; | ||
152 | if (y >= h) | ||
153 | y = h - 1; | ||
154 | if (x < 0) | ||
155 | x = 0; | ||
156 | if (y < 0) | ||
157 | y = 0; | ||
158 | return map[x, y]; | ||
159 | } | ||
160 | } | ||
161 | |||
162 | public void SetWrap(int x, int y, double val) | ||
163 | { | ||
164 | SetDiff(x, y); | ||
165 | |||
166 | map[x%w, y%h] = val; | ||
167 | } | ||
168 | |||
169 | public void SetWrapClip(int x, int y, double val) | ||
170 | { | ||
171 | SetDiff(x, y); | ||
172 | |||
173 | if (val > 1.0) | ||
174 | val = 1.0; | ||
175 | if (val < 0.0) | ||
176 | val = 0.0; | ||
177 | |||
178 | map[x%w, y%h] = val; | ||
179 | } | ||
180 | |||
181 | public void Fill(double val) | ||
182 | { | ||
183 | SetDiff(); | ||
184 | |||
185 | int x, y; | ||
186 | for (x = 0; x < w; x++) | ||
187 | { | ||
188 | for (y = 0; y < h; y++) | ||
189 | { | ||
190 | map[x, y] = val; | ||
191 | } | ||
192 | } | ||
193 | } | ||
194 | |||
195 | public void Fill(double min, double max, double val) | ||
196 | { | ||
197 | SetDiff(); | ||
198 | |||
199 | int x, y; | ||
200 | for (x = 0; x < w; x++) | ||
201 | { | ||
202 | for (y = 0; y < h; y++) | ||
203 | { | ||
204 | if (map[x, y] >= min && map[x, y] <= max) | ||
205 | map[x, y] = val; | ||
206 | } | ||
207 | } | ||
208 | } | ||
209 | |||
210 | public double FindMax() | ||
211 | { | ||
212 | int x, y; | ||
213 | double max = double.MinValue; | ||
214 | |||
215 | for (x = 0; x < w; x++) | ||
216 | { | ||
217 | for (y = 0; y < h; y++) | ||
218 | { | ||
219 | if (map[x, y] > max) | ||
220 | max = map[x, y]; | ||
221 | } | ||
222 | } | ||
223 | |||
224 | return max; | ||
225 | } | ||
226 | |||
227 | public double FindMin() | ||
228 | { | ||
229 | int x, y; | ||
230 | double min = double.MaxValue; | ||
231 | |||
232 | for (x = 0; x < w; x++) | ||
233 | { | ||
234 | for (y = 0; y < h; y++) | ||
235 | { | ||
236 | if (map[x, y] < min) | ||
237 | min = map[x, y]; | ||
238 | } | ||
239 | } | ||
240 | |||
241 | return min; | ||
242 | } | ||
243 | |||
244 | public double Sum() | ||
245 | { | ||
246 | int x, y; | ||
247 | double sum = 0.0; | ||
248 | |||
249 | for (x = 0; x < w; x++) | ||
250 | { | ||
251 | for (y = 0; y < h; y++) | ||
252 | { | ||
253 | sum += map[x, y]; | ||
254 | } | ||
255 | } | ||
256 | |||
257 | return sum; | ||
258 | } | ||
259 | |||
260 | public double Avg() | ||
261 | { | ||
262 | return Sum()/(w*h); | ||
263 | } | ||
264 | |||
265 | public bool ContainsNaN() | ||
266 | { | ||
267 | int x, y; | ||
268 | for (x = 0; x < w; x++) | ||
269 | { | ||
270 | for (y = 0; y < h; y++) | ||
271 | { | ||
272 | double elm = map[x, y]; | ||
273 | |||
274 | if (Double.IsNaN(elm)) | ||
275 | return true; | ||
276 | } | ||
277 | } | ||
278 | return false; | ||
279 | } | ||
280 | } | ||
281 | } | ||