topology.js
function connectedComponents_dense(cells, vertex_count) {
  var labels = new UnionFind(vertex_count)
  for(var i=0; i<cells.length; ++i) {
    var c = cells[i]
    for(var j=0; j<c.length; ++j) {
      for(var k=j+1; k<c.length; ++k) {
        labels.link(c[j], c[k])
      }
    }
  }
  var components = []
    , component_labels = labels.ranks
  for(var i=0; i<component_labels.length; ++i) {
    component_labels[i] = -1
  }
  for(var i=0; i<cells.length; ++i) {
    var l = labels.find(cells[i][0])
    if(component_labels[l] < 0) {
      component_labels[l] = components.length
      components.push([cells[i].slice(0)])
    } else {
      components[component_labels[l]].push(cells[i].slice(0))
    }
  }
  return components
}
function connectedComponents_dense(cells, vertex_count) {
  var labels = new UnionFind(vertex_count)
  for(var i=0; i<cells.length; ++i) {
    var c = cells[i]
    for(var j=0; j<c.length; ++j) {
      for(var k=j+1; k<c.length; ++k) {
        labels.link(c[j], c[k])
      }
    }
  }
  var components = []
    , component_labels = labels.ranks
  for(var i=0; i<component_labels.length; ++i) {
    component_labels[i] = -1
  }
  for(var i=0; i<cells.length; ++i) {
    var l = labels.find(cells[i][0])
    if(component_labels[l] < 0) {
      component_labels[l] = components.length
      components.push([cells[i].slice(0)])
    } else {
      components[component_labels[l]].push(cells[i].slice(0))
    }
  }
  return components
}
function connectedComponents_dense ( cells , vertex_count ) { var labels = new UnionFind ( vertex_count ) for ( var i = 0 ; i < cells . length ; ++ i ) { var c = cells [ i ] for ( var j = 0 ; j < c . length ; ++ j ) { for ( var k = j + 1 ; k < c . length ; ++ k ) { labels . link ( c [ j ] , c [ k ] ) } } } var components = [ ] , component_labels = labels . ranks for ( var i = 0 ; i < component_labels . length ; ++ i ) { component_labels [ i ] = - 1 } for ( var i = 0 ; i < cells . length ; ++ i ) { var l = labels . find ( cells [ i ] [ 0 ] ) if ( component_labels [ l ] < 0 ) { component_labels [ l ] = components . length components . push ( [ cells [ i ] . slice ( 0 ) ] ) } else { components [ component_labels [ l ] ] . push ( cells [ i ] . slice ( 0 ) ) } } return components }
Computes connected components for a dense cell complex
Computes connected components for a dense cell complex