corrade-nucleus-nucleons – Diff between revs 7 and 9
?pathlinks?
Rev 7 | Rev 9 | |||
---|---|---|---|---|
Line 10... | Line 10... | |||
10 | new Array(Math.max(this.length, a.length)), |
10 | new Array(Math.max(this.length, a.length)), |
|
11 | function(e, i) { |
11 | function(e, i) { |
|
12 | var o = {}; |
12 | var o = {}; |
|
13 | o[a[i]] = b[i]; |
13 | o[a[i]] = b[i]; |
|
14 | return o; |
14 | return o; |
|
15 | }); |
15 | }); |
|
16 | }; |
16 | }; |
|
17 | } |
17 | } |
|
18 | $.extend({ |
18 | $.extend({ |
|
19 | product: function(a, b) { |
19 | product: function(a, b) { |
|
20 | return $.map( |
20 | return $.map( |
|
21 | new Array(Math.max(this.length, a.length)), |
21 | new Array(Math.max(this.length, a.length)), |
|
22 | function(e, i) { |
22 | function(e, i) { |
|
23 | var o = {}; |
23 | var o = {}; |
|
24 | o[a[i]] = b[i]; |
24 | o[a[i]] = b[i]; |
|
25 | return o; |
25 | return o; |
|
26 | }); |
26 | }); |
|
27 | } |
27 | } |
|
28 | }); |
28 | }); |
|
Line 29... | Line 29... | |||
29 | |
29 | |
|
30 | /*************************************************************************/ |
30 | /*************************************************************************/ |
|
Line 65... | Line 65... | |||
65 | return [a.slice(0, n)] |
65 | return [a.slice(0, n)] |
|
66 | .concat(a.slice(n).chunk(n)); |
66 | .concat(a.slice(n).chunk(n)); |
|
67 | } |
67 | } |
|
68 | }); |
68 | }); |
|
Line -... | Line 69... | |||
- | 69 | |
||
- | 70 | /*************************************************************************/ |
||
- | 71 | /* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */ |
||
69 | |
72 | /*************************************************************************/ |
|
- | 73 | /*stackoverflow.com/questions/7837456/how-to-compare-arrays-in-javascript*/ |
||
- | 74 | /*************************************************************************/ |
||
- | 75 | if (!Array.prototype.equals) { |
||
- | 76 | // attach the .equals method to Array's prototype to call it on any array |
||
- | 77 | Array.prototype.equals = function(a) { |
||
- | 78 | // if the other array is a falsy value, return |
||
- | 79 | if (!a) { |
||
- | 80 | return false; |
||
- | 81 | } |
||
- | 82 | |
||
- | 83 | // compare lengths - can save a lot of time |
||
- | 84 | if (this.length !== a.length) { |
||
- | 85 | return false; |
||
- | 86 | } |
||
- | 87 | |
||
- | 88 | for (var i = 0, l = this.length; i < l; i++) { |
||
- | 89 | // Check if we have nested arrays |
||
- | 90 | if (this[i] instanceof Array && a[i] instanceof Array) { |
||
- | 91 | // recurse into the nested arrays |
||
- | 92 | if (!this[i].equals(a[i])) { |
||
- | 93 | return false; |
||
- | 94 | } |
||
- | 95 | } else if (this[i] !== a[i]) { |
||
- | 96 | // Warning - two different object instances will never be equal: {x:20} != {x:20} |
||
- | 97 | return false; |
||
- | 98 | } |
||
- | 99 | } |
||
- | 100 | return true; |
||
- | 101 | }; |
||
- | 102 | } |
||
- | 103 | |
||
- | 104 | $.extend({ |
||
- | 105 | equals: function(a) { |
||
- | 106 | // if the other array is a falsy value, return |
||
- | 107 | if (!a) { |
||
- | 108 | return false; |
||
- | 109 | } |
||
- | 110 | |
||
- | 111 | // compare lengths - can save a lot of time |
||
- | 112 | if (this.length !== a.length) { |
||
- | 113 | return false; |
||
- | 114 | } |
||
- | 115 | |
||
- | 116 | for (var i = 0, l = this.length; i < l; i++) { |
||
- | 117 | // Check if we have nested arrays |
||
- | 118 | if (this[i] instanceof Array && a[i] instanceof Array) { |
||
- | 119 | // recurse into the nested arrays |
||
- | 120 | if (!this[i].equals(a[i])) { |
||
- | 121 | return false; |
||
- | 122 | } |
||
- | 123 | } else if (this[i] !== a[i]) { |
||
- | 124 | // Warning - two different object instances will never be equal: {x:20} != {x:20} |
||
- | 125 | return false; |
||
- | 126 | } |
||
- | 127 | } |
||
- | 128 | return true; |
||
- | 129 | } |
||
- | 130 | }); |
||
70 | /////////////////////////////////////////////////////////////////////////// |
131 | |
|
71 | // Copyright (C) 2016 Wizardry and Steamworks - License: GNU GPLv3 // |
132 | /* Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 */ |
|
72 | /////////////////////////////////////////////////////////////////////////// |
133 | /*************************************************************************/ |
|
73 | function wasCSVToArray(csv) { |
134 | function wasCSVToArray(csv) { |
|
74 | var l = []; |
135 | var l = []; |
|
75 | var s = []; |
136 | var s = []; |
|
Line 106... | Line 167... | |||
106 | l.push(m); |
167 | l.push(m); |
|
Line 107... | Line 168... | |||
107 | |
168 | |
|
108 | return l; |
169 | return l; |
|
Line 109... | Line 170... | |||
109 | } |
170 | } |
|
110 | |
171 | |
|
111 | /////////////////////////////////////////////////////////////////////////// |
172 | /*************************************************************************/ |
|
112 | // Copyright (C) 2016 Wizardry and Steamworks - License: GNU GPLv3 // |
173 | /* Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 */ |
|
113 | /////////////////////////////////////////////////////////////////////////// |
174 | /*************************************************************************/ |
|
114 | function wasArrayToCSV(a) { |
175 | function wasArrayToCSV(a) { |
|
115 | var csv = []; |
176 | var csv = []; |
|
116 | for(var i=0; i<a.length; ++i) { |
177 | for(var i=0; i<a.length; ++i) { |
|
Line 121... | Line 182... | |||
121 | } |
182 | } |
|
122 | csv[i] = cell; |
183 | csv[i] = cell; |
|
123 | } |
184 | } |
|
124 | return csv.join(); |
185 | return csv.join(); |
|
125 | } |
186 | } |
|
- | 187 | |
||
- | 188 | /* Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 */ |
||
- | 189 | /*************************************************************************/ |
||
- | 190 | function wasMapValueToRange(value, xMin, xMax, yMin, yMax) { |
||
- | 191 | return yMin + ( |
||
- | 192 | ( yMax - yMin ) * ( value - xMin ) / ( xMax - xMin ) |
||
- | 193 | ); |
||
- | 194 | } |
||
- | 195 | |
||
- | 196 | /* Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 */ |
||
- | 197 | /*************************************************************************/ |
||
- | 198 | function wasHexToRGB(hex) { |
||
- | 199 | var shortRegEx = /^#?([a-f\d])([a-f\d])([a-f\d])$/i; |
||
- | 200 | hex = hex.replace( |
||
- | 201 | shortRegEx, |
||
- | 202 | function(m, r, g, b) { |
||
- | 203 | return r + r + g + g + b + b; |
||
- | 204 | } |
||
- | 205 | ); |
||
- | 206 | |
||
- | 207 | var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); |
||
- | 208 | return result ? { |
||
- | 209 | r: parseInt(result[1], 16), |
||
- | 210 | g: parseInt(result[2], 16), |
||
- | 211 | b: parseInt(result[3], 16) |
||
- | 212 | } : null; |
||
- | 213 | } |
||
- | 214 | |
||
- | 215 | /*************************************************************************/ |
||
- | 216 | /* Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 */ |
||
- | 217 | /*************************************************************************/ |
||
- | 218 | function wasRGBToHex(r, g, b) { |
||
- | 219 | return "#" + ( |
||
- | 220 | (1 << 24) +><> |
||
- | 221 | |
||
- | 222 | |
||
- | 223 | |
||
- | 224 | |
||
- | 225 | |