void dxSAPSpace::collide (void *data, dNearCallback *callback)
{
    dAASSERT (callback);

    lock_count++;

    cleanGeoms();

    // by now all geoms are in GeomList, and DirtyList must be empty
    int geomSize = GeomList.size();
    dUASSERT( geomSize == count, "geom counts messed up" );

    // separate all geoms into infinite AABBs and normal AABBs
    TmpGeomList.setSize(0);
    TmpInfGeomList.setSize(0);
    int axis0max = SortAxes.mAxis0*2+1;
    for( int i = 0; i < geomSize; ++i ) {
        dxGeom* g =GeomList[i];
        if( !GEOM_ENABLED(g) ) // skip disabled ones
            continue;
        const dReal& amax = g->aabb[axis0max];
        if( amax == dInfinity ) // HACK? probably not...
            TmpInfGeomList.push( g );
        else
            TmpGeomList.push( g );
    }

    // do SAP on normal AABBs
    Pairs overlapBoxes;
    bool isok = complete_box_pruning( TmpGeomList.size(), (const dxGeom**)TmpGeomList.data(), overlapBoxes, SortAxes );

    // collide overlapping
    udword overlapCount = overlapBoxes.GetNbPairs();
    for( udword j = 0; j < overlapCount; ++j ) {
        const Pair* pair = overlapBoxes.GetPair(j);
        dxGeom* g1 = TmpGeomList[pair->id0];
        dxGeom* g2 = TmpGeomList[pair->id1];
        collideGeomsNoAABBs( g1, g2, data, callback );
    }

    int infSize = TmpInfGeomList.size();
    int normSize = TmpGeomList.size();
    int m, n;
    for( m = 0; m < infSize; ++m ) {
        dxGeom* g1 = TmpInfGeomList[m];
        // collide infinite ones
        for( n = m+1; n < infSize; ++n ) {
            dxGeom* g2 = TmpInfGeomList[n];
            collideGeomsNoAABBs( g1, g2, data, callback );
        }
        // collide infinite ones with normal ones
        for( n = 0; n < normSize; ++n ) {
            dxGeom* g2 = TmpGeomList[n];
            collideGeomsNoAABBs( g1, g2, data, callback );
        }
    }

    lock_count--;
}