clockwerk-opensim – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 vero 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 OpenSimulator 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 using System.Collections.Generic;
30 using System.IO;
31 using System.Text;
32 using NUnit.Framework;
33 using OpenMetaverse;
34 using OpenSim.Region.Framework.Scenes;
35 using OpenSim.Tests.Common;
36  
37 namespace OpenSim.Region.Framework.Scenes.Tests
38 {
39 [TestFixture]
40 public class BorderTests : OpenSimTestCase
41 {
42 [Test]
43 public void TestCross()
44 {
45 TestHelpers.InMethod();
46  
47 List<Border> testborders = new List<Border>();
48  
49 Border NorthBorder = new Border();
50 NorthBorder.BorderLine = new Vector3(0, 256, 256); //<---
51 NorthBorder.CrossDirection = Cardinals.N;
52 testborders.Add(NorthBorder);
53  
54 Border SouthBorder = new Border();
55 SouthBorder.BorderLine = new Vector3(0, 256, 0); //--->
56 SouthBorder.CrossDirection = Cardinals.S;
57 testborders.Add(SouthBorder);
58  
59 Border EastBorder = new Border();
60 EastBorder.BorderLine = new Vector3(0, 256, 256); //<---
61 EastBorder.CrossDirection = Cardinals.E;
62 testborders.Add(EastBorder);
63  
64 Border WestBorder = new Border();
65 WestBorder.BorderLine = new Vector3(0, 256, 0); //--->
66 WestBorder.CrossDirection = Cardinals.W;
67 testborders.Add(WestBorder);
68  
69 Vector3 position = new Vector3(200,200,21);
70  
71 foreach (Border b in testborders)
72 Assert.That(!b.TestCross(position));
73  
74 position = new Vector3(200,280,21);
75 Assert.That(NorthBorder.TestCross(position));
76  
77 // Test automatic border crossing
78 // by setting the border crossing aabb to be the whole region
79 position = new Vector3(25,25,21); // safely within one 256m region
80  
81 // The Z value of the BorderLine is reversed, making all positions within the region
82 // trigger bordercross
83  
84 SouthBorder.BorderLine = new Vector3(0,256,256); // automatic border cross in the region
85 Assert.That(SouthBorder.TestCross(position));
86  
87 NorthBorder.BorderLine = new Vector3(0, 256, 0); // automatic border cross in the region
88 Assert.That(NorthBorder.TestCross(position));
89  
90 EastBorder.BorderLine = new Vector3(0, 256, 0); // automatic border cross in the region
91 Assert.That(EastBorder.TestCross(position));
92  
93 WestBorder.BorderLine = new Vector3(0, 256, 255); // automatic border cross in the region
94 Assert.That(WestBorder.TestCross(position));
95 }
96  
97 [Test]
98 public void TestCrossSquare512()
99 {
100 TestHelpers.InMethod();
101  
102 List<Border> testborders = new List<Border>();
103  
104 Border NorthBorder = new Border();
105 NorthBorder.BorderLine = new Vector3(0, 512, 512);
106 NorthBorder.CrossDirection = Cardinals.N;
107 testborders.Add(NorthBorder);
108  
109 Border SouthBorder = new Border();
110 SouthBorder.BorderLine = new Vector3(0, 512, 0);
111 SouthBorder.CrossDirection = Cardinals.S;
112 testborders.Add(SouthBorder);
113  
114 Border EastBorder = new Border();
115 EastBorder.BorderLine = new Vector3(0, 512, 512);
116 EastBorder.CrossDirection = Cardinals.E;
117 testborders.Add(EastBorder);
118  
119 Border WestBorder = new Border();
120 WestBorder.BorderLine = new Vector3(0, 512, 0);
121 WestBorder.CrossDirection = Cardinals.W;
122 testborders.Add(WestBorder);
123  
124 Vector3 position = new Vector3(450,220,21);
125  
126 foreach (Border b in testborders)
127 {
128 Assert.That(!b.TestCross(position));
129  
130 }
131  
132 //Trigger east border
133 position = new Vector3(513,220,21);
134 foreach (Border b in testborders)
135 {
136 if (b.CrossDirection == Cardinals.E)
137 Assert.That(b.TestCross(position));
138 else
139 Assert.That(!b.TestCross(position));
140  
141 }
142  
143 //Trigger west border
144 position = new Vector3(-1, 220, 21);
145 foreach (Border b in testborders)
146 {
147 if (b.CrossDirection == Cardinals.W)
148 Assert.That(b.TestCross(position));
149 else
150 Assert.That(!b.TestCross(position));
151  
152 }
153  
154 //Trigger north border
155 position = new Vector3(220, 513, 21);
156 foreach (Border b in testborders)
157 {
158 if (b.CrossDirection == Cardinals.N)
159 Assert.That(b.TestCross(position));
160 else
161 Assert.That(!b.TestCross(position));
162  
163 }
164  
165 //Trigger south border
166 position = new Vector3(220, -1, 21);
167 foreach (Border b in testborders)
168 {
169 if (b.CrossDirection == Cardinals.S)
170 Assert.That(b.TestCross(position));
171 else
172 Assert.That(!b.TestCross(position));
173  
174 }
175 }
176  
177 [Test]
178 public void TestCrossRectangle512x256()
179 {
180 TestHelpers.InMethod();
181  
182 List<Border> testborders = new List<Border>();
183  
184 Border NorthBorder = new Border();
185 NorthBorder.BorderLine = new Vector3(0, 512, 256);
186 NorthBorder.CrossDirection = Cardinals.N;
187 testborders.Add(NorthBorder);
188  
189 Border SouthBorder = new Border();
190 SouthBorder.BorderLine = new Vector3(0, 512, 0);
191 SouthBorder.CrossDirection = Cardinals.S;
192 testborders.Add(SouthBorder);
193  
194 Border EastBorder = new Border();
195 EastBorder.BorderLine = new Vector3(0, 256, 512);
196 EastBorder.CrossDirection = Cardinals.E;
197 testborders.Add(EastBorder);
198  
199 Border WestBorder = new Border();
200 WestBorder.BorderLine = new Vector3(0, 256, 0);
201 WestBorder.CrossDirection = Cardinals.W;
202 testborders.Add(WestBorder);
203  
204 Vector3 position = new Vector3(450, 220, 21);
205  
206 foreach (Border b in testborders)
207 {
208 Assert.That(!b.TestCross(position));
209  
210 }
211  
212 //Trigger east border
213 position = new Vector3(513, 220, 21);
214 foreach (Border b in testborders)
215 {
216 if (b.CrossDirection == Cardinals.E)
217 Assert.That(b.TestCross(position));
218 else
219 Assert.That(!b.TestCross(position));
220  
221 }
222  
223 //Trigger west border
224 position = new Vector3(-1, 220, 21);
225 foreach (Border b in testborders)
226 {
227 if (b.CrossDirection == Cardinals.W)
228 Assert.That(b.TestCross(position));
229 else
230 Assert.That(!b.TestCross(position));
231  
232 }
233  
234 //Trigger north border
235 position = new Vector3(220, 257, 21);
236 foreach (Border b in testborders)
237 {
238 if (b.CrossDirection == Cardinals.N)
239 Assert.That(b.TestCross(position));
240 else
241 Assert.That(!b.TestCross(position));
242  
243 }
244  
245 //Trigger south border
246 position = new Vector3(220, -1, 21);
247 foreach (Border b in testborders)
248 {
249 if (b.CrossDirection == Cardinals.S)
250 Assert.That(b.TestCross(position));
251 else
252 Assert.That(!b.TestCross(position));
253  
254 }
255 }
256  
257 [Test]
258 public void TestCrossOdd512x512w256hole()
259 {
260 TestHelpers.InMethod();
261  
262 List<Border> testborders = new List<Border>();
263 // 512____
264 // | |
265 // 256__| |___
266 // | |
267 // |______|
268 // 0 | 512
269 // 256
270  
271 // Compound North border since the hole is at the top
272 Border NorthBorder1 = new Border();
273 NorthBorder1.BorderLine = new Vector3(0, 256, 512);
274 NorthBorder1.CrossDirection = Cardinals.N;
275 testborders.Add(NorthBorder1);
276  
277 Border NorthBorder2 = new Border();
278 NorthBorder2.BorderLine = new Vector3(256, 512, 256);
279 NorthBorder2.CrossDirection = Cardinals.N;
280 testborders.Add(NorthBorder2);
281  
282 Border SouthBorder = new Border();
283 SouthBorder.BorderLine = new Vector3(0, 512, 0);
284 SouthBorder.CrossDirection = Cardinals.S;
285 testborders.Add(SouthBorder);
286  
287 //Compound East border
288 Border EastBorder1 = new Border();
289 EastBorder1.BorderLine = new Vector3(0, 256, 512);
290 EastBorder1.CrossDirection = Cardinals.E;
291 testborders.Add(EastBorder1);
292  
293 Border EastBorder2 = new Border();
294 EastBorder2.BorderLine = new Vector3(257, 512, 256);
295 EastBorder2.CrossDirection = Cardinals.E;
296 testborders.Add(EastBorder2);
297  
298  
299  
300 Border WestBorder = new Border();
301 WestBorder.BorderLine = new Vector3(0, 512, 0);
302 WestBorder.CrossDirection = Cardinals.W;
303 testborders.Add(WestBorder);
304  
305 Vector3 position = new Vector3(450, 220, 21);
306  
307 foreach (Border b in testborders)
308 {
309 Assert.That(!b.TestCross(position));
310  
311 }
312  
313 position = new Vector3(220, 450, 21);
314  
315 foreach (Border b in testborders)
316 {
317 Assert.That(!b.TestCross(position));
318  
319 }
320  
321 bool result = false;
322 int bordersTriggered = 0;
323  
324 position = new Vector3(450, 450, 21);
325  
326 foreach (Border b in testborders)
327 {
328 if (b.TestCross(position))
329 {
330 bordersTriggered++;
331 result = true;
332 }
333 }
334  
335 Assert.That(result);
336 Assert.That(bordersTriggered == 2);
337  
338 }
339 }
340 }