示例#1
0
        internal bool TestOverlap(BoundValues b, Proxy p)
        {
            int  i = 0;
            bool result;

            while (i < 2)
            {
                Bound[] array = this._bounds[i];
                Box2DXDebug.Assert((int)p.LowerBounds[i] < 2 * this._proxyCount);
                Box2DXDebug.Assert((int)p.UpperBounds[i] < 2 * this._proxyCount);
                if (b.LowerValues[i] > array[(int)p.UpperBounds[i]].Value)
                {
                    result = false;
                }
                else
                {
                    if (b.UpperValues[i] >= array[(int)p.LowerBounds[i]].Value)
                    {
                        i++;
                        continue;
                    }
                    result = false;
                }
                return(result);
            }
            result = true;
            return(result);
        }
示例#2
0
        internal bool TestOverlap(BoundValues b, Proxy p)
        {
            for (int axis = 0; axis < 2; ++axis)
            {
                Bound[] bounds = _bounds[axis];

                Box2DXDebug.Assert(p.LowerBounds[axis] < 2 * _proxyCount);
                Box2DXDebug.Assert(p.UpperBounds[axis] < 2 * _proxyCount);

                if (b.LowerValues[axis] > bounds[p.UpperBounds[axis]].Value)
                {
                    return(false);
                }

                if (b.UpperValues[axis] < bounds[p.LowerBounds[axis]].Value)
                {
                    return(false);
                }
            }

            return(true);
        }
