* Count disconnected mesh shells via BFS on the adjacency graph. * @param {Array >} adjacency - from buildAdjacency * @param {number} triCount * @returns {number} number of disconnected components
(adjacency, triCount)
| 18 | |
| 19 | /** |
| 20 | * Count disconnected mesh shells via BFS on the adjacency graph. |
| 21 | * @param {Array<Array<{neighbor:number}>>} adjacency - from buildAdjacency |
| 22 | * @param {number} triCount |
| 23 | * @returns {number} number of disconnected components |
| 24 | */ |
| 25 | function countShells(adjacency, triCount) { |
| 26 | const visited = new Uint8Array(triCount); |
| 27 | let shellCount = 0; |
| 28 | for (let seed = 0; seed < triCount; seed++) { |
| 29 | if (visited[seed]) continue; |
| 30 | shellCount++; |
| 31 | const queue = [seed]; |
| 32 | visited[seed] = 1; |
| 33 | let head = 0; |
| 34 | while (head < queue.length) { |
| 35 | const cur = queue[head++]; |
| 36 | const neighbors = adjacency[cur]; |
| 37 | if (!neighbors) continue; |
| 38 | for (const { neighbor } of neighbors) { |
| 39 | if (!visited[neighbor]) { |
| 40 | visited[neighbor] = 1; |
| 41 | queue.push(neighbor); |
| 42 | } |
| 43 | } |
| 44 | } |
| 45 | } |
no test coverage detected