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

#include "EspaceC3D.h"
#include "coordonn.h"
#include "TestAlloc.h"

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

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

void EspaceC3D::init(coord_3D *c) {
  for ( int i = 0 ; i < dy ; i++ )
    for ( int j = 0 ; j < dx+1 ; j++ )
      p[i][j] = *c ;
}

void EspaceC3D::chercheCoord_3D(int x,int y,coord_3D *c) {
  *c = p[y][x] ;
}

void EspaceC3D::sauveCoord_3D(coord_3D *c,int x,int y) {
  p[y][x] = *c ;
}

