#include <string.h>
#include <stdlib.h>
#include <stdio.h>

#include "EspaceF.h"
#include "TestAlloc.h"

EspaceF::EspaceF(int dx,int dy) {
  this->dx = dx;
  this->dy = dy;
  p =(float **) calloc(dy,sizeof(float *));
  testAllocAndExit(p,"new EspaceF(int,int)");
  if ( p ) {
    for ( int i = 0 ; i < dy ; i++ ) {
      p[i] =(float *) calloc(dx+1,sizeof(float));
      testAllocAndExit(p[i],"new EspaceF(int,int)",i); } }
}

EspaceF::~EspaceF(void) {
  for ( int i = 0 ; i < dy ; i++ )
    free(p[i]) ;
  free(p) ;
}

void EspaceF::init(float v) {
  for ( int i = 0 ; i < dy ; i++ )
    for ( int j = 0 ; j < dx+1 ; j++ )
      p[i][j] = v ;
}

float EspaceF::chercheAltitude(int x,int y) {
  return(p[y][x]) ;
}

void EspaceF::sauveAltitude(float altitude,int x,int y) {
  p[y][x] = altitude ;
}

