63 lines
1.5 KiB
C
63 lines
1.5 KiB
C
#include "conversion.h"
|
|
|
|
|
|
sfVector2f* conversionPoints(Point *tabInitial, uint32_t nbElements, const Coordonnees *const pointCentral, const double echelle)
|
|
{
|
|
sfVector2f *tabConverti = calloc(nbElements, sizeof(*tabConverti));
|
|
|
|
if(tabConverti == NULL)
|
|
{
|
|
fprintf(stderr, "%s\n", strerror(errno));
|
|
return NULL;
|
|
}
|
|
|
|
// Un ratio pour passer des distances (en mètres) à des pixels sur l'écran !
|
|
const double ratio = (1.0e2 * PPCM) / echelle;
|
|
|
|
for(uint32_t i = 0; i < nbElements; i++)
|
|
{
|
|
tabConverti[i].x = (ratio * RAYON * RADIANS(tabInitial[i].pos.lon - pointCentral->lon) + (MAPSIZE * MAPSCALE) / 2.0) * WIDTH / (float)(MAPSIZE * MAPSCALE);
|
|
tabConverti[i].y = (ratio * RAYON * log(tan(PI / 4.0 + RADIANS(pointCentral->lat) / 2.0) / tan(PI / 4.0 + RADIANS(tabInitial[i].pos.lat) / 2.0)) + (MAPSIZE * MAPSCALE) / 2.0) * HEIGHT / (float)(MAPSIZE * MAPSCALE);
|
|
}
|
|
|
|
return tabConverti;
|
|
}
|
|
|
|
|
|
char** conversionDates(Point *tabInitial, uint32_t nbElements)
|
|
{
|
|
char **tabConverti = calloc(nbElements, sizeof(*tabConverti));
|
|
|
|
if(tabConverti == NULL)
|
|
{
|
|
fprintf(stderr, "Allocation impossible (1).\n");
|
|
|
|
return NULL;
|
|
}
|
|
|
|
for(uint32_t i = 0; i < nbElements; i++)
|
|
{
|
|
tabConverti[i] = calloc(DATESIZE, sizeof(*tabConverti[i]));
|
|
|
|
if(tabConverti[i] == NULL)
|
|
{
|
|
fprintf(stderr, "Allocation impossible (2).\n");
|
|
|
|
for(int32_t j = i - 1; j >= 0; j--)
|
|
{
|
|
free(tabConverti[j]);
|
|
tabConverti[j] = NULL;
|
|
}
|
|
|
|
free(tabConverti);
|
|
tabConverti = NULL;
|
|
|
|
return NULL;
|
|
}
|
|
|
|
strcpy(tabConverti[i], ctime(&tabInitial[i].date));
|
|
}
|
|
|
|
return tabConverti;
|
|
}
|