src/parse-map.js
function generateContourGrid(arr) {
  // Generate grid for holding values.
  var contour_grid = new Array(arr.length - 1);
  for (var n = 0; n < contour_grid.length; n++) {
    contour_grid[n] = new Array(arr[0].length - 1);
  }
  var corners = [1.1, 1.2, 1.3, 1.4];
  // Specifies the resulting values for the above corner values. The index
  // of the objects in this array corresponds to the proper values for the
  // quadrant of the same index.
  var corner_values = [
    {1.1: 3, 1.2: 0, 1.3: 2, 1.4: 1},
    {1.1: 0, 1.2: 3, 1.3: 1, 1.4: 2},
    {1.1: 3, 1.2: 1, 1.3: 2, 1.4: 0},
    {1.1: 1, 1.2: 3, 1.3: 0, 1.4: 2}
  ];
  for (var i = 0; i < (arr.length - 1); i++) {
    for (var j = 0; j < (arr[0].length - 1); j++) {
      var cell = [arr[i][j], arr[i][j+1], arr[i+1][j+1], arr[i+1][j]];
      // Convert corner tiles to appropriate representation.
      cell.forEach(function(val, i, cell) {
        if (corners.indexOf(val) !== -1) {
          cell[i] = corner_values[i][val];
        }
      });

      contour_grid[i][j] = cell;
    }
  }
  return contour_grid;
}
function generateContourGrid(arr) {
  // Generate grid for holding values.
  var contour_grid = new Array(arr.length - 1);
  for (var n = 0; n < contour_grid.length; n++) {
    contour_grid[n] = new Array(arr[0].length - 1);
  }
  var corners = [1.1, 1.2, 1.3, 1.4];
  // Specifies the resulting values for the above corner values. The index
  // of the objects in this array corresponds to the proper values for the
  // quadrant of the same index.
  var corner_values = [
    {1.1: 3, 1.2: 0, 1.3: 2, 1.4: 1},
    {1.1: 0, 1.2: 3, 1.3: 1, 1.4: 2},
    {1.1: 3, 1.2: 1, 1.3: 2, 1.4: 0},
    {1.1: 1, 1.2: 3, 1.3: 0, 1.4: 2}
  ];
  for (var i = 0; i < (arr.length - 1); i++) {
    for (var j = 0; j < (arr[0].length - 1); j++) {
      var cell = [arr[i][j], arr[i][j+1], arr[i+1][j+1], arr[i+1][j]];
      // Convert corner tiles to appropriate representation.
      cell.forEach(function(val, i, cell) {
        if (corners.indexOf(val) !== -1) {
          cell[i] = corner_values[i][val];
        }
      });

      contour_grid[i][j] = cell;
    }
  }
  return contour_grid;
}
function generateContourGrid ( arr ) { // Generate grid for holding values. var contour_grid = new Array ( arr . length - 1 ) ; for ( var n = 0 ; n < contour_grid . length ; n ++ ) { contour_grid [ n ] = new Array ( arr [ 0 ] . length - 1 ) ; } var corners = [ 1.1 , 1.2 , 1.3 , 1.4 ] ; // Specifies the resulting values for the above corner values. The index // of the objects in this array corresponds to the proper values for the // quadrant of the same index. var corner_values = [ { 1.1 : 3 , 1.2 : 0 , 1.3 : 2 , 1.4 : 1 } , { 1.1 : 0 , 1.2 : 3 , 1.3 : 1 , 1.4 : 2 } , { 1.1 : 3 , 1.2 : 1 , 1.3 : 2 , 1.4 : 0 } , { 1.1 : 1 , 1.2 : 3 , 1.3 : 0 , 1.4 : 2 } ] ; for ( var i = 0 ; i < ( arr . length - 1 ) ; i ++ ) { for ( var j = 0 ; j < ( arr [ 0 ] . length - 1 ) ; j ++ ) { var cell = [ arr [ i ] [ j ] , arr [ i ] [ j + 1 ] , arr [ i + 1 ] [ j + 1 ] , arr [ i + 1 ] [ j ] ] ; // Convert corner tiles to appropriate representation. cell . forEach ( function ( val , i , cell ) { if ( corners . indexOf ( val ) !== - 1 ) { cell [ i ] = corner_values [ i ] [ val ] ; } } ) ; contour_grid [ i ] [ j ] = cell ; } } return contour_grid ; }
Converts the provided array into its equivalent representation
using cells.
@private
@param {MapTiles} arr -
@param {Array.<Array.<Cell>>} - The converted array.
Converts the provided array into its equivalent representation using cells .