|
| 1 | +// Only seems to be used for Horspool's algorithm |
| 2 | + |
1 | 3 | /* eslint-disable no-plusplus */
|
2 | 4 | /* eslint-disable class-methods-use-this */
|
3 | 5 | /* eslint-disable max-classes-per-file */
|
@@ -41,89 +43,81 @@ class TwoArray2DTracer extends Tracer {
|
41 | 43 | * @param {array} array2d
|
42 | 44 | * @param {string} algo used to mark if it is a specific algorithm
|
43 | 45 | */
|
44 |
| - set(array2d = [],array2d1=[], algo) { |
| 46 | + set(array2d = [], array2d1 = [], algo) { |
45 | 47 | this.data = array2d.map(array1d => [...array1d].map(value => new Element(value)));
|
46 | 48 | this.data1 = array2d1.map(array1d => [...array1d].map(value => new Element(value)));
|
47 | 49 | this.algo = algo;
|
48 | 50 | super.set();
|
49 | 51 | }
|
50 | 52 |
|
51 |
| - getposition(x,y){ |
| 53 | + getposition(x, y) { |
52 | 54 | let longestRow = this.data.reduce((longestRow, row) => longestRow.length < row.length ? row : longestRow, []);
|
53 | 55 | let len = longestRow.length;
|
54 |
| - var xx=x; |
55 |
| - var pos=0; |
56 |
| - if (x>=len){xx=x-len;pos=1;} |
57 |
| - return [pos,xx,y]; |
| 56 | + var xx = x; |
| 57 | + var pos = 0; |
| 58 | + if (x >= len) { xx = x - len; pos = 1; } |
| 59 | + return [pos, xx, y]; |
58 | 60 | }
|
59 | 61 |
|
60 | 62 | patch(x, y, v = this.data[x][y].value) {
|
61 |
| - let rr=this.getposition(x,y); |
62 |
| - var pos=rr[0]; |
| 63 | + let rr = this.getposition(x, y); |
| 64 | + var pos = rr[0]; |
63 | 65 | var xx = rr[2];//x is actually the vertical one
|
64 | 66 | var yy = rr[1];
|
65 |
| - if (pos===0) |
66 |
| - { |
67 |
| - if (!this.data[xx][yy]) {this.data[xx][yy] = new Element();} |
| 67 | + if (pos === 0) { |
| 68 | + if (!this.data[xx][yy]) { this.data[xx][yy] = new Element(); } |
68 | 69 | this.data[xx][yy].value = v;
|
69 | 70 | this.data[xx][yy].patched = true;
|
70 | 71 | }
|
71 |
| - else |
72 |
| - { |
73 |
| - if (!this.data1[xx][yy]) {this.data1[xx][yy] = new Element();} |
| 72 | + else { |
| 73 | + if (!this.data1[xx][yy]) { this.data1[xx][yy] = new Element(); } |
74 | 74 | this.data1[xx][yy].value = v;
|
75 | 75 | this.data1[xx][yy].patched = true;
|
76 | 76 | }
|
77 | 77 |
|
78 | 78 | }
|
79 | 79 |
|
80 | 80 | depatch(x, y) {
|
81 |
| - let rr=this.getposition(x,y); |
82 |
| - var pos=rr[0]; |
| 81 | + let rr = this.getposition(x, y); |
| 82 | + var pos = rr[0]; |
83 | 83 | var xx = rr[2];//x is actually the vertical one
|
84 | 84 | var yy = rr[1];
|
85 |
| - if (pos===0) |
86 |
| - { |
87 |
| - if (!this.data[xx][yy]) {this.data[xx][yy] = new Element();} |
| 85 | + if (pos === 0) { |
| 86 | + if (!this.data[xx][yy]) { this.data[xx][yy] = new Element(); } |
88 | 87 |
|
89 | 88 | this.data[xx][yy].patched = false;
|
90 | 89 | }
|
91 |
| - else |
92 |
| - { |
93 |
| - if (!this.data1[xx][yy]) {this.data1[xx][yy] = new Element();} |
| 90 | + else { |
| 91 | + if (!this.data1[xx][yy]) { this.data1[xx][yy] = new Element(); } |
94 | 92 |
|
95 | 93 | this.data1[xx][yy].patched = false;
|
96 | 94 | }
|
97 | 95 | }
|
98 | 96 | select(x, y) {
|
99 |
| - let rr=this.getposition(x,y); |
100 |
| - var pos=rr[0]; |
| 97 | + let rr = this.getposition(x, y); |
| 98 | + var pos = rr[0]; |
101 | 99 | var xx = rr[2];//x is actually the vertical one
|
102 | 100 | var yy = rr[1];
|
103 |
| - if (pos===0) |
104 |
| - { |
105 |
| - if (!this.data[xx][yy]) {this.data[xx][yy] = new Element();} |
| 101 | + if (pos === 0) { |
| 102 | + if (!this.data[xx][yy]) { this.data[xx][yy] = new Element(); } |
106 | 103 | this.data[xx][yy].selected = true;
|
107 | 104 | }
|
108 |
| - else |
109 |
| - { |
110 |
| - if (!this.data1[xx][yy]) {this.data1[xx][yy] = new Element();} |
| 105 | + else { |
| 106 | + if (!this.data1[xx][yy]) { this.data1[xx][yy] = new Element(); } |
111 | 107 | this.data1[xx][yy].selected = true;
|
112 | 108 | }
|
113 | 109 |
|
114 | 110 | }
|
115 | 111 |
|
116 | 112 | deselect(x, y) {
|
117 |
| - let rr=this.getposition(x,y); |
118 |
| - var pos=rr[0]; |
| 113 | + let rr = this.getposition(x, y); |
| 114 | + var pos = rr[0]; |
119 | 115 | var xx = rr[2];//x is actually the vertical one
|
120 | 116 | var yy = rr[1];
|
121 |
| - if (pos===0) |
122 |
| - { |
| 117 | + if (pos === 0) { |
123 | 118 | this.data[xx][yy].selected = false;
|
124 | 119 | }
|
125 |
| - else |
126 |
| - { |
| 120 | + else { |
127 | 121 | this.data1[xx][yy].selected = false;
|
128 | 122 | }
|
129 | 123 |
|
|
0 commit comments