-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
74 lines (74 loc) · 2.19 KB
/
index.js
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Generated by CoffeeScript 1.9.2
module.exports = {
up: function(x, y, z) {
var halfx, halfy, prevz;
halfx = Math.floor(x / 2);
halfy = Math.floor(y / 2);
prevz = z - 1;
return [halfx, halfy, prevz];
},
down: function(x, y, z) {
var doublex, doubley, nextz;
doublex = x * 2;
doubley = y * 2;
nextz = z + 1;
return [[doublex, doubley, nextz], [doublex + 1, doubley, nextz], [doublex + 1, doubley + 1, nextz], [doublex, doubley + 1, nextz]];
},
preallocate: function(zmax) {
var i, levels, results;
levels = (function() {
results = [];
for (var i = 0; 0 <= zmax ? i <= zmax : i >= zmax; 0 <= zmax ? i++ : i--){ results.push(i); }
return results;
}).apply(this).map(function(z) {
var len;
len = Math.pow(2, z);
return new Array(len * len);
});
return {
get: function(x, y, z) {
var len;
len = Math.pow(2, z);
if (z > zmax) {
return null;
}
if (y * len + x >= levels[z].length) {
return null;
}
return levels[z][y * len + x];
},
assert: function(x, y, z) {
var len;
len = Math.pow(2, z);
if (z > zmax) {
return null;
}
if (y * len + x >= levels[z].length) {
return null;
}
if (levels[z][y * len + x] == null) {
levels[z][y * len + x] = {};
}
return levels[z][y * len + x];
},
visit: function(zstart, zend, f) {
var j, k, l, len1, len2, m, ref, ref1, ref2, results1, widths, x, y, z;
for (z = j = ref = zstart, ref1 = zend; ref <= ref1 ? j <= ref1 : j >= ref1; z = ref <= ref1 ? ++j : --j) {
widths = (function() {
results1 = [];
for (var k = 0, ref2 = Math.pow(2, z); 0 <= ref2 ? k < ref2 : k > ref2; 0 <= ref2 ? k++ : k--){ results1.push(k); }
return results1;
}).apply(this);
for (l = 0, len1 = widths.length; l < len1; l++) {
y = widths[l];
for (m = 0, len2 = widths.length; m < len2; m++) {
x = widths[m];
f(x, y, z);
}
}
}
return null;
}
};
}
};