clean-pslg.js
function cleanPSLG (points, edges, colors) {
  // If using colors, augment edges with color data
  var prevEdges
  if (colors) {
    prevEdges = edges
    var augEdges = new Array(edges.length)
    for (var i = 0; i < edges.length; ++i) {
      var e = edges[i]
      augEdges[i] = [e[0], e[1], colors[i]]
    }
    edges = augEdges
  }

  // First round: remove duplicate edges and points
  var modified = preRound(points, edges, !!colors)

  // Run snap rounding until convergence
  while (snapRound(points, edges, !!colors)) {
    modified = true
  }

  // Strip color tags
  if (!!colors && modified) {
    prevEdges.length = 0
    colors.length = 0
    for (var i = 0; i < edges.length; ++i) {
      var e = edges[i]
      prevEdges.push([e[0], e[1]])
      colors.push(e[2])
    }
  }

  return modified
}
function cleanPSLG (points, edges, colors) {
  // If using colors, augment edges with color data
  var prevEdges
  if (colors) {
    prevEdges = edges
    var augEdges = new Array(edges.length)
    for (var i = 0; i < edges.length; ++i) {
      var e = edges[i]
      augEdges[i] = [e[0], e[1], colors[i]]
    }
    edges = augEdges
  }

  // First round: remove duplicate edges and points
  var modified = preRound(points, edges, !!colors)

  // Run snap rounding until convergence
  while (snapRound(points, edges, !!colors)) {
    modified = true
  }

  // Strip color tags
  if (!!colors && modified) {
    prevEdges.length = 0
    colors.length = 0
    for (var i = 0; i < edges.length; ++i) {
      var e = edges[i]
      prevEdges.push([e[0], e[1]])
      colors.push(e[2])
    }
  }

  return modified
}
function cleanPSLG ( points , edges , colors ) { // If using colors, augment edges with color data var prevEdges if ( colors ) { prevEdges = edges var augEdges = new Array ( edges . length ) for ( var i = 0 ; i < edges . length ; ++ i ) { var e = edges [ i ] augEdges [ i ] = [ e [ 0 ] , e [ 1 ] , colors [ i ] ] } edges = augEdges } // First round: remove duplicate edges and points var modified = preRound ( points , edges , ! ! colors ) // Run snap rounding until convergence while ( snapRound ( points , edges , ! ! colors ) ) { modified = true } // Strip color tags if ( ! ! colors && modified ) { prevEdges . length = 0 colors . length = 0 for ( var i = 0 ; i < edges . length ; ++ i ) { var e = edges [ i ] prevEdges . push ( [ e [ 0 ] , e [ 1 ] ] ) colors . push ( e [ 2 ] ) } } return modified }
Main loop, runs PSLG clean up until completion
Main loop runs PSLG clean up until completion