protected void processCluster ( List < SquareNode > cluster ) { invalid = false ; // handle a special case if ( cluster . size ( ) == 1 ) { SquareNode n = cluster . get ( 0 ) ; if ( n . getNumberOfConnections ( ) == 0 ) { SquareGrid grid = grids . grow ( ) ; grid . reset ( ) ; grid . columns = grid . rows = 1 ; grid . nodes . add ( n ) ; return ; } } for ( int i = 0 ; i < cluster . size ( ) ; i ++ ) { cluster . get ( i ) . graph = SquareNode . RESET_GRAPH ; } SquareNode seed = findSeedNode ( cluster ) ; if ( seed == null ) return ; // find the first row List < SquareNode > firstRow ; if ( seed . getNumberOfConnections ( ) == 1 ) { firstRow = firstRow1 ( seed ) ; } else if ( seed . getNumberOfConnections ( ) == 2 ) { firstRow = firstRow2 ( seed ) ; } else { throw new RuntimeException ( "BUG" ) ; } if ( invalid || firstRow == null ) return ; // Add the next rows to the list, one after another List < List < SquareNode > > listRows = new ArrayList <> ( ) ; // TODO remove memory declaration here listRows . add ( firstRow ) ; while ( true ) { List < SquareNode > previous = listRows . get ( listRows . size ( ) - 1 ) ; if ( ! addNextRow ( previous . get ( 0 ) , listRows ) ) { break ; } } if ( invalid || listRows . size ( ) < 2 ) return ; // re-organize into a grid data structure SquareGrid grid = assembleGrid ( listRows ) ; // check the grids connectivity if ( grid == null || ! checkEdgeCount ( grid ) ) { grids . removeTail ( ) ; } }
Converts the cluster into a grid data structure . If its not a grid then nothing happens