simplicial-complex
Advanced tools
Comparing version 0.0.1 to 0.1.0
{ | ||
"name": "simplicial-complex", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"description": "Topological indexing for simplicial complexes", | ||
@@ -8,3 +8,3 @@ "main": "topology.js", | ||
"bit-twiddle": "~0.0.1", | ||
"union-find": "~0.0.1" | ||
"union-find": "~0.0.3" | ||
}, | ||
@@ -11,0 +11,0 @@ "devDependencies": { |
@@ -91,6 +91,7 @@ simplicial-complex | ||
### `normalize(cells)` | ||
### `normalize(cells[, attr])` | ||
Canonicalizes a cell complex so that it is possible to compute `findCell` queries. Note that this function is done **in place**. `cells` will be mutated. If this is not acceptable, you should make a copy first using `cloneCells`. | ||
* `cells` is a complex. | ||
* `attr` is an optional array of per-cell properties which is permuted alongside `cells` | ||
@@ -97,0 +98,0 @@ **Returns** `cells` |
@@ -191,3 +191,20 @@ var test = require("tap").test | ||
var cells = top.normalize([ | ||
[1,2,3], | ||
[0], | ||
[5,6,7], | ||
[8,3], | ||
[4,6], | ||
[2,5], | ||
[2,7], | ||
[2,0] | ||
]); | ||
//Compute vertex stars | ||
console.log(cells); | ||
var stars = top.stars(cells); | ||
console.log(stars); | ||
t.equals(stars.length, 9); | ||
t.end(); | ||
@@ -197,10 +214,31 @@ }); | ||
test("boundary", function(t) { | ||
t.end(); | ||
}); | ||
test("connectedComponents_sparse", function(t) { | ||
var tris = top.normalize([ | ||
[0,1,2], | ||
[0,1,3], | ||
[0,2,3], | ||
[1,2,3] | ||
]); | ||
var tetra = [[0,1,2,3]]; | ||
arr_equals(t,top.boundary(tetra,2), tris); | ||
arr_equals(t,top.boundary(tris,1), []); | ||
t.end(); | ||
}); | ||
test("connectedComponents_dense", function(t) { | ||
test("connectedComponents", function(t) { | ||
var graph = top.normalize([ | ||
[0,1], | ||
[1,2], | ||
[2,3], | ||
[5,6], | ||
[4], | ||
[4,7,8] | ||
]); | ||
console.log(top.connectedComponents(graph)); | ||
console.log(top.connectedComponents(graph,9)); | ||
t.end(); | ||
@@ -210,1 +248,2 @@ }); | ||
@@ -92,4 +92,20 @@ "use strict"; "use restrict"; | ||
function compareZipped(a, b) { | ||
return compareCells(a[0], b[0]); | ||
} | ||
//Puts a cell complex into normal order for the purposes of findCell queries | ||
function normalize(cells) { | ||
function normalize(cells, attr) { | ||
if(attr) { | ||
var zipped = new Array(cells.length); | ||
for(var i=0; i<cells.length; ++i) { | ||
zipped[i] = [cells[i], arr[i]]; | ||
} | ||
zipped.sort(compareZipped); | ||
for(var i=0; i<cells.length; ++i) { | ||
cells[i] = zipped[i][0]; | ||
attr[i] = zipped[i][1]; | ||
} | ||
return cells | ||
} | ||
cells.sort(compareCells); | ||
@@ -157,7 +173,7 @@ return cells; | ||
if(!vertex_count) { | ||
vertex_count = countVertices(faces); | ||
vertex_count = countVertices(cells); | ||
} | ||
var stars = new Array(vertex_count); | ||
var res = new Array(vertex_count); | ||
for(var i=0; i<vertex_count; ++i) { | ||
stars[i] = []; | ||
res[i] = []; | ||
} | ||
@@ -167,6 +183,6 @@ for(var i=0; i<cells.length; ++i) { | ||
for(var j=0; j<c.length; ++j) { | ||
stars[c[j]].push(i); | ||
res[c[j]].push(i); | ||
} | ||
} | ||
return stars; | ||
return res; | ||
}; | ||
@@ -236,3 +252,3 @@ exports.stars = stars; | ||
while(true) { | ||
while(i < res.length && !compareCells(res[i], res[i+1])) { | ||
while(i < res.length-1 && compareCells(res[i], res[i+1]) === 0) { | ||
i += 2; | ||
@@ -245,3 +261,3 @@ } | ||
, b = res[i++]; | ||
for(var j=0; j<=d; ++d) { | ||
for(var j=0; j<=n; ++j) { | ||
a[j] = b[j]; | ||
@@ -285,4 +301,4 @@ } | ||
function connectedComponents_sparse(cells) { | ||
var verts = skeleton(cells, 0) | ||
, labels = new UnionFind(verts.length); | ||
var vertices = skeleton(cells, 0) | ||
, labels = new UnionFind(vertices.length); | ||
for(var i=0; i<cells.length; ++i) { | ||
@@ -297,4 +313,4 @@ var c = cells[i]; | ||
} | ||
var components = [] | ||
, component_labels = labels.ranks; | ||
var components = [] | ||
, component_labels = labels.ranks; | ||
for(var i=0; i<component_labels.length; ++i) { | ||
@@ -304,3 +320,3 @@ component_labels[i] = -1; | ||
for(var i=0; i<cells.length; ++i) { | ||
var l = labels.find(findCell(verts, [cells[i][0]])); | ||
var l = labels.find(findCell(vertices, [cells[i][0]])); | ||
if(component_labels[l] < 0) { | ||
@@ -307,0 +323,0 @@ component_labels[l] = components.length; |
20279
502
193
Updatedunion-find@~0.0.3