示例#3
0
 public void MoveProxy(int proxyId, AABB aabb)
 {
     if (proxyId == (int)PairManager.NullProxy || Settings.MaxProxies <= proxyId)
     {
         Box2DXDebug.Assert(false);
     }
     else
     {
         if (!aabb.IsValid)
         {
             Box2DXDebug.Assert(false);
         }
         else
         {
             int         num         = 2 * this._proxyCount;
             Proxy       proxy       = this._proxyPool[proxyId];
             BoundValues boundValues = new BoundValues();
             this.ComputeBounds(out boundValues.LowerValues, out boundValues.UpperValues, aabb);
             BoundValues boundValues2 = new BoundValues();
             for (int i = 0; i < 2; i++)
             {
                 boundValues2.LowerValues[i] = this._bounds[i][(int)proxy.LowerBounds[i]].Value;
                 boundValues2.UpperValues[i] = this._bounds[i][(int)proxy.UpperBounds[i]].Value;
             }
             for (int i = 0; i < 2; i++)
             {
                 Bound[] array = this._bounds[i];
                 int     num2  = (int)proxy.LowerBounds[i];
                 int     num3  = (int)proxy.UpperBounds[i];
                 ushort  num4  = boundValues.LowerValues[i];
                 ushort  num5  = boundValues.UpperValues[i];
                 int     num6  = (int)(num4 - array[num2].Value);
                 int     num7  = (int)(num5 - array[num3].Value);
                 array[num2].Value = num4;
                 array[num3].Value = num5;
                 if (num6 < 0)
                 {
                     int num8 = num2;
                     while (num8 > 0 && num4 < array[num8 - 1].Value)
                     {
                         Bound bound    = array[num8];
                         Bound bound2   = array[num8 - 1];
                         int   proxyId2 = (int)bound2.ProxyId;
                         Proxy proxy2   = this._proxyPool[(int)bound2.ProxyId];
                         Bound expr_18A = bound2;
                         expr_18A.StabbingCount += 1;
                         if (bound2.IsUpper)
                         {
                             if (this.TestOverlap(boundValues, proxy2))
                             {
                                 this._pairManager.AddBufferedPair(proxyId, proxyId2);
                             }
                             ushort[] expr_1DA_cp_0 = proxy2.UpperBounds;
                             int      expr_1DA_cp_1 = i;
                             expr_1DA_cp_0[expr_1DA_cp_1] += 1;
                             Bound expr_1EA = bound;
                             expr_1EA.StabbingCount += 1;
                         }
                         else
                         {
                             ushort[] expr_20A_cp_0 = proxy2.LowerBounds;
                             int      expr_20A_cp_1 = i;
                             expr_20A_cp_0[expr_20A_cp_1] += 1;
                             Bound expr_21A = bound;
                             expr_21A.StabbingCount -= 1;
                         }
                         ushort[] expr_236_cp_0 = proxy.LowerBounds;
                         int      expr_236_cp_1 = i;
                         expr_236_cp_0[expr_236_cp_1] -= 1;
                         Box2DX.Common.Math.Swap <Bound>(ref array[num8], ref array[num8 - 1]);
                         num8--;
                     }
                 }
                 if (num7 > 0)
                 {
                     int num8 = num3;
                     while (num8 < num - 1 && array[num8 + 1].Value <= num5)
                     {
                         Bound bound    = array[num8];
                         Bound bound3   = array[num8 + 1];
                         int   proxyId3 = (int)bound3.ProxyId;
                         Proxy proxy3   = this._proxyPool[proxyId3];
                         Bound expr_2C9 = bound3;
                         expr_2C9.StabbingCount += 1;
                         if (bound3.IsLower)
                         {
                             if (this.TestOverlap(boundValues, proxy3))
                             {
                                 this._pairManager.AddBufferedPair(proxyId, proxyId3);
                             }
                             ushort[] expr_319_cp_0 = proxy3.LowerBounds;
                             int      expr_319_cp_1 = i;
                             expr_319_cp_0[expr_319_cp_1] -= 1;
                             Bound expr_329 = bound;
                             expr_329.StabbingCount += 1;
                         }
                         else
                         {
                             ushort[] expr_349_cp_0 = proxy3.UpperBounds;
                             int      expr_349_cp_1 = i;
                             expr_349_cp_0[expr_349_cp_1] -= 1;
                             Bound expr_359 = bound;
                             expr_359.StabbingCount -= 1;
                         }
                         ushort[] expr_375_cp_0 = proxy.UpperBounds;
                         int      expr_375_cp_1 = i;
                         expr_375_cp_0[expr_375_cp_1] += 1;
                         Box2DX.Common.Math.Swap <Bound>(ref array[num8], ref array[num8 + 1]);
                         num8++;
                     }
                 }
                 if (num6 > 0)
                 {
                     int num8 = num2;
                     while (num8 < num - 1 && array[num8 + 1].Value <= num4)
                     {
                         Bound bound    = array[num8];
                         Bound bound3   = array[num8 + 1];
                         int   proxyId3 = (int)bound3.ProxyId;
                         Proxy proxy3   = this._proxyPool[proxyId3];
                         Bound expr_40D = bound3;
                         expr_40D.StabbingCount -= 1;
                         if (bound3.IsUpper)
                         {
                             if (this.TestOverlap(boundValues2, proxy3))
                             {
                                 this._pairManager.RemoveBufferedPair(proxyId, proxyId3);
                             }
                             ushort[] expr_45D_cp_0 = proxy3.UpperBounds;
                             int      expr_45D_cp_1 = i;
                             expr_45D_cp_0[expr_45D_cp_1] -= 1;
                             Bound expr_46D = bound;
                             expr_46D.StabbingCount -= 1;
                         }
                         else
                         {
                             ushort[] expr_48D_cp_0 = proxy3.LowerBounds;
                             int      expr_48D_cp_1 = i;
                             expr_48D_cp_0[expr_48D_cp_1] -= 1;
                             Bound expr_49D = bound;
                             expr_49D.StabbingCount += 1;
                         }
                         ushort[] expr_4B9_cp_0 = proxy.LowerBounds;
                         int      expr_4B9_cp_1 = i;
                         expr_4B9_cp_0[expr_4B9_cp_1] += 1;
                         Box2DX.Common.Math.Swap <Bound>(ref array[num8], ref array[num8 + 1]);
                         num8++;
                     }
                 }
                 if (num7 < 0)
                 {
                     int num8 = num3;
                     while (num8 > 0 && num5 < array[num8 - 1].Value)
                     {
                         Bound bound    = array[num8];
                         Bound bound2   = array[num8 - 1];
                         int   proxyId2 = (int)bound2.ProxyId;
                         Proxy proxy2   = this._proxyPool[proxyId2];
                         Bound expr_551 = bound2;
                         expr_551.StabbingCount -= 1;
                         if (bound2.IsLower)
                         {
                             if (this.TestOverlap(boundValues2, proxy2))
                             {
                                 this._pairManager.RemoveBufferedPair(proxyId, proxyId2);
                             }
                             ushort[] expr_5A1_cp_0 = proxy2.LowerBounds;
                             int      expr_5A1_cp_1 = i;
                             expr_5A1_cp_0[expr_5A1_cp_1] += 1;
                             Bound expr_5B1 = bound;
                             expr_5B1.StabbingCount -= 1;
                         }
                         else
                         {
                             ushort[] expr_5D1_cp_0 = proxy2.UpperBounds;
                             int      expr_5D1_cp_1 = i;
                             expr_5D1_cp_0[expr_5D1_cp_1] += 1;
                             Bound expr_5E1 = bound;
                             expr_5E1.StabbingCount += 1;
                         }
                         ushort[] expr_5FD_cp_0 = proxy.UpperBounds;
                         int      expr_5FD_cp_1 = i;
                         expr_5FD_cp_0[expr_5FD_cp_1] -= 1;
                         Box2DX.Common.Math.Swap <Bound>(ref array[num8], ref array[num8 - 1]);
                         num8--;
                     }
                 }
             }
             if (BroadPhase.IsValidate)
             {
                 this.Validate();
             }
         }
     }
 }
