Repository navigation
Expand file tree
/
Copy patharraymap.js
More file actions
89 lines (66 loc) · 1.29 KB
/
Copy patharraymap.js
File metadata and controls
89 lines (66 loc) · 1.29 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
The arraymap component creates an auto expandable two-dimensional array.
*/
re.c('arraymap')
.inherit({
lengthX:0,
lengthY:0
})
.extend({
/*map:null,
size:null,*/
value:0,
set:function(x, y, value){
//increate y length
while(y >= this.map.length){
var m = new Array(this.map[0]);
for(var l in m){
m[l] = this.value;
}
this.map.push(m);
}
//increase x length
while(x >= this.map[this.map.length-1].length){
for(var k=0; k<this.map.length; k++){
this.map[k].push(this.value);
}
}
this.lengthX = this.map[y].length;
this.lengthY = this.map.length;
this.map[y][x] = value;
return this;
},
within:function(x, y){
if(y < 0 || y >= this.lengthY || x < 0 || x >= this.lengthX){
return false;
}
return true;
},
get:function(x, y){
if(this.within(x,y)){
return this.map[y][x];
}
return null;
},
copy:function(a){
for(var y=0; y<a.length; y++){
for(var x=0; x<a[0].length; x++){
this.set(x, y, a[y][x]);
}
}
return this;
},
copyByRef:function(m){
this.map = m;
if(m.length > 0){
this.lengthX = m[0].length;
} else {
this.lengthX = 0;
}
this.lengthY = m.length;
return this;
}
})
.init(function(){
this.map = [];
});