-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutil.js
More file actions
35 lines (31 loc) · 759 Bytes
/
util.js
File metadata and controls
35 lines (31 loc) · 759 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
//Browser Compatibility
if(typeof console !== "object") {
console = {};
}
if(typeof console.log !== "function") {
console.log = function() {};
}
if(typeof console.assert !== "function") {
console.assert = function() {};
}
Array.prototype.get = function(i) {
if(this.length === 0) {
console.log("Tried to get value from 0-length array");
return undefined;
}
return this[this.normalizeIndex(i)];
}
Array.prototype.normalizeIndex = function(i) {
if(this.length === 0) {
console.log("Tried to normalize index of 0-length array");
return undefined;
}
while(i < 0) {
i += this.length;
}
return i % this.length;
}
function isApproxEqual(a, b) {
var epsilon = 1e-4;
return (a + epsilon >= b) && (a - epsilon <= b);
}