示例#4
0
 internal bool TestOverlap(BoundValues b, Proxy p)
 {
     int i = 0;
     bool result;
     while (i < 2)
     {
         Bound[] array = this._bounds[i];
         Box2DXDebug.Assert((int)p.LowerBounds[i] < 2 * this._proxyCount);
         Box2DXDebug.Assert((int)p.UpperBounds[i] < 2 * this._proxyCount);
         if (b.LowerValues[i] > array[(int)p.UpperBounds[i]].Value)
         {
             result = false;
         }
         else
         {
             if (b.UpperValues[i] >= array[(int)p.LowerBounds[i]].Value)
             {
                 i++;
                 continue;
             }
             result = false;
         }
         return result;
     }
     result = true;
     return result;
 }
示例#5
0
 public void MoveProxy(int proxyId, AABB aabb)
 {
     if (proxyId == (int)PairManager.NullProxy || Settings.MaxProxies <= proxyId)
     {
         Box2DXDebug.Assert(false);
     }
     else
     {
         if (!aabb.IsValid)
         {
             Box2DXDebug.Assert(false);
         }
         else
         {
             int num = 2 * this._proxyCount;
             Proxy proxy = this._proxyPool[proxyId];
             BoundValues boundValues = new BoundValues();
             this.ComputeBounds(out boundValues.LowerValues, out boundValues.UpperValues, aabb);
             BoundValues boundValues2 = new BoundValues();
             for (int i = 0; i < 2; i++)
             {
                 boundValues2.LowerValues[i] = this._bounds[i][(int)proxy.LowerBounds[i]].Value;
                 boundValues2.UpperValues[i] = this._bounds[i][(int)proxy.UpperBounds[i]].Value;
             }
             for (int i = 0; i < 2; i++)
             {
                 Bound[] array = this._bounds[i];
                 int num2 = (int)proxy.LowerBounds[i];
                 int num3 = (int)proxy.UpperBounds[i];
                 ushort num4 = boundValues.LowerValues[i];
                 ushort num5 = boundValues.UpperValues[i];
                 int num6 = (int)(num4 - array[num2].Value);
                 int num7 = (int)(num5 - array[num3].Value);
                 array[num2].Value = num4;
                 array[num3].Value = num5;
                 if (num6 < 0)
                 {
                     int num8 = num2;
                     while (num8 > 0 && num4 < array[num8 - 1].Value)
                     {
                         Bound bound = array[num8];
                         Bound bound2 = array[num8 - 1];
                         int proxyId2 = (int)bound2.ProxyId;
                         Proxy proxy2 = this._proxyPool[(int)bound2.ProxyId];
                         Bound expr_18A = bound2;
                         expr_18A.StabbingCount += 1;
                         if (bound2.IsUpper)
                         {
                             if (this.TestOverlap(boundValues, proxy2))
                             {
                                 this._pairManager.AddBufferedPair(proxyId, proxyId2);
                             }
                             ushort[] expr_1DA_cp_0 = proxy2.UpperBounds;
                             int expr_1DA_cp_1 = i;
                             expr_1DA_cp_0[expr_1DA_cp_1] += 1;
                             Bound expr_1EA = bound;
                             expr_1EA.StabbingCount += 1;
                         }
                         else
                         {
                             ushort[] expr_20A_cp_0 = proxy2.LowerBounds;
                             int expr_20A_cp_1 = i;
                             expr_20A_cp_0[expr_20A_cp_1] += 1;
                             Bound expr_21A = bound;
                             expr_21A.StabbingCount -= 1;
                         }
                         ushort[] expr_236_cp_0 = proxy.LowerBounds;
                         int expr_236_cp_1 = i;
                         expr_236_cp_0[expr_236_cp_1] -= 1;
                         Box2DX.Common.Math.Swap<Bound>(ref array[num8], ref array[num8 - 1]);
                         num8--;
                     }
                 }
                 if (num7 > 0)
                 {
                     int num8 = num3;
                     while (num8 < num - 1 && array[num8 + 1].Value <= num5)
                     {
                         Bound bound = array[num8];
                         Bound bound3 = array[num8 + 1];
                         int proxyId3 = (int)bound3.ProxyId;
                         Proxy proxy3 = this._proxyPool[proxyId3];
                         Bound expr_2C9 = bound3;
                         expr_2C9.StabbingCount += 1;
                         if (bound3.IsLower)
                         {
                             if (this.TestOverlap(boundValues, proxy3))
                             {
                                 this._pairManager.AddBufferedPair(proxyId, proxyId3);
                             }
                             ushort[] expr_319_cp_0 = proxy3.LowerBounds;
                             int expr_319_cp_1 = i;
                             expr_319_cp_0[expr_319_cp_1] -= 1;
                             Bound expr_329 = bound;
                             expr_329.StabbingCount += 1;
                         }
                         else
                         {
                             ushort[] expr_349_cp_0 = proxy3.UpperBounds;
                             int expr_349_cp_1 = i;
                             expr_349_cp_0[expr_349_cp_1] -= 1;
                             Bound expr_359 = bound;
                             expr_359.StabbingCount -= 1;
                         }
                         ushort[] expr_375_cp_0 = proxy.UpperBounds;
                         int expr_375_cp_1 = i;
                         expr_375_cp_0[expr_375_cp_1] += 1;
                         Box2DX.Common.Math.Swap<Bound>(ref array[num8], ref array[num8 + 1]);
                         num8++;
                     }
                 }
                 if (num6 > 0)
                 {
                     int num8 = num2;
                     while (num8 < num - 1 && array[num8 + 1].Value <= num4)
                     {
                         Bound bound = array[num8];
                         Bound bound3 = array[num8 + 1];
                         int proxyId3 = (int)bound3.ProxyId;
                         Proxy proxy3 = this._proxyPool[proxyId3];
                         Bound expr_40D = bound3;
                         expr_40D.StabbingCount -= 1;
                         if (bound3.IsUpper)
                         {
                             if (this.TestOverlap(boundValues2, proxy3))
                             {
                                 this._pairManager.RemoveBufferedPair(proxyId, proxyId3);
                             }
                             ushort[] expr_45D_cp_0 = proxy3.UpperBounds;
                             int expr_45D_cp_1 = i;
                             expr_45D_cp_0[expr_45D_cp_1] -= 1;
                             Bound expr_46D = bound;
                             expr_46D.StabbingCount -= 1;
                         }
                         else
                         {
                             ushort[] expr_48D_cp_0 = proxy3.LowerBounds;
                             int expr_48D_cp_1 = i;
                             expr_48D_cp_0[expr_48D_cp_1] -= 1;
                             Bound expr_49D = bound;
                             expr_49D.StabbingCount += 1;
                         }
                         ushort[] expr_4B9_cp_0 = proxy.LowerBounds;
                         int expr_4B9_cp_1 = i;
                         expr_4B9_cp_0[expr_4B9_cp_1] += 1;
                         Box2DX.Common.Math.Swap<Bound>(ref array[num8], ref array[num8 + 1]);
                         num8++;
                     }
                 }
                 if (num7 < 0)
                 {
                     int num8 = num3;
                     while (num8 > 0 && num5 < array[num8 - 1].Value)
                     {
                         Bound bound = array[num8];
                         Bound bound2 = array[num8 - 1];
                         int proxyId2 = (int)bound2.ProxyId;
                         Proxy proxy2 = this._proxyPool[proxyId2];
                         Bound expr_551 = bound2;
                         expr_551.StabbingCount -= 1;
                         if (bound2.IsLower)
                         {
                             if (this.TestOverlap(boundValues2, proxy2))
                             {
                                 this._pairManager.RemoveBufferedPair(proxyId, proxyId2);
                             }
                             ushort[] expr_5A1_cp_0 = proxy2.LowerBounds;
                             int expr_5A1_cp_1 = i;
                             expr_5A1_cp_0[expr_5A1_cp_1] += 1;
                             Bound expr_5B1 = bound;
                             expr_5B1.StabbingCount -= 1;
                         }
                         else
                         {
                             ushort[] expr_5D1_cp_0 = proxy2.UpperBounds;
                             int expr_5D1_cp_1 = i;
                             expr_5D1_cp_0[expr_5D1_cp_1] += 1;
                             Bound expr_5E1 = bound;
                             expr_5E1.StabbingCount += 1;
                         }
                         ushort[] expr_5FD_cp_0 = proxy.UpperBounds;
                         int expr_5FD_cp_1 = i;
                         expr_5FD_cp_0[expr_5FD_cp_1] -= 1;
                         Box2DX.Common.Math.Swap<Bound>(ref array[num8], ref array[num8 - 1]);
                         num8--;
                     }
                 }
             }
             if (BroadPhase.IsValidate)
             {
                 this.Validate();
             }
         }
     }
 }
