diff options
author | Teravus Ovares (Dan Olivares) | 2009-08-19 14:43:03 -0400 |
---|---|---|
committer | Teravus Ovares (Dan Olivares) | 2009-08-19 14:43:03 -0400 |
commit | de543002aa4d2b05c21db386b5a11628e272f353 (patch) | |
tree | a0a233c89ae8588d8fce98459ee69048a407e011 /OpenSim/Region/Framework/Scenes/Tests | |
parent | *remove conflicts (diff) | |
download | opensim-SC-de543002aa4d2b05c21db386b5a11628e272f353.zip opensim-SC-de543002aa4d2b05c21db386b5a11628e272f353.tar.gz opensim-SC-de543002aa4d2b05c21db386b5a11628e272f353.tar.bz2 opensim-SC-de543002aa4d2b05c21db386b5a11628e272f353.tar.xz |
Add Border (a virtual border management class)
Move Cardinals to it's own file.
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/Tests')
-rw-r--r-- | OpenSim/Region/Framework/Scenes/Tests/BorderTests.cs | 312 |
1 files changed, 312 insertions, 0 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Tests/BorderTests.cs b/OpenSim/Region/Framework/Scenes/Tests/BorderTests.cs new file mode 100644 index 0000000..6f77062 --- /dev/null +++ b/OpenSim/Region/Framework/Scenes/Tests/BorderTests.cs | |||
@@ -0,0 +1,312 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | using OpenMetaverse; | ||
5 | using OpenSim.Region.Framework.Scenes; | ||
6 | |||
7 | using NUnit.Framework; | ||
8 | |||
9 | namespace OpenSim.Region.Framework.Tests | ||
10 | { | ||
11 | [TestFixture] | ||
12 | public class BorderTests | ||
13 | { | ||
14 | |||
15 | [Test] | ||
16 | public void TestCross() | ||
17 | { | ||
18 | List<Border> testborders = new List<Border>(); | ||
19 | |||
20 | Border NorthBorder = new Border(); | ||
21 | NorthBorder.BorderLine = new Vector3(0, 256, 256); //<--- | ||
22 | NorthBorder.CrossDirection = Cardinals.N; | ||
23 | testborders.Add(NorthBorder); | ||
24 | |||
25 | Border SouthBorder = new Border(); | ||
26 | SouthBorder.BorderLine = new Vector3(0, 256, 0); //---> | ||
27 | SouthBorder.CrossDirection = Cardinals.S; | ||
28 | testborders.Add(SouthBorder); | ||
29 | |||
30 | Border EastBorder = new Border(); | ||
31 | EastBorder.BorderLine = new Vector3(0, 256, 256); //<--- | ||
32 | EastBorder.CrossDirection = Cardinals.E; | ||
33 | testborders.Add(EastBorder); | ||
34 | |||
35 | Border WestBorder = new Border(); | ||
36 | WestBorder.BorderLine = new Vector3(0, 256, 0); //---> | ||
37 | WestBorder.CrossDirection = Cardinals.W; | ||
38 | testborders.Add(WestBorder); | ||
39 | |||
40 | Vector3 position = new Vector3(200,200,21); | ||
41 | |||
42 | foreach (Border b in testborders) | ||
43 | { | ||
44 | Assert.That(!b.TestCross(position)); | ||
45 | |||
46 | } | ||
47 | |||
48 | position = new Vector3(200,280,21); | ||
49 | Assert.That(NorthBorder.TestCross(position)); | ||
50 | |||
51 | |||
52 | |||
53 | // Test automatic border crossing | ||
54 | // by setting the border crossing aabb to be the whole region | ||
55 | position = new Vector3(25,25,21); // safely within one 256m region | ||
56 | |||
57 | // The Z value of the BorderLine is reversed, making all positions within the region | ||
58 | // trigger bordercross | ||
59 | |||
60 | SouthBorder.BorderLine = new Vector3(0,256,256); // automatic border cross in the region | ||
61 | Assert.That(SouthBorder.TestCross(position)); | ||
62 | |||
63 | NorthBorder.BorderLine = new Vector3(0, 256, 0); // automatic border cross in the region | ||
64 | Assert.That(NorthBorder.TestCross(position)); | ||
65 | |||
66 | EastBorder.BorderLine = new Vector3(0, 256, 0); // automatic border cross in the region | ||
67 | Assert.That(EastBorder.TestCross(position)); | ||
68 | |||
69 | WestBorder.BorderLine = new Vector3(0, 256, 255); // automatic border cross in the region | ||
70 | Assert.That(WestBorder.TestCross(position)); | ||
71 | |||
72 | } | ||
73 | |||
74 | [Test] | ||
75 | public void TestCrossSquare512() | ||
76 | { | ||
77 | List<Border> testborders = new List<Border>(); | ||
78 | |||
79 | Border NorthBorder = new Border(); | ||
80 | NorthBorder.BorderLine = new Vector3(0, 512, 512); | ||
81 | NorthBorder.CrossDirection = Cardinals.N; | ||
82 | testborders.Add(NorthBorder); | ||
83 | |||
84 | Border SouthBorder = new Border(); | ||
85 | SouthBorder.BorderLine = new Vector3(0, 512, 0); | ||
86 | SouthBorder.CrossDirection = Cardinals.S; | ||
87 | testborders.Add(SouthBorder); | ||
88 | |||
89 | Border EastBorder = new Border(); | ||
90 | EastBorder.BorderLine = new Vector3(0, 512, 512); | ||
91 | EastBorder.CrossDirection = Cardinals.E; | ||
92 | testborders.Add(EastBorder); | ||
93 | |||
94 | Border WestBorder = new Border(); | ||
95 | WestBorder.BorderLine = new Vector3(0, 512, 0); | ||
96 | WestBorder.CrossDirection = Cardinals.W; | ||
97 | testborders.Add(WestBorder); | ||
98 | |||
99 | Vector3 position = new Vector3(450,220,21); | ||
100 | |||
101 | foreach (Border b in testborders) | ||
102 | { | ||
103 | Assert.That(!b.TestCross(position)); | ||
104 | |||
105 | } | ||
106 | |||
107 | //Trigger east border | ||
108 | position = new Vector3(513,220,21); | ||
109 | foreach (Border b in testborders) | ||
110 | { | ||
111 | if (b.CrossDirection == Cardinals.E) | ||
112 | Assert.That(b.TestCross(position)); | ||
113 | else | ||
114 | Assert.That(!b.TestCross(position)); | ||
115 | |||
116 | } | ||
117 | |||
118 | //Trigger west border | ||
119 | position = new Vector3(-1, 220, 21); | ||
120 | foreach (Border b in testborders) | ||
121 | { | ||
122 | if (b.CrossDirection == Cardinals.W) | ||
123 | Assert.That(b.TestCross(position)); | ||
124 | else | ||
125 | Assert.That(!b.TestCross(position)); | ||
126 | |||
127 | } | ||
128 | |||
129 | //Trigger north border | ||
130 | position = new Vector3(220, 513, 21); | ||
131 | foreach (Border b in testborders) | ||
132 | { | ||
133 | if (b.CrossDirection == Cardinals.N) | ||
134 | Assert.That(b.TestCross(position)); | ||
135 | else | ||
136 | Assert.That(!b.TestCross(position)); | ||
137 | |||
138 | } | ||
139 | |||
140 | //Trigger south border | ||
141 | position = new Vector3(220, -1, 21); | ||
142 | foreach (Border b in testborders) | ||
143 | { | ||
144 | if (b.CrossDirection == Cardinals.S) | ||
145 | Assert.That(b.TestCross(position)); | ||
146 | else | ||
147 | Assert.That(!b.TestCross(position)); | ||
148 | |||
149 | } | ||
150 | |||
151 | } | ||
152 | |||
153 | [Test] | ||
154 | public void TestCrossRectangle512x256() | ||
155 | { | ||
156 | List<Border> testborders = new List<Border>(); | ||
157 | |||
158 | Border NorthBorder = new Border(); | ||
159 | NorthBorder.BorderLine = new Vector3(0, 512, 256); | ||
160 | NorthBorder.CrossDirection = Cardinals.N; | ||
161 | testborders.Add(NorthBorder); | ||
162 | |||
163 | Border SouthBorder = new Border(); | ||
164 | SouthBorder.BorderLine = new Vector3(0, 512, 0); | ||
165 | SouthBorder.CrossDirection = Cardinals.S; | ||
166 | testborders.Add(SouthBorder); | ||
167 | |||
168 | Border EastBorder = new Border(); | ||
169 | EastBorder.BorderLine = new Vector3(0, 256, 512); | ||
170 | EastBorder.CrossDirection = Cardinals.E; | ||
171 | testborders.Add(EastBorder); | ||
172 | |||
173 | Border WestBorder = new Border(); | ||
174 | WestBorder.BorderLine = new Vector3(0, 256, 0); | ||
175 | WestBorder.CrossDirection = Cardinals.W; | ||
176 | testborders.Add(WestBorder); | ||
177 | |||
178 | Vector3 position = new Vector3(450, 220, 21); | ||
179 | |||
180 | foreach (Border b in testborders) | ||
181 | { | ||
182 | Assert.That(!b.TestCross(position)); | ||
183 | |||
184 | } | ||
185 | |||
186 | //Trigger east border | ||
187 | position = new Vector3(513, 220, 21); | ||
188 | foreach (Border b in testborders) | ||
189 | { | ||
190 | if (b.CrossDirection == Cardinals.E) | ||
191 | Assert.That(b.TestCross(position)); | ||
192 | else | ||
193 | Assert.That(!b.TestCross(position)); | ||
194 | |||
195 | } | ||
196 | |||
197 | //Trigger west border | ||
198 | position = new Vector3(-1, 220, 21); | ||
199 | foreach (Border b in testborders) | ||
200 | { | ||
201 | if (b.CrossDirection == Cardinals.W) | ||
202 | Assert.That(b.TestCross(position)); | ||
203 | else | ||
204 | Assert.That(!b.TestCross(position)); | ||
205 | |||
206 | } | ||
207 | |||
208 | //Trigger north border | ||
209 | position = new Vector3(220, 257, 21); | ||
210 | foreach (Border b in testborders) | ||
211 | { | ||
212 | if (b.CrossDirection == Cardinals.N) | ||
213 | Assert.That(b.TestCross(position)); | ||
214 | else | ||
215 | Assert.That(!b.TestCross(position)); | ||
216 | |||
217 | } | ||
218 | |||
219 | //Trigger south border | ||
220 | position = new Vector3(220, -1, 21); | ||
221 | foreach (Border b in testborders) | ||
222 | { | ||
223 | if (b.CrossDirection == Cardinals.S) | ||
224 | Assert.That(b.TestCross(position)); | ||
225 | else | ||
226 | Assert.That(!b.TestCross(position)); | ||
227 | |||
228 | } | ||
229 | } | ||
230 | |||
231 | [Test] | ||
232 | public void TestCrossOdd512x512w256hole() | ||
233 | { | ||
234 | List<Border> testborders = new List<Border>(); | ||
235 | // 512____ | ||
236 | // | | | ||
237 | // 256__| |___ | ||
238 | // | | | ||
239 | // |______| | ||
240 | // 0 | 512 | ||
241 | // 256 | ||
242 | |||
243 | // Compound North border since the hole is at the top | ||
244 | Border NorthBorder1 = new Border(); | ||
245 | NorthBorder1.BorderLine = new Vector3(0, 256, 512); | ||
246 | NorthBorder1.CrossDirection = Cardinals.N; | ||
247 | testborders.Add(NorthBorder1); | ||
248 | |||
249 | Border NorthBorder2 = new Border(); | ||
250 | NorthBorder2.BorderLine = new Vector3(256, 512, 256); | ||
251 | NorthBorder2.CrossDirection = Cardinals.N; | ||
252 | testborders.Add(NorthBorder2); | ||
253 | |||
254 | Border SouthBorder = new Border(); | ||
255 | SouthBorder.BorderLine = new Vector3(0, 512, 0); | ||
256 | SouthBorder.CrossDirection = Cardinals.S; | ||
257 | testborders.Add(SouthBorder); | ||
258 | |||
259 | //Compound East border | ||
260 | Border EastBorder1 = new Border(); | ||
261 | EastBorder1.BorderLine = new Vector3(0, 256, 512); | ||
262 | EastBorder1.CrossDirection = Cardinals.E; | ||
263 | testborders.Add(EastBorder1); | ||
264 | |||
265 | Border EastBorder2 = new Border(); | ||
266 | EastBorder2.BorderLine = new Vector3(257, 512, 256); | ||
267 | EastBorder2.CrossDirection = Cardinals.E; | ||
268 | testborders.Add(EastBorder2); | ||
269 | |||
270 | |||
271 | |||
272 | Border WestBorder = new Border(); | ||
273 | WestBorder.BorderLine = new Vector3(0, 512, 0); | ||
274 | WestBorder.CrossDirection = Cardinals.W; | ||
275 | testborders.Add(WestBorder); | ||
276 | |||
277 | Vector3 position = new Vector3(450, 220, 21); | ||
278 | |||
279 | foreach (Border b in testborders) | ||
280 | { | ||
281 | Assert.That(!b.TestCross(position)); | ||
282 | |||
283 | } | ||
284 | |||
285 | position = new Vector3(220, 450, 21); | ||
286 | |||
287 | foreach (Border b in testborders) | ||
288 | { | ||
289 | Assert.That(!b.TestCross(position)); | ||
290 | |||
291 | } | ||
292 | |||
293 | bool result = false; | ||
294 | int bordersTriggered = 0; | ||
295 | |||
296 | position = new Vector3(450, 450, 21); | ||
297 | |||
298 | foreach (Border b in testborders) | ||
299 | { | ||
300 | if (b.TestCross(position)) | ||
301 | { | ||
302 | bordersTriggered++; | ||
303 | result = true; | ||
304 | } | ||
305 | } | ||
306 | |||
307 | Assert.That(result); | ||
308 | Assert.That(bordersTriggered == 2); | ||
309 | |||
310 | } | ||
311 | } | ||
312 | } | ||