MCPcopy Create free account
hub / github.com/CNCKitchen/stlTexturizer / countShells

Function countShells

js/meshValidation.js:20–42  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

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 */
25function 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 }

Callers 1

runFastDiagnosticsFunction · 0.85

Calls 1

pushMethod · 0.80

Tested by

no test coverage detected