示例#6
0
		internal bool TestOverlap(BoundValues b, Proxy p)
		{
			for (int axis = 0; axis < 2; ++axis)
			{
				Bound[] bounds = _bounds[axis];

				Box2DXDebug.Assert(p.LowerBounds[axis] < 2 * _proxyCount);
				Box2DXDebug.Assert(p.UpperBounds[axis] < 2 * _proxyCount);

				if (b.LowerValues[axis] > bounds[p.UpperBounds[axis]].Value)
					return false;

				if (b.UpperValues[axis] < bounds[p.LowerBounds[axis]].Value)
					return false;
			}

			return true;
		}
示例#7
0
		// Call MoveProxy as many times as you like, then when you are done
		// call Commit to finalized the proxy pairs (for your time step).
		public void MoveProxy(int proxyId, AABB aabb)
		{
			if (proxyId == PairManager.NullProxy || Settings.MaxProxies <= proxyId)
			{
				Box2DXDebug.Assert(false);
				return;
			}

			if (aabb.IsValid == false)
			{
				Box2DXDebug.Assert(false);
				return;
			}

			int boundCount = 2 * _proxyCount;

			Proxy proxy = _proxyPool[proxyId];

			// Get new bound values
			BoundValues newValues = new BoundValues(); ;
			ComputeBounds(out newValues.LowerValues, out newValues.UpperValues, aabb);

			// Get old bound values
			BoundValues oldValues = new BoundValues();
			for (int axis = 0; axis < 2; ++axis)
			{
				oldValues.LowerValues[axis] = _bounds[axis][proxy.LowerBounds[axis]].Value;
				oldValues.UpperValues[axis] = _bounds[axis][proxy.UpperBounds[axis]].Value;
			}

			for (int axis = 0; axis < 2; ++axis)
			{
				Bound[] bounds = _bounds[axis];

				int lowerIndex = proxy.LowerBounds[axis];
				int upperIndex = proxy.UpperBounds[axis];

				ushort lowerValue = newValues.LowerValues[axis];
				ushort upperValue = newValues.UpperValues[axis];

				int deltaLower = lowerValue - bounds[lowerIndex].Value;
				int deltaUpper = upperValue - bounds[upperIndex].Value;

				bounds[lowerIndex].Value = lowerValue;
				bounds[upperIndex].Value = upperValue;

				//
				// Expanding adds overlaps
				//

				// Should we move the lower bound down?
				if (deltaLower < 0)
				{
					int index = lowerIndex;
					while (index > 0 && lowerValue < bounds[index - 1].Value)
					{
						Bound bound = bounds[index];
						Bound prevBound = bounds[index - 1];

						int prevProxyId = prevBound.ProxyId;
						Proxy prevProxy = _proxyPool[prevBound.ProxyId];

						++prevBound.StabbingCount;

						if (prevBound.IsUpper == true)
						{
							if (TestOverlap(newValues, prevProxy))
							{
								_pairManager.AddBufferedPair(proxyId, prevProxyId);
							}

							++prevProxy.UpperBounds[axis];
							++bound.StabbingCount;
						}
						else
						{
							++prevProxy.LowerBounds[axis];
							--bound.StabbingCount;
						}

						--proxy.LowerBounds[axis];
						Common.Math.Swap<Bound>(ref bounds[index], ref bounds[index - 1]);
						--index;
					}
				}

				// Should we move the upper bound up?
				if (deltaUpper > 0)
				{
					int index = upperIndex;
					while (index < boundCount - 1 && bounds[index + 1].Value <= upperValue)
					{
						Bound bound = bounds[index];
						Bound nextBound = bounds[index + 1];
						int nextProxyId = nextBound.ProxyId;
						Proxy nextProxy = _proxyPool[nextProxyId];

						++nextBound.StabbingCount;

						if (nextBound.IsLower == true)
						{
							if (TestOverlap(newValues, nextProxy))
							{
								_pairManager.AddBufferedPair(proxyId, nextProxyId);
							}

							--nextProxy.LowerBounds[axis];
							++bound.StabbingCount;
						}
						else
						{
							--nextProxy.UpperBounds[axis];
							--bound.StabbingCount;
						}

						++proxy.UpperBounds[axis];
						Common.Math.Swap<Bound>(ref bounds[index], ref bounds[index + 1]);
						++index;
					}
				}

				//
				// Shrinking removes overlaps
				//

				// Should we move the lower bound up?
				if (deltaLower > 0)
				{
					int index = lowerIndex;
					while (index < boundCount - 1 && bounds[index + 1].Value <= lowerValue)
					{
						Bound bound = bounds[index];
						Bound nextBound = bounds[index + 1];

						int nextProxyId = nextBound.ProxyId;
						Proxy nextProxy = _proxyPool[nextProxyId];

						--nextBound.StabbingCount;

						if (nextBound.IsUpper)
						{
							if (TestOverlap(oldValues, nextProxy))
							{
								_pairManager.RemoveBufferedPair(proxyId, nextProxyId);
							}

							--nextProxy.UpperBounds[axis];
							--bound.StabbingCount;
						}
						else
						{
							--nextProxy.LowerBounds[axis];
							++bound.StabbingCount;
						}

						++proxy.LowerBounds[axis];
						Common.Math.Swap<Bound>(ref bounds[index], ref bounds[index + 1]);
						++index;
					}
				}

				// Should we move the upper bound down?
				if (deltaUpper < 0)
				{
					int index = upperIndex;
					while (index > 0 && upperValue < bounds[index - 1].Value)
					{
						Bound bound = bounds[index];
						Bound prevBound = bounds[index - 1];

						int prevProxyId = prevBound.ProxyId;
						Proxy prevProxy = _proxyPool[prevProxyId];

						--prevBound.StabbingCount;

						if (prevBound.IsLower == true)
						{
							if (TestOverlap(oldValues, prevProxy))
							{
								_pairManager.RemoveBufferedPair(proxyId, prevProxyId);
							}

							++prevProxy.LowerBounds[axis];
							--bound.StabbingCount;
						}
						else
						{
							++prevProxy.UpperBounds[axis];
							++bound.StabbingCount;
						}

						--proxy.UpperBounds[axis];
						Common.Math.Swap<Bound>(ref bounds[index], ref bounds[index - 1]);
						--index;
					}
				}
			}

			if (IsValidate)
			{
				Validate();
			}
		}
示例#8
0
        // Call MoveProxy as many times as you like, then when you are done
        // call Commit to finalized the proxy pairs (for your time step).
        public void MoveProxy(int proxyId, AABB aabb)
        {
            if (proxyId == PairManager.NullProxy || Settings.MaxProxies <= proxyId)
            {
                Box2DXDebug.Assert(false);
                return;
            }

            if (aabb.IsValid == false)
            {
                Box2DXDebug.Assert(false);
                return;
            }

            int boundCount = 2 * _proxyCount;

            Proxy proxy = _proxyPool[proxyId];

            // Get new bound values
            BoundValues newValues = new BoundValues();;

            ComputeBounds(out newValues.LowerValues, out newValues.UpperValues, aabb);

            // Get old bound values
            BoundValues oldValues = new BoundValues();

            for (int axis = 0; axis < 2; ++axis)
            {
                oldValues.LowerValues[axis] = _bounds[axis][proxy.LowerBounds[axis]].Value;
                oldValues.UpperValues[axis] = _bounds[axis][proxy.UpperBounds[axis]].Value;
            }

            for (int axis = 0; axis < 2; ++axis)
            {
                Bound[] bounds = _bounds[axis];

                int lowerIndex = proxy.LowerBounds[axis];
                int upperIndex = proxy.UpperBounds[axis];

                ushort lowerValue = newValues.LowerValues[axis];
                ushort upperValue = newValues.UpperValues[axis];

                int deltaLower = lowerValue - bounds[lowerIndex].Value;
                int deltaUpper = upperValue - bounds[upperIndex].Value;

                bounds[lowerIndex].Value = lowerValue;
                bounds[upperIndex].Value = upperValue;

                //
                // Expanding adds overlaps
                //

                // Should we move the lower bound down?
                if (deltaLower < 0)
                {
                    int index = lowerIndex;
                    while (index > 0 && lowerValue < bounds[index - 1].Value)
                    {
                        Bound bound     = bounds[index];
                        Bound prevBound = bounds[index - 1];

                        int   prevProxyId = prevBound.ProxyId;
                        Proxy prevProxy   = _proxyPool[prevBound.ProxyId];

                        ++prevBound.StabbingCount;

                        if (prevBound.IsUpper == true)
                        {
                            if (TestOverlap(newValues, prevProxy))
                            {
                                _pairManager.AddBufferedPair(proxyId, prevProxyId);
                            }

                            ++prevProxy.UpperBounds[axis];
                            ++bound.StabbingCount;
                        }
                        else
                        {
                            ++prevProxy.LowerBounds[axis];
                            --bound.StabbingCount;
                        }

                        --proxy.LowerBounds[axis];
                        Common.Math.Swap <Bound>(ref bounds[index], ref bounds[index - 1]);
                        --index;
                    }
                }

                // Should we move the upper bound up?
                if (deltaUpper > 0)
                {
                    int index = upperIndex;
                    while (index < boundCount - 1 && bounds[index + 1].Value <= upperValue)
                    {
                        Bound bound       = bounds[index];
                        Bound nextBound   = bounds[index + 1];
                        int   nextProxyId = nextBound.ProxyId;
                        Proxy nextProxy   = _proxyPool[nextProxyId];

                        ++nextBound.StabbingCount;

                        if (nextBound.IsLower == true)
                        {
                            if (TestOverlap(newValues, nextProxy))
                            {
                                _pairManager.AddBufferedPair(proxyId, nextProxyId);
                            }

                            --nextProxy.LowerBounds[axis];
                            ++bound.StabbingCount;
                        }
                        else
                        {
                            --nextProxy.UpperBounds[axis];
                            --bound.StabbingCount;
                        }

                        ++proxy.UpperBounds[axis];
                        Common.Math.Swap <Bound>(ref bounds[index], ref bounds[index + 1]);
                        ++index;
                    }
                }

                //
                // Shrinking removes overlaps
                //

                // Should we move the lower bound up?
                if (deltaLower > 0)
                {
                    int index = lowerIndex;
                    while (index < boundCount - 1 && bounds[index + 1].Value <= lowerValue)
                    {
                        Bound bound     = bounds[index];
                        Bound nextBound = bounds[index + 1];

                        int   nextProxyId = nextBound.ProxyId;
                        Proxy nextProxy   = _proxyPool[nextProxyId];

                        --nextBound.StabbingCount;

                        if (nextBound.IsUpper)
                        {
                            if (TestOverlap(oldValues, nextProxy))
                            {
                                _pairManager.RemoveBufferedPair(proxyId, nextProxyId);
                            }

                            --nextProxy.UpperBounds[axis];
                            --bound.StabbingCount;
                        }
                        else
                        {
                            --nextProxy.LowerBounds[axis];
                            ++bound.StabbingCount;
                        }

                        ++proxy.LowerBounds[axis];
                        Common.Math.Swap <Bound>(ref bounds[index], ref bounds[index + 1]);
                        ++index;
                    }
                }

                // Should we move the upper bound down?
                if (deltaUpper < 0)
                {
                    int index = upperIndex;
                    while (index > 0 && upperValue < bounds[index - 1].Value)
                    {
                        Bound bound     = bounds[index];
                        Bound prevBound = bounds[index - 1];

                        int   prevProxyId = prevBound.ProxyId;
                        Proxy prevProxy   = _proxyPool[prevProxyId];

                        --prevBound.StabbingCount;

                        if (prevBound.IsLower == true)
                        {
                            if (TestOverlap(oldValues, prevProxy))
                            {
                                _pairManager.RemoveBufferedPair(proxyId, prevProxyId);
                            }

                            ++prevProxy.LowerBounds[axis];
                            --bound.StabbingCount;
                        }
                        else
                        {
                            ++prevProxy.UpperBounds[axis];
                            ++bound.StabbingCount;
                        }

                        --proxy.UpperBounds[axis];
                        Common.Math.Swap <Bound>(ref bounds[index], ref bounds[index - 1]);
                        --index;
                    }
                }
            }

            if (IsValidate)
            {
                Validate();
            }
        }