//a complete 2D matrix of points plus a value
function squareData( topleft, xindices, yindices, xstep, ystep )
{
  this.data = new Array();
  this.topleft = topleft;
  
  this.xindices = xindices;
  this.yindices = yindices;
  this.long_step = xstep;
  this.lat_step = ystep;
}

squareData.prototype.lng = function( i )
{
  return this.topleft.lng() + this.long_step * i;
}

squareData.prototype.lat = function( i )
{
  return this.topleft.lat() - this.lat_step * i;
}

squareData.prototype.getPoint = function( lat_i, lng_i )
{
  var pt = new GLatLng( this.lat( lat_i ), this.lng( lng_i ) );
  pt.value = this.getValue( lat_i, lng_i );
  pt.lat_i = lat_i;
  pt.lng_i = lng_i;
  return pt;
}

squareData.prototype.getValue = function( lat_i, lng_i )
{
  return this.data[lng_i][lat_i];
}

squareData.prototype.setValue = function( lat_i, lng_i, value )
{
  this.data[lng_i][lat_i] =  value;
}

squareData.prototype.hashCoords = function( lat_i, lng_i )
{
  return this.xindices * lat_i + lng_i;
}

squareData.prototype.getAdjPts = function( lat_i, lng_i )
{
  var adjarray = new Array();
  var offsets = [ -1, 0, +1 ];
  
  for( var yoff in offsets )
  {
    var y = lat_i + offsets[ yoff ];
    
    for( var xoff in offsets )
    {
      var x = lng_i + offsets[ xoff ];
      
      if( y >= 0 && y < this.yindices && x >= 0 && x < this.xindices )
      {
        if( !( x == lng_i && y == lat_i ) ) //not the centre
        {
          adjarray.push( [ y, x ] );
        }
      }
    }
  }
  
  return adjarray;
}

