private static LmtNode bound_list( LmtTable lmt_table, double y ) { if( lmt_table.top_node == null ) { lmt_table.top_node = new LmtNode(y); return lmt_table.top_node ; } else { LmtNode prev = null ; LmtNode node = lmt_table.top_node ; bool done = false ; while( !done ) { if( y < node.y ) { /* Insert a new LMT node before the current node */ LmtNode existing_node = node ; node = new LmtNode(y); node.next = existing_node ; if( prev == null ) { lmt_table.top_node = node ; } else { prev.next = node ; } // if( existing_node == lmt_table.top_node ) // { // lmt_table.top_node = node ; // } done = true ; } else if ( y > node.y ) { /* Head further up the LMT */ if( node.next == null ) { node.next = new LmtNode(y); node = node.next ; done = true ; } else { prev = node ; node = node.next ; } } else { /* Use this existing LMT node */ done = true ; } } return node ; } }
private static void insert_bound( LmtNode lmt_node, EdgeNode e) { if( lmt_node.first_bound == null ) { /* Link node e to the tail of the list */ lmt_node.first_bound = e ; } else { bool done = false ; EdgeNode prev_bound = null ; EdgeNode current_bound = lmt_node.first_bound ; while( !done ) { /* Do primary sort on the x field */ if (e.bot.X < current_bound.bot.X) { /* Insert a new node mid-list */ if( prev_bound == null ) { lmt_node.first_bound = e ; } else { prev_bound.next_bound = e ; } e.next_bound = current_bound ; // EdgeNode existing_bound = current_bound ; // current_bound = e ; // current_bound.next_bound = existing_bound ; // if( lmt_node.first_bound == existing_bound ) // { // lmt_node.first_bound = current_bound ; // } done = true ; } else if (e.bot.X == current_bound.bot.X) { /* Do secondary sort on the dx field */ if (e.dx < current_bound.dx) { /* Insert a new node mid-list */ if( prev_bound == null ) { lmt_node.first_bound = e ; } else { prev_bound.next_bound = e ; } e.next_bound = current_bound ; // EdgeNode existing_bound = current_bound ; // current_bound = e ; // current_bound.next_bound = existing_bound ; // if( lmt_node.first_bound == existing_bound ) // { // lmt_node.first_bound = current_bound ; // } done = true ; } else { /* Head further down the list */ if( current_bound.next_bound == null ) { current_bound.next_bound = e ; done = true ; } else { prev_bound = current_bound ; current_bound = current_bound.next_bound ; } } } else { /* Head further down the list */ if( current_bound.next_bound == null ) { current_bound.next_bound = e ; done = true ; } else { prev_bound = current_bound ; current_bound = current_bound.next_bound ; } } } } }