public void expand(int level){
  ArrayList<S2CellId> output=new ArrayList<S2CellId>();
  long levelLsb=S2CellId.lowestOnBitForLevel(level);
  int i=size() - 1;
  do {
    S2CellId id=cellId(i);
    if (id.lowestOnBit() < levelLsb) {
      id=id.parent(level);
      while (i > 0 && id.contains(cellId(i - 1))) {
        --i;
      }
    }
    output.add(id);
    id.getAllNeighbors(level,output);
  }
 while (--i >= 0);
  initSwap(output);
}

public void expand ( int level ) { ArrayList < S2CellId > output = new ArrayList < S2CellId > ( ) ; long levelLsb = S2CellId . lowestOnBitForLevel ( level ) ; int i = size ( ) - 1 ; do { S2CellId id = cellId ( i ) ; if ( id . lowestOnBit ( ) < levelLsb ) { id = id . parent ( level ) ; while ( i > 0 && id . contains ( cellId ( i - 1 ) ) ) { -- i ; } } output . add ( id ) ; id . getAllNeighbors ( level , output ) ; } while ( -- i >= 0 ) ; initSwap ( output ) ; }
expands the cell union such that it contains all cells of the given level that are adjacent to any cell of the original union . two cells are defined as adjacent if their boundaries have any points in common , i . e . most cells have 8 adjacent cells ( not counting the cell itself ) . note that the size of the output is exponential in " level " . for example , if level = = 20 and the input has a cell at level 10 , there will be on the order of 4000 adjacent cells in the output . for most applications the expand ( min_fraction , min_distance ) method below is easier to use .
