aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework/Scenes
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Framework/Scenes')
-rw-r--r--OpenSim/Region/Framework/Scenes/Border.cs131
-rw-r--r--OpenSim/Region/Framework/Scenes/Cardinals.cs11
-rw-r--r--OpenSim/Region/Framework/Scenes/Scene.cs107
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs4
-rw-r--r--OpenSim/Region/Framework/Scenes/ScenePresence.cs22
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/BorderTests.cs312
6 files changed, 570 insertions, 17 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Border.cs b/OpenSim/Region/Framework/Scenes/Border.cs
new file mode 100644
index 0000000..19ecb4f
--- /dev/null
+++ b/OpenSim/Region/Framework/Scenes/Border.cs
@@ -0,0 +1,131 @@
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
28using System;
29using System.Collections.Generic;
30using System.Text;
31using OpenMetaverse;
32
33namespace OpenSim.Region.Framework.Scenes
34{
35 public class Border
36 {
37
38 /// <summary>
39 /// Line perpendicular to the Direction Cardinal. Z value is the
40 /// </summary>
41 public Vector3 BorderLine = Vector3.Zero;
42
43 /// <summary>
44 /// Direction cardinal of the border, think, 'which side of the region this is'. EX South border: Cardinal.S
45 /// </summary>
46 public Cardinals CrossDirection = Cardinals.N;
47 public uint TriggerRegionX = 0;
48 public uint TriggerRegionY = 0;
49
50 public Border()
51 {
52 }
53
54 /// <summary>
55 /// Creates a Border. The line is perpendicular to the direction cardinal.
56 /// IE: if the direction cardinal is South, the line is West->East
57 /// </summary>
58 /// <param name="lineStart">The starting point for the line of the border.
59 /// The position of an object must be greater then this for this border to trigger.
60 /// Perpendicular to the direction cardinal</param>
61 /// <param name="lineEnd">The ending point for the line of the border.
62 /// The position of an object must be less then this for this border to trigger.
63 /// Perpendicular to the direction cardinal</param>
64 /// <param name="triggerCoordinate">The position that triggers border the border
65 /// cross parallel to the direction cardinal. On the North cardinal, this
66 /// normally 256. On the South cardinal, it's normally 0. Any position past this
67 /// point on the cartesian coordinate will trigger the border cross as long as it
68 /// falls within the line start and the line end.</param>
69 /// <param name="triggerRegionX">When this border triggers, teleport to this regionX
70 /// in the grid</param>
71 /// <param name="triggerRegionY">When this border triggers, teleport to this regionY
72 /// in the grid</param>
73 /// <param name="direction">Cardinal for border direction. Think, 'which side of the
74 /// region is this'</param>
75 public Border(float lineStart, float lineEnd, float triggerCoordinate, uint triggerRegionX,
76 uint triggerRegionY, Cardinals direction)
77 {
78 BorderLine = new Vector3(lineStart,lineEnd,triggerCoordinate);
79 CrossDirection = direction;
80 TriggerRegionX = triggerRegionX;
81 TriggerRegionY = triggerRegionY;
82 }
83
84 public bool TestCross(Vector3 position)
85 {
86 bool result = false;
87 switch (CrossDirection)
88 {
89 case Cardinals.N: // x+0, y+1
90 if (position.X >= BorderLine.X && position.X <=BorderLine.Y && position.Y > BorderLine.Z )
91 {
92 return true;
93 }
94 break;
95 case Cardinals.NE: // x+1, y+1
96 break;
97 case Cardinals.E: // x+1, y+0
98 if (position.Y >= BorderLine.X && position.Y <= BorderLine.Y && position.X > BorderLine.Z)
99 {
100 return true;
101 }
102 break;
103 case Cardinals.SE: // x+1, y-1
104 break;
105 case Cardinals.S: // x+0, y-1
106 if (position.X >= BorderLine.X && position.X <= BorderLine.Y && position.Y < BorderLine.Z)
107 {
108 return true;
109 }
110 break;
111 case Cardinals.SW: // x-1, y-1
112 break;
113 case Cardinals.W: // x-1, y+0
114 if (position.Y >= BorderLine.X && position.Y <= BorderLine.Y && position.X < BorderLine.Z)
115 {
116 return true;
117 }
118 break;
119 case Cardinals.NW: // x-1, y+1
120 break;
121
122
123 }
124
125 return result;
126 }
127
128 }
129
130
131}
diff --git a/OpenSim/Region/Framework/Scenes/Cardinals.cs b/OpenSim/Region/Framework/Scenes/Cardinals.cs
new file mode 100644
index 0000000..692389a
--- /dev/null
+++ b/OpenSim/Region/Framework/Scenes/Cardinals.cs
@@ -0,0 +1,11 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace OpenSim.Region.Framework.Scenes
6{
7 public enum Cardinals
8 {
9 N = 1, NE, E, SE, S, SW, W, NW
10 }
11}
diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs
index d1f7a4b..cb4e443 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.cs
@@ -81,6 +81,11 @@ namespace OpenSim.Region.Framework.Scenes
81 protected List<RegionInfo> m_regionRestartNotifyList = new List<RegionInfo>(); 81 protected List<RegionInfo> m_regionRestartNotifyList = new List<RegionInfo>();
82 protected List<RegionInfo> m_neighbours = new List<RegionInfo>(); 82 protected List<RegionInfo> m_neighbours = new List<RegionInfo>();
83 83
84 public List<Border> NorthBorders = new List<Border>();
85 public List<Border> EastBorders = new List<Border>();
86 public List<Border> SouthBorders = new List<Border>();
87 public List<Border> WestBorders = new List<Border>();
88
84 /// <value> 89 /// <value>
85 /// The scene graph for this scene 90 /// The scene graph for this scene
86 /// </value> 91 /// </value>
@@ -326,6 +331,28 @@ namespace OpenSim.Region.Framework.Scenes
326 m_config = config; 331 m_config = config;
327 332
328 Random random = new Random(); 333 Random random = new Random();
334
335 Border northBorder = new Border();
336 northBorder.BorderLine = new Vector3(0, (int)Constants.RegionSize, (int)Constants.RegionSize); //<---
337 northBorder.CrossDirection = Cardinals.N;
338 NorthBorders.Add(northBorder);
339
340 Border southBorder = new Border();
341 southBorder.BorderLine = new Vector3(0, (int)Constants.RegionSize, 0); //--->
342 southBorder.CrossDirection = Cardinals.S;
343 SouthBorders.Add(southBorder);
344
345 Border eastBorder = new Border();
346 eastBorder.BorderLine = new Vector3(0, (int)Constants.RegionSize, (int)Constants.RegionSize); //<---
347 eastBorder.CrossDirection = Cardinals.E;
348 EastBorders.Add(eastBorder);
349
350 Border westBorder = new Border();
351 westBorder.BorderLine = new Vector3(0, (int)Constants.RegionSize, 0); //--->
352 westBorder.CrossDirection = Cardinals.W;
353 WestBorders.Add(westBorder);
354
355
329 m_lastAllocatedLocalId = (uint)(random.NextDouble() * (double)(uint.MaxValue/2))+(uint)(uint.MaxValue/4); 356 m_lastAllocatedLocalId = (uint)(random.NextDouble() * (double)(uint.MaxValue/2))+(uint)(uint.MaxValue/4);
330 m_moduleLoader = moduleLoader; 357 m_moduleLoader = moduleLoader;
331 m_authenticateHandler = authen; 358 m_authenticateHandler = authen;
@@ -455,6 +482,26 @@ namespace OpenSim.Region.Framework.Scenes
455 /// <param name="regInfo"></param> 482 /// <param name="regInfo"></param>
456 public Scene(RegionInfo regInfo) 483 public Scene(RegionInfo regInfo)
457 { 484 {
485 Border northBorder = new Border();
486 northBorder.BorderLine = new Vector3(0, (int)Constants.RegionSize, (int)Constants.RegionSize); //<---
487 northBorder.CrossDirection = Cardinals.N;
488 NorthBorders.Add(northBorder);
489
490 Border southBorder = new Border();
491 southBorder.BorderLine = new Vector3(0, (int)Constants.RegionSize, 0); //--->
492 southBorder.CrossDirection = Cardinals.S;
493 SouthBorders.Add(southBorder);
494
495 Border eastBorder = new Border();
496 eastBorder.BorderLine = new Vector3(0, (int)Constants.RegionSize, (int)Constants.RegionSize); //<---
497 eastBorder.CrossDirection = Cardinals.E;
498 EastBorders.Add(eastBorder);
499
500 Border westBorder = new Border();
501 westBorder.BorderLine = new Vector3(0, (int)Constants.RegionSize, 0); //--->
502 westBorder.CrossDirection = Cardinals.W;
503 WestBorders.Add(westBorder);
504
458 m_regInfo = regInfo; 505 m_regInfo = regInfo;
459 m_eventManager = new EventManager(); 506 m_eventManager = new EventManager();
460 } 507 }
@@ -1659,14 +1706,16 @@ namespace OpenSim.Region.Framework.Scenes
1659 ulong newRegionHandle = 0; 1706 ulong newRegionHandle = 0;
1660 Vector3 pos = attemptedPosition; 1707 Vector3 pos = attemptedPosition;
1661 1708
1662 if (attemptedPosition.X > Constants.RegionSize + 0.1f) 1709
1710
1711 if (TestBorderCross(attemptedPosition, Cardinals.E))
1663 { 1712 {
1664 pos.X = ((pos.X - Constants.RegionSize)); 1713 pos.X = ((pos.X - Constants.RegionSize));
1665 newRegionHandle 1714 newRegionHandle
1666 = Util.UIntsToLong((uint)((thisx + 1) * Constants.RegionSize), (uint)(thisy * Constants.RegionSize)); 1715 = Util.UIntsToLong((uint)((thisx + 1) * Constants.RegionSize), (uint)(thisy * Constants.RegionSize));
1667 // x + 1 1716 // x + 1
1668 } 1717 }
1669 else if (attemptedPosition.X < -0.1f) 1718 else if (TestBorderCross(attemptedPosition, Cardinals.W))
1670 { 1719 {
1671 pos.X = ((pos.X + Constants.RegionSize)); 1720 pos.X = ((pos.X + Constants.RegionSize));
1672 newRegionHandle 1721 newRegionHandle
@@ -1674,14 +1723,14 @@ namespace OpenSim.Region.Framework.Scenes
1674 // x - 1 1723 // x - 1
1675 } 1724 }
1676 1725
1677 if (attemptedPosition.Y > Constants.RegionSize + 0.1f) 1726 if (TestBorderCross(attemptedPosition, Cardinals.N))
1678 { 1727 {
1679 pos.Y = ((pos.Y - Constants.RegionSize)); 1728 pos.Y = ((pos.Y - Constants.RegionSize));
1680 newRegionHandle 1729 newRegionHandle
1681 = Util.UIntsToLong((uint)(thisx * Constants.RegionSize), (uint)((thisy + 1) * Constants.RegionSize)); 1730 = Util.UIntsToLong((uint)(thisx * Constants.RegionSize), (uint)((thisy + 1) * Constants.RegionSize));
1682 // y + 1 1731 // y + 1
1683 } 1732 }
1684 else if (attemptedPosition.Y < -0.1f) 1733 else if (TestBorderCross(attemptedPosition, Cardinals.S))
1685 { 1734 {
1686 pos.Y = ((pos.Y + Constants.RegionSize)); 1735 pos.Y = ((pos.Y + Constants.RegionSize));
1687 newRegionHandle 1736 newRegionHandle
@@ -1701,6 +1750,56 @@ namespace OpenSim.Region.Framework.Scenes
1701 } 1750 }
1702 } 1751 }
1703 1752
1753 public bool TestBorderCross(Vector3 position, Cardinals border)
1754 {
1755 switch (border)
1756 {
1757 case Cardinals.N:
1758 lock (NorthBorders)
1759 {
1760 foreach(Border b in NorthBorders)
1761 {
1762 if (b.TestCross(position))
1763 return true;
1764 }
1765 }
1766 break;
1767 case Cardinals.E:
1768 lock (EastBorders)
1769 {
1770 foreach (Border b in EastBorders)
1771 {
1772 if (b.TestCross(position))
1773 return true;
1774 }
1775 }
1776 break;
1777 case Cardinals.S:
1778 lock (SouthBorders)
1779 {
1780 foreach (Border b in SouthBorders)
1781 {
1782 if (b.TestCross(position))
1783 return true;
1784 }
1785 }
1786 break;
1787 case Cardinals.W:
1788 lock (WestBorders)
1789 {
1790 foreach (Border b in WestBorders)
1791 {
1792 if (b.TestCross(position))
1793 return true;
1794 }
1795 }
1796 break;
1797
1798 }
1799 return false;
1800 }
1801
1802
1704 /// <summary> 1803 /// <summary>
1705 /// Move the given scene object into a new region 1804 /// Move the given scene object into a new region
1706 /// </summary> 1805 /// </summary>
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
index 1b541c4..e5c6bf1 100644
--- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
@@ -264,7 +264,9 @@ namespace OpenSim.Region.Framework.Scenes
264 { 264 {
265 Vector3 val = value; 265 Vector3 val = value;
266 266
267 if ((val.X > 257f || val.X < -1f || val.Y > 257f || val.Y < -1f) && !IsAttachment) 267 if ((m_scene.TestBorderCross(val,Cardinals.E) || m_scene.TestBorderCross(val,Cardinals.W)
268 || m_scene.TestBorderCross(val, Cardinals.N) || m_scene.TestBorderCross(val, Cardinals.S))
269 && !IsAttachment)
268 { 270 {
269 m_scene.CrossPrimGroupIntoNewRegion(val, this, true); 271 m_scene.CrossPrimGroupIntoNewRegion(val, this, true);
270 } 272 }
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index ff97183..aae1823 100644
--- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs
+++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
@@ -222,10 +222,7 @@ namespace OpenSim.Region.Framework.Scenes
222 DIR_CONTROL_FLAG_DOWN_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG 222 DIR_CONTROL_FLAG_DOWN_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG
223 } 223 }
224 224
225 protected enum Cardinals 225
226 {
227 N=1,NE,E,SE,S,SW,W,NW
228 }
229 /// <summary> 226 /// <summary>
230 /// Position at which a significant movement was made 227 /// Position at which a significant movement was made
231 /// </summary> 228 /// </summary>
@@ -2833,27 +2830,28 @@ namespace OpenSim.Region.Framework.Scenes
2833 if (!IsInTransit) 2830 if (!IsInTransit)
2834 { 2831 {
2835 // Checks if where it's headed exists a region 2832 // Checks if where it's headed exists a region
2836 if (pos2.X < 0) 2833
2834 if (m_scene.TestBorderCross(pos2, Cardinals.W))
2837 { 2835 {
2838 if (pos2.Y < 0) 2836 if (m_scene.TestBorderCross(pos2, Cardinals.S))
2839 neighbor = HaveNeighbor(Cardinals.SW, ref fix); 2837 neighbor = HaveNeighbor(Cardinals.SW, ref fix);
2840 else if (pos2.Y > Constants.RegionSize) 2838 else if (m_scene.TestBorderCross(pos2, Cardinals.N))
2841 neighbor = HaveNeighbor(Cardinals.NW, ref fix); 2839 neighbor = HaveNeighbor(Cardinals.NW, ref fix);
2842 else 2840 else
2843 neighbor = HaveNeighbor(Cardinals.W, ref fix); 2841 neighbor = HaveNeighbor(Cardinals.W, ref fix);
2844 } 2842 }
2845 else if (pos2.X > Constants.RegionSize) 2843 else if (m_scene.TestBorderCross(pos2, Cardinals.E))
2846 { 2844 {
2847 if (pos2.Y < 0) 2845 if (m_scene.TestBorderCross(pos2, Cardinals.S))
2848 neighbor = HaveNeighbor(Cardinals.SE, ref fix); 2846 neighbor = HaveNeighbor(Cardinals.SE, ref fix);
2849 else if (pos2.Y > Constants.RegionSize) 2847 else if (m_scene.TestBorderCross(pos2, Cardinals.N))
2850 neighbor = HaveNeighbor(Cardinals.NE, ref fix); 2848 neighbor = HaveNeighbor(Cardinals.NE, ref fix);
2851 else 2849 else
2852 neighbor = HaveNeighbor(Cardinals.E, ref fix); 2850 neighbor = HaveNeighbor(Cardinals.E, ref fix);
2853 } 2851 }
2854 else if (pos2.Y < 0) 2852 else if (m_scene.TestBorderCross(pos2, Cardinals.S))
2855 neighbor = HaveNeighbor(Cardinals.S, ref fix); 2853 neighbor = HaveNeighbor(Cardinals.S, ref fix);
2856 else if (pos2.Y > Constants.RegionSize) 2854 else if (m_scene.TestBorderCross(pos2, Cardinals.N))
2857 neighbor = HaveNeighbor(Cardinals.N, ref fix); 2855 neighbor = HaveNeighbor(Cardinals.N, ref fix);
2858 2856
2859 // Makes sure avatar does not end up outside region 2857 // Makes sure avatar does not end up outside region
diff --git a/OpenSim/Region/Framework/Scenes/Tests/BorderTests.cs b/OpenSim/Region/Framework/Scenes/Tests/BorderTests.cs
new file mode 100644
index 0000000..272c96e
--- /dev/null
+++ b/OpenSim/Region/Framework/Scenes/Tests/BorderTests.cs
@@ -0,0 +1,312 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using OpenMetaverse;
5using OpenSim.Region.Framework.Scenes;
6
7using NUnit.Framework;
8
9namespace OpenSim.Region.Framework.Scenes.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}