loops.js
function next(a, b, noCut) {
    var nextCell, nextVertex, nextDir
    for(var i=0; i<2; ++i) {
      if(adj[i][b].length > 0) {
        nextCell = adj[i][b][0]
        nextDir = i
        break
      }
    }
    nextVertex = nextCell[nextDir^1]

    for(var dir=0; dir<2; ++dir) {
      var nbhd = adj[dir][b]
      for(var k=0; k<nbhd.length; ++k) {
        var e = nbhd[k]
        var p = e[dir^1]
        var cmp = compareAngle(
            positions[a], 
            positions[b], 
            positions[nextVertex],
            positions[p])
        if(cmp > 0) {
          nextCell = e
          nextVertex = p
          nextDir = dir
        }
      }
    }
    if(noCut) {
      return nextVertex
    }
    if(nextCell) {
      cut(nextCell, nextDir)
    }
    return nextVertex
  }
function next(a, b, noCut) {
    var nextCell, nextVertex, nextDir
    for(var i=0; i<2; ++i) {
      if(adj[i][b].length > 0) {
        nextCell = adj[i][b][0]
        nextDir = i
        break
      }
    }
    nextVertex = nextCell[nextDir^1]

    for(var dir=0; dir<2; ++dir) {
      var nbhd = adj[dir][b]
      for(var k=0; k<nbhd.length; ++k) {
        var e = nbhd[k]
        var p = e[dir^1]
        var cmp = compareAngle(
            positions[a], 
            positions[b], 
            positions[nextVertex],
            positions[p])
        if(cmp > 0) {
          nextCell = e
          nextVertex = p
          nextDir = dir
        }
      }
    }
    if(noCut) {
      return nextVertex
    }
    if(nextCell) {
      cut(nextCell, nextDir)
    }
    return nextVertex
  }
function next ( a , b , noCut ) { var nextCell , nextVertex , nextDir for ( var i = 0 ; i < 2 ; ++ i ) { if ( adj [ i ] [ b ] . length > 0 ) { nextCell = adj [ i ] [ b ] [ 0 ] nextDir = i break } } nextVertex = nextCell [ nextDir ^ 1 ] for ( var dir = 0 ; dir < 2 ; ++ dir ) { var nbhd = adj [ dir ] [ b ] for ( var k = 0 ; k < nbhd . length ; ++ k ) { var e = nbhd [ k ] var p = e [ dir ^ 1 ] var cmp = compareAngle ( positions [ a ] , positions [ b ] , positions [ nextVertex ] , positions [ p ] ) if ( cmp > 0 ) { nextCell = e nextVertex = p nextDir = dir } } } if ( noCut ) { return nextVertex } if ( nextCell ) { cut ( nextCell , nextDir ) } return nextVertex }
Find next vertex and cut edge
Find next vertex and cut edge