Box2DX.Collision.BroadPhase.BinarySearch C# (CSharp) Method

BinarySearch() private static method

private static BinarySearch ( Bound bounds, int count, ushort value ) : int
bounds Bound
count int
value ushort
return int
		private static int BinarySearch(Bound[] bounds, int count, ushort value)
		{
			int low = 0;
			int high = count - 1;
			while (low <= high)
			{
				int mid = (low + high) >> 1;
				if (bounds[mid].Value > value)
				{
					high = mid - 1;
				}
				else if (bounds[mid].Value < value)
				{
					low = mid + 1;
				}
				else
				{
					return (ushort)mid;
				}
			}

			return low;
		}
	}

Usage Example

Example #1
0
        private void Query(out int lowerQueryOut, out int upperQueryOut, ushort lowerValue, ushort upperValue, Bound[] bounds, int boundCount, int axis)
        {
            int num  = BroadPhase.BinarySearch(bounds, boundCount, lowerValue);
            int num2 = BroadPhase.BinarySearch(bounds, boundCount, upperValue);

            for (int i = num; i < num2; i++)
            {
                if (bounds[i].IsLower)
                {
                    this.IncrementOverlapCount((int)bounds[i].ProxyId);
                }
            }
            if (num > 0)
            {
                int i    = num - 1;
                int num3 = (int)bounds[i].StabbingCount;
                while (num3 != 0)
                {
                    Box2DXDebug.Assert(i >= 0);
                    if (bounds[i].IsLower)
                    {
                        Proxy proxy = this._proxyPool[(int)bounds[i].ProxyId];
                        if (num <= (int)proxy.UpperBounds[axis])
                        {
                            this.IncrementOverlapCount((int)bounds[i].ProxyId);
                            num3--;
                        }
                    }
                    i--;
                }
            }
            lowerQueryOut = num;
            upperQueryOut = num2;
        }