code: function insertionSort(d, axis, start, end, boxes, ids) {
    var elemSize = 2 * d
    var boxPtr = elemSize * (start+1) + axis
    for(var i=start+1; i<end; ++i, boxPtr+=elemSize) {
      var x = boxes[boxPtr]
      for(var j=i, ptr=elemSize*(i-1); 
          j>start && boxes[ptr+axis] > x; 
          --j, ptr-=elemSize) {
        //Swap
        var aPtr = ptr
        var bPtr = ptr+elemSize
        for(var k=0; k<elemSize; ++k, ++aPtr, ++bPtr) {
          var y = boxes[aPtr]
          boxes[aPtr] = boxes[bPtr]
          boxes[bPtr] = y
        }
        var tmp = ids[j]
        ids[j] = ids[j-1]
        ids[j-1] = tmp
      }
    }
  }
docs: Base case for median finding:  Use insertion sort