@@ -37,12 +37,12 @@ Fixed2DArray.prototype.getWidth = function getWidth() {
37
37
*
38
38
* @param rowNumber {number} number of the row where top left is (0,0).
39
39
*/
40
- Fixed2DArray . prototype . getRow = function getRow ( rowNumber ) {
41
- try {
42
- this . validateCoords ( 0 , rowNumber ) ;
43
- } catch ( err ) {
44
- throw new Error ( 'fixed-2d-array: row number ' + rowNumber + ' is not valid.' +
45
- ' The size of this array is (' + this . _width + '/' + this . _height + ')' ) ;
40
+ Fixed2DArray . prototype . getRow = function getRow ( rowNumber ) {
41
+ try {
42
+ this . validateCoords ( 0 , rowNumber ) ;
43
+ } catch ( err ) {
44
+ throw new Error ( 'fixed-2d-array: row number ' + rowNumber + ' is not valid.' +
45
+ ' The size of this array is (' + this . _width + '/' + this . _height + ')' ) ;
46
46
}
47
47
48
48
return this . _grid [ rowNumber ] ;
@@ -53,12 +53,12 @@ Fixed2DArray.prototype.getRow = function getRow(rowNumber){
53
53
*
54
54
* @param colNumber {number} number of the column where top left is (0,0).
55
55
*/
56
- Fixed2DArray . prototype . getColumn = function getColumn ( colNumber ) {
57
- try {
58
- this . validateCoords ( colNumber , 0 ) ;
59
- } catch ( err ) {
60
- throw new Error ( 'fixed-2d-array: row number ' + colNumber + ' is not valid.' +
61
- ' The size of this array is (' + this . _width + '/' + this . _height + ')' ) ;
56
+ Fixed2DArray . prototype . getColumn = function getColumn ( colNumber ) {
57
+ try {
58
+ this . validateCoords ( colNumber , 0 ) ;
59
+ } catch ( err ) {
60
+ throw new Error ( 'fixed-2d-array: column number ' + colNumber + ' is not valid.' +
61
+ ' The size of this array is (' + this . _width + '/' + this . _height + ')' ) ;
62
62
}
63
63
64
64
var returnArray = [ ] ;
@@ -83,10 +83,10 @@ Fixed2DArray.prototype.getColumn = function getColumn(colNumber){
83
83
*
84
84
* @param thisArg Optional. Value to use as this when executing callback.
85
85
*/
86
- Fixed2DArray . prototype . forEach = function forEach ( fn , thisArg ) {
86
+ Fixed2DArray . prototype . forEach = function forEach ( fn , thisArg ) {
87
87
for ( var i = 0 ; i < this . _width ; i ++ ) {
88
88
for ( var j = 0 ; j < this . _height ; j ++ ) {
89
- fn . call ( thisArg , this . _grid [ i ] [ j ] , { x : i , y : j } , this ) ;
89
+ fn . call ( thisArg , this . _grid [ i ] [ j ] , { x : i , y : j } , this ) ;
90
90
}
91
91
}
92
92
} ;
@@ -98,10 +98,9 @@ Fixed2DArray.prototype.forEach = function forEach(fn, thisArg){
98
98
* @param y {number} y coordinate
99
99
*/
100
100
Fixed2DArray . prototype . validateCoords = function validateCoords ( x , y ) {
101
- if ( x < 0 || y < 0 || x >= this . _width || y >= this . _height ) {
102
- throw new Error ( 'fixed-2d-array: the coordinate (' + x + '/' + y + ') ' +
103
- 'is not valid.' +
104
- ' The size of this array is (' + this . _width + '/' + this . _height + ')' ) ;
101
+ if ( x < 0 || y < 0 || x >= this . _width || y >= this . _height ) {
102
+ throw new Error ( 'fixed-2d-array: the coordinate (' + x + '/' + y + ') ' +
103
+ 'is not valid. The size of this array is (' + this . _width + '/' + this . _height + ')' ) ;
105
104
}
106
105
} ;
107
106
@@ -112,7 +111,7 @@ Fixed2DArray.prototype.validateCoords = function validateCoords(x, y) {
112
111
* @param y {number} y coordinate
113
112
*/
114
113
Fixed2DArray . prototype . get = function get ( x , y ) {
115
- this . validateCoords ( x , y ) ;
114
+ this . validateCoords ( x , y ) ;
116
115
return this . _grid [ x ] [ y ] ;
117
116
} ;
118
117
@@ -124,7 +123,7 @@ Fixed2DArray.prototype.get = function get(x, y) {
124
123
* @param val new value
125
124
*/
126
125
Fixed2DArray . prototype . set = function set ( x , y , val ) {
127
- this . validateCoords ( x , y ) ;
126
+ this . validateCoords ( x , y ) ;
128
127
this . _grid [ x ] [ y ] = val ;
129
128
} ;
130
129
@@ -148,25 +147,24 @@ Fixed2DArray.prototype.set = function set(x, y, val) {
148
147
* @param y {number} y coordinate
149
148
* @param distance {number} length of the neighbor-square around the given coordinate.
150
149
*/
151
- Fixed2DArray . prototype . getNeighbours = function getNeighbours ( x , y , distance ) {
152
- this . validateCoords ( x , y ) ;
153
-
154
- if ( typeof distance === 'undefined' ) { distance = 1 ; }
155
- if ( distance <= 0 ) {
150
+ Fixed2DArray . prototype . getNeighbours = function getNeighbours ( x , y , distance ) {
151
+ this . validateCoords ( x , y ) ;
152
+
153
+ if ( typeof distance === 'undefined' ) { distance = 1 ; }
154
+ if ( distance <= 0 ) {
156
155
return [ ] ;
157
156
}
158
157
159
158
var returnArray = [ ] ;
160
159
161
- for ( var i = x - distance ; i <= x + distance ; i ++ ) {
162
- for ( var j = y - distance ; j <= y + distance ; j ++ ) {
160
+ for ( var i = x - distance ; i <= x + distance ; i ++ ) {
161
+ for ( var j = y - distance ; j <= y + distance ; j ++ ) {
163
162
try {
164
- if ( ! ( i === x && j === y ) ) {
165
- var element = this . get ( i , j ) ;
163
+ if ( ! ( i === x && j === y ) ) {
164
+ var element = this . get ( i , j ) ;
166
165
returnArray . push ( element ) ;
167
166
}
168
- }
169
- catch ( e ) {
167
+ } catch ( e ) {
170
168
//this is a field at the edge of the grid.
171
169
//ignore
172
170
}
@@ -218,20 +216,17 @@ Fixed2DArray.prototype.getNeighbours = function getNeighbours(x, y, distance){
218
216
* @param y2 {number} second y coordinate.
219
217
* @param distance {number} Optional. Maximum distance for coordinates to be considered neighbors.
220
218
*/
221
- Fixed2DArray . prototype . areNeighbours = function areNeighbours ( x1 , y1 , x2 , y2 , distance ) {
222
- this . validateCoords ( x1 , y1 ) ;
223
- this . validateCoords ( x2 , y2 ) ;
219
+ Fixed2DArray . prototype . areNeighbours = function areNeighbours ( x1 , y1 , x2 , y2 , distance ) {
220
+ this . validateCoords ( x1 , y1 ) ;
221
+ this . validateCoords ( x2 , y2 ) ;
224
222
225
- if ( typeof distance === 'undefined' ) { distance = 1 ; }
226
- if ( distance <= 0 ) {
223
+ if ( typeof distance === 'undefined' ) { distance = 1 ; }
224
+ if ( distance <= 0 ) {
227
225
return false ;
228
226
}
229
227
230
- if ( ( Math . abs ( x1 - x2 ) <= distance ) && ( Math . abs ( y1 - y2 ) <= distance ) ) {
231
- return true ;
232
- } else {
233
- return false ;
234
- }
228
+
229
+ return ( Math . abs ( x1 - x2 ) <= distance ) && ( Math . abs ( y1 - y2 ) <= distance ) ;
235
230
} ;
236
231
237
- module . exports = Fixed2DArray ;
232
+ module . exports = Fixed2DArray ;
0 commit comments