49ba71bbfd
Gère les libérations de mémoire (quasiment toutes !) Termine (presque complètement) la feature des agglos en mode multi-files
133 lines
2.5 KiB
C
133 lines
2.5 KiB
C
#include "others.h"
|
|
|
|
|
|
void printPoint(const Point p)
|
|
{
|
|
printf("Date : %ld\n", p.date);
|
|
printf("Lat : %.16lf\n", p.pos.lat);
|
|
printf("Lon : %.16lf\n\n", p.pos.lon);
|
|
}
|
|
|
|
|
|
void printTabPoint(const Point *p, const uint32_t taille)
|
|
{
|
|
for(uint32_t i = 0; i < taille; ++i)
|
|
printPoint(p[i]);
|
|
}
|
|
|
|
|
|
void printAgglo(Agglomerat const* const a)
|
|
{
|
|
printf("-------------------------------------------\n");
|
|
printf("Nombre de points : %"PRIu32"\n",a->nbPts);
|
|
printf("Moyenne des coordonnees: \n");
|
|
printf("lat:%lf lon:%lf \n", a->moy.lat, a->moy.lon);
|
|
printf("-------------------------------------------\n");
|
|
for (uint32_t i=0; i<a->nbPts; i++)
|
|
{
|
|
printPoint(*a->agglo[i]);
|
|
}
|
|
}
|
|
|
|
|
|
uint32_t getMinAgglo(Agglomerat *agglos, uint32_t nbAgglos)
|
|
{
|
|
uint32_t nbPointsAggloMin = 0;
|
|
|
|
if(nbAgglos > 0)
|
|
{
|
|
nbPointsAggloMin = agglos[0].nbPts;
|
|
|
|
for(uint32_t i = 1; i < nbAgglos; i++)
|
|
{
|
|
if(agglos[i].nbPts < nbPointsAggloMin)
|
|
{
|
|
nbPointsAggloMin = agglos[i].nbPts;
|
|
}
|
|
}
|
|
}
|
|
|
|
return nbPointsAggloMin;
|
|
}
|
|
|
|
|
|
uint32_t getMinAggloGlobal(AgglomeratGlobal *agglos, uint32_t nbAgglos)
|
|
{
|
|
uint32_t nbPointsAggloMin = 0;
|
|
|
|
if(nbAgglos > 0)
|
|
{
|
|
nbPointsAggloMin = agglos[0].nbPtsGlobal;
|
|
|
|
for(uint32_t i = 1; i < nbAgglos; i++)
|
|
{
|
|
if(agglos[i].nbPtsGlobal < nbPointsAggloMin)
|
|
{
|
|
nbPointsAggloMin = agglos[i].nbPtsGlobal;
|
|
}
|
|
}
|
|
}
|
|
|
|
return nbPointsAggloMin;
|
|
}
|
|
|
|
|
|
Point** copieTabPointeurPt(Point **tab, uint32_t taille)
|
|
{
|
|
Point** retour = calloc(taille, sizeof(Point*));
|
|
if(retour == NULL)
|
|
{
|
|
fprintf(stderr, "Copie tableau pointeur point: %s\n", strerror(errno));
|
|
return NULL;
|
|
}
|
|
|
|
for(uint32_t i = 0; i < taille; i++)
|
|
{
|
|
retour[i] = tab[i];
|
|
}
|
|
|
|
return retour;
|
|
}
|
|
|
|
|
|
ErrEnum initStructures(Point *tabPoint, uint32_t tailleP, Agglomerat **tabAgglo, uint32_t *tailleA, Route **tabRoute, uint32_t *tailleR, AgglomeratGlobal **tabAggloGlobal, uint32_t *tailleAGlobal)
|
|
{
|
|
ErrEnum result;
|
|
|
|
// On repère les agglomérats !
|
|
result = repereAgglo(tabPoint, tailleP, tabAgglo, tailleA);
|
|
if(result != SUCCESS)
|
|
{
|
|
free(tabPoint);
|
|
return result;
|
|
}
|
|
|
|
result = repereRoute(tabPoint, tailleP, *tabAgglo, *tailleA, tabRoute, tailleR);
|
|
if(result != SUCCESS)
|
|
{
|
|
free(*tabAgglo);
|
|
free(tabPoint);
|
|
return result;
|
|
}
|
|
|
|
result = pointageSurRoute(*tabAgglo, *tailleA, *tabRoute, *tailleR);
|
|
if(result != SUCCESS)
|
|
{
|
|
free(*tabRoute);
|
|
free(*tabAgglo);
|
|
free(tabPoint);
|
|
return result;
|
|
}
|
|
|
|
result = assemblageGlobalAgglo(*tabAgglo, *tailleA, tabAggloGlobal, tailleAGlobal);
|
|
if(result != SUCCESS)
|
|
{
|
|
free(*tabRoute);
|
|
free(*tabAgglo);
|
|
free(tabPoint);
|
|
return result;
|
|
}
|
|
|
|
return SUCCESS;
|
|
}
|