-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
39 lines (30 loc) · 758 Bytes
/
index.js
File metadata and controls
39 lines (30 loc) · 758 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
function mergeVertices(cells, positions) {
function hashPosition(position) {
return JSON.stringify(position);
}
var positionLookup = {};
positions.forEach(function(position) {
positionLookup[hashPosition(position)] = position;
});
var keys = Object.keys(positionLookup);
var indexLookup = {};
var index = 0;
keys.forEach(function(key) {
indexLookup[key] = index;
index++;
});
cells = cells.map(function(cell) {
return cell.map(function(index) {
var hash = hashPosition(positions[index])
return indexLookup[hash];
})
});
positions = keys.map(function(key) {
return positionLookup[key];
});
return {
cells: cells,
positions: positions
};
}
module.exports = mergeVertices;