public static ArrayList<BoundingBox> newBoxes(ArrayList<BoundingBox> existing,BoundingBox newBox){
  ArrayList<BoundingBox> result=new ArrayList<BoundingBox>();
  result.add(newBox);
  for (  BoundingBox b : existing) {
    ArrayList<BoundingBox> temp=new ArrayList<BoundingBox>();
    for (    BoundingBox rb : result) {
      if (b.intersects(rb)) {
        try {
          if (rb.top > b.top) {
            temp.add(new BoundingBox(rb.left,b.top,rb.right,rb.top));
            rb.setTop(b.top);
          }
          if (rb.bottom < b.bottom) {
            temp.add(new BoundingBox(rb.left,rb.bottom,rb.right,b.bottom));
            rb.setBottom(b.bottom);
          }
          if (rb.left < b.left && rb.bottom != rb.top) {
            temp.add(new BoundingBox(rb.left,rb.bottom,b.left,rb.top));
            rb.setLeft(b.left);
          }
          if (rb.right > b.right && rb.bottom != rb.top) {
            temp.add(new BoundingBox(b.right,rb.bottom,rb.right,rb.top));
            rb.setRight(b.right);
          }
          rb.calcDimensions();
          rb.calcBottomMercator();
        }
 catch (        OsmException e) {
          Log.d("BoundingBox","Exception " + e.getMessage());
        }
      }
 else {
        temp.add(rb);
      }
    }
    result=temp;
  }
  return result;
}

public static ArrayList < BoundingBox > newBoxes ( ArrayList < BoundingBox > existing , BoundingBox newBox ) { ArrayList < BoundingBox > result = new ArrayList < BoundingBox > ( ) ; result . add ( newBox ) ; for ( BoundingBox b : existing ) { ArrayList < BoundingBox > temp = new ArrayList < BoundingBox > ( ) ; for ( BoundingBox rb : result ) { if ( b . intersects ( rb ) ) { try { if ( rb . top > b . top ) { temp . add ( new BoundingBox ( rb . left , b . top , rb . right , rb . top ) ) ; rb . setTop ( b . top ) ; } if ( rb . bottom < b . bottom ) { temp . add ( new BoundingBox ( rb . left , rb . bottom , rb . right , b . bottom ) ) ; rb . setBottom ( b . bottom ) ; } if ( rb . left < b . left && rb . bottom != rb . top ) { temp . add ( new BoundingBox ( rb . left , rb . bottom , b . left , rb . top ) ) ; rb . setLeft ( b . left ) ; } if ( rb . right > b . right && rb . bottom != rb . top ) { temp . add ( new BoundingBox ( b . right , rb . bottom , rb . right , rb . top ) ) ; rb . setRight ( b . right ) ; } rb . calcDimensions ( ) ; rb . calcBottomMercator ( ) ; } catch ( OsmException e ) { Log . d ( "BoundingBox" , "Exception " + e . getMessage ( ) ) ; } } else { temp . add ( rb ) ; } } result = temp ; } return result ; }
given a list of existing bounding boxes and a new bbox . return a list of pieces of the new bbox that complete the coverage
