MCPcopy Create free account
hub / github.com/algorithm-visualizer/algorithm-visualizer / Array2DTracer

Class Array2DTracer

src/core/tracers/Array2DTracer.js:12–63  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10}
11
12class Array2DTracer extends Tracer {
13 getRendererClass() {
14 return Array2DRenderer;
15 }
16
17 set(array2d = []) {
18 this.data = array2d.map(array1d => [...array1d].map(value => new Element(value)));
19 super.set();
20 }
21
22 patch(x, y, v = this.data[x][y].value) {
23 if (!this.data[x][y]) this.data[x][y] = new Element();
24 this.data[x][y].value = v;
25 this.data[x][y].patched = true;
26 }
27
28 depatch(x, y) {
29 this.data[x][y].patched = false;
30 }
31
32 select(sx, sy, ex = sx, ey = sy) {
33 for (let x = sx; x <= ex; x++) {
34 for (let y = sy; y <= ey; y++) {
35 this.data[x][y].selected = true;
36 }
37 }
38 }
39
40 selectRow(x, sy, ey) {
41 this.select(x, sy, x, ey);
42 }
43
44 selectCol(y, sx, ex) {
45 this.select(sx, y, ex, y);
46 }
47
48 deselect(sx, sy, ex = sx, ey = sy) {
49 for (let x = sx; x <= ex; x++) {
50 for (let y = sy; y <= ey; y++) {
51 this.data[x][y].selected = false;
52 }
53 }
54 }
55
56 deselectRow(x, sy, ey) {
57 this.deselect(x, sy, x, ey);
58 }
59
60 deselectCol(y, sx, ex) {
61 this.deselect(sx, y, ex, y);
62 }
63}
64
65export default Array2DTracer;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected