private int ComparePairs(b2DynamicTreePair pair1, b2DynamicTreePair pair2)
 {
     //TODO_BORIS:
     // We cannot consistently sort objects easily in AS3
     // The caller of this needs replacing with a different method.
     return(0);
 }
        /**
         * Update the pairs. This results in pair callbacks. This can only add pairs.
         */
        public void UpdatePairs(Action <object, object> callback)
        {
            m_pairCount = 0;
            // Perform tree queries for all moving queries
            foreach (b2DynamicTreeNode queryProxy in m_moveBuffer)
            {
                /*bool QueryCallback(b2DynamicTreeNode proxy)
                 * {
                 *      // A proxy cannot form a pair with itself.
                 *      if (proxy == queryProxy)
                 *              return true;
                 *
                 *      // Grow the pair buffer as needed
                 *      if (m_pairCount == m_pairBuffer.Count)
                 *      {
                 *              m_pairBuffer[m_pairCount] = new b2DynamicTreePair();
                 *      }
                 *
                 *      b2DynamicTreePair pair = m_pairBuffer[m_pairCount];
                 *      pair.proxyA = proxy < queryProxy?proxy:queryProxy;
                 *      pair.proxyB = proxy >= queryProxy?proxy:queryProxy;
                 ++m_pairCount;
                 *
                 *      return true;
                 * }*/
                BroadPhaseQueryCallback QueryCallback = delegate(object proxy){
                    // A proxy cannot form a pair with itself.
                    if (proxy == queryProxy)
                    {
                        return(true);
                    }

                    // Grow the pair buffer as needed
                    if (m_pairCount == m_pairBuffer.Count)
                    {
                        m_pairBuffer.Add(new b2DynamicTreePair());
                    }

                    b2DynamicTreePair pair = m_pairBuffer[m_pairCount];
                    //pair.proxyA = proxy < queryProxy?proxy:queryProxy;
                    //pair.proxyB = proxy >= queryProxy?proxy:queryProxy;
                    //改
                    pair.proxyA = queryProxy;
                    pair.proxyB = (b2DynamicTreeNode)proxy;

                    ++m_pairCount;

                    return(true);
                };
                // We have to query the tree with the fat AABB so that
                // we don't fail to create a pair that may touch later.
                b2AABB fatAABB = m_tree.GetFatAABB(queryProxy);
                m_tree.Query(QueryCallback, fatAABB);
            }

            // Reset move buffer
            //m_moveBuffer.length = 0;
            m_moveBuffer.RemoveRange(0, m_moveBuffer.Count);

            // Sort the pair buffer to expose duplicates.
            // TODO: Something more sensible
            //m_pairBuffer.sort(ComparePairs);

            // Send the pair buffer
            for (int i = 0; i < m_pairCount;)
            {
                b2DynamicTreePair primaryPair = m_pairBuffer[i];
                object            userDataA   = m_tree.GetUserData(primaryPair.proxyA);
                object            userDataB   = m_tree.GetUserData(primaryPair.proxyB);
                callback(userDataA, userDataB);
                ++i;

                // Skip any duplicate pairs
                while (i < m_pairCount)
                {
                    b2DynamicTreePair pair = m_pairBuffer[i];
                    if (pair.proxyA != primaryPair.proxyA || pair.proxyB != primaryPair.proxyB)
                    {
                        break;
                    }
                    ++i;
                }
            }
        }