index.js
function boxIntersect(red, blue, visit, full) {
  var n = red.length
  var m = blue.length

  //If either array is empty, then we can skip this whole thing
  if(n <= 0 || m <= 0) {
    return
  }

  //Compute dimension, if it is 0 then we skip
  var d = (red[0].length)>>>1
  if(d <= 0) {
    return
  }

  var retval

  //Convert red boxes
  var redList  = pool.mallocDouble(2*d*n)
  var redIds   = pool.mallocInt32(n)
  n = convertBoxes(red, d, redList, redIds)

  if(n > 0) {
    if(d === 1 && full) {
      //Special case: 1d complete
      sweep.init(n)
      retval = sweep.sweepComplete(
        d, visit, 
        0, n, redList, redIds,
        0, n, redList, redIds)
    } else {

      //Convert blue boxes
      var blueList = pool.mallocDouble(2*d*m)
      var blueIds  = pool.mallocInt32(m)
      m = convertBoxes(blue, d, blueList, blueIds)

      if(m > 0) {
        sweep.init(n+m)

        if(d === 1) {
          //Special case: 1d bipartite
          retval = sweep.sweepBipartite(
            d, visit, 
            0, n, redList,  redIds,
            0, m, blueList, blueIds)
        } else {
          //General case:  d>1
          retval = boxIntersectIter(
            d, visit,    full,
            n, redList,  redIds,
            m, blueList, blueIds)
        }

        pool.free(blueList)
        pool.free(blueIds)
      }
    }

    pool.free(redList)
    pool.free(redIds)
  }

  return retval
}
function boxIntersect(red, blue, visit, full) {
  var n = red.length
  var m = blue.length

  //If either array is empty, then we can skip this whole thing
  if(n <= 0 || m <= 0) {
    return
  }

  //Compute dimension, if it is 0 then we skip
  var d = (red[0].length)>>>1
  if(d <= 0) {
    return
  }

  var retval

  //Convert red boxes
  var redList  = pool.mallocDouble(2*d*n)
  var redIds   = pool.mallocInt32(n)
  n = convertBoxes(red, d, redList, redIds)

  if(n > 0) {
    if(d === 1 && full) {
      //Special case: 1d complete
      sweep.init(n)
      retval = sweep.sweepComplete(
        d, visit, 
        0, n, redList, redIds,
        0, n, redList, redIds)
    } else {

      //Convert blue boxes
      var blueList = pool.mallocDouble(2*d*m)
      var blueIds  = pool.mallocInt32(m)
      m = convertBoxes(blue, d, blueList, blueIds)

      if(m > 0) {
        sweep.init(n+m)

        if(d === 1) {
          //Special case: 1d bipartite
          retval = sweep.sweepBipartite(
            d, visit, 
            0, n, redList,  redIds,
            0, m, blueList, blueIds)
        } else {
          //General case:  d>1
          retval = boxIntersectIter(
            d, visit,    full,
            n, redList,  redIds,
            m, blueList, blueIds)
        }

        pool.free(blueList)
        pool.free(blueIds)
      }
    }

    pool.free(redList)
    pool.free(redIds)
  }

  return retval
}
function boxIntersect ( red , blue , visit , full ) { var n = red . length var m = blue . length //If either array is empty, then we can skip this whole thing if ( n <= 0 || m <= 0 ) { return } //Compute dimension, if it is 0 then we skip var d = ( red [ 0 ] . length ) >>> 1 if ( d <= 0 ) { return } var retval //Convert red boxes var redList = pool . mallocDouble ( 2 * d * n ) var redIds = pool . mallocInt32 ( n ) n = convertBoxes ( red , d , redList , redIds ) if ( n > 0 ) { if ( d === 1 && full ) { //Special case: 1d complete sweep . init ( n ) retval = sweep . sweepComplete ( d , visit , 0 , n , redList , redIds , 0 , n , redList , redIds ) } else { //Convert blue boxes var blueList = pool . mallocDouble ( 2 * d * m ) var blueIds = pool . mallocInt32 ( m ) m = convertBoxes ( blue , d , blueList , blueIds ) if ( m > 0 ) { sweep . init ( n + m ) if ( d === 1 ) { //Special case: 1d bipartite retval = sweep . sweepBipartite ( d , visit , 0 , n , redList , redIds , 0 , m , blueList , blueIds ) } else { //General case:  d>1 retval = boxIntersectIter ( d , visit , full , n , redList , redIds , m , blueList , blueIds ) } pool . free ( blueList ) pool . free ( blueIds ) } } pool . free ( redList ) pool . free ( redIds ) } return retval }
Perform type conversions, check bounds
Perform type conversions check bounds