diff --git a/roads.c b/roads.c index 9d45aa2..caf4699 100644 --- a/roads.c +++ b/roads.c @@ -1,12 +1,4 @@ -#include -#include - -typedef struct Vertex { - int x; - int y; -} Vertex; - -typedef Vertex Polygon; +#include "roads.h" void svg_start(int w, int h) { printf(""); @@ -35,42 +27,44 @@ void roads(Polygon* quartier) { * le nombre et les portions de routes auxquelles il appartient. */ -/* Cette structure définie un nœd de route. Le nœd contient la liste de toute les intersections. - */ -typedef struct roadNodeY { - Vertex *v; - short nbIntersec; - struct intersectionY *intersec; -} roadNodeY; - -/* Définition d'une intersection. Permet de savoir quelle route est concernée par cette intersection. - * Elle permet également de changer la navigation por parcourir une nouvelle route. - * */ -typedef struct intersectionY { - roadNodeY roadId; // Premier nœd de la route qui lui sert d'identifiant. - roadNodeY *next; // Nœd de la route juste après l'intersection. - roadNodeY *previous; // Nœd de la route juste avant l'intersection. - int zIndex; // Index sur l'axe z de la route. -} intersectionY; - -typedef struct roadPointY { - struct roadPointY *first; - struct roadPointY *next; - struct roadPointY *previous; - roadNodeY *rn; -} roadPointY; - -const int maxSubDivision = 6; // Nombre de subdivisions max en hauteur et largeur. - // TODO Fusionner les deux fonctions et retourner une paire de valeurs. // Transforme des coordonnées du plan en coordonées du tableau sur x. -int toX(int x) { - return x/maxSubDivision; +int toX(Vertex *v) { + return v->x*(maxSubDivision-1)/quarterSize; } // Transforme des coordonnées du plan en coordonées du tableau sur y. -int toY(int y) { - return y/maxSubDivision; +int toY(Vertex *v) { + return v->x*(maxSubDivision-1)/quarterSize; +} + +void grid_initNodesGrid(int size) { + nodesGrid = (roadNodeY****) malloc(sizeof(roadNodeY***)*size); + int i,j,k; + + maxSubDivision = size; + + for(i=0;iv == NULL) + return 0; + + int i; + for(i=0;iv)][toY(rn->v)][i] = rn; + return 1; + } + + return 0; } void addRoadNode(roadPointY *rp, roadNodeY *rn) { @@ -88,23 +82,24 @@ void addRoadNode(roadPointY *rp, roadNodeY *rn) { rp->next = rpp; } +int distBetween(Vertex *v, Vertex *u) { + //return sqrt((v->x-u->x)*(v->x-u->x)+(v->y-u->y)*(v->y*u->y)); + return v->x+u->x; +} + +roadNodeY** grid_getNearNodes(roadNodeY *rn) { + return nodesGrid[toX(rn->v)][toY(rn->v)]; +} + void carreY() { - roadNodeY ***nodesGrid = (roadNodeY***) malloc(sizeof(roadNodeY**)*maxSubDivision); - int i = 0; - int j = 0; int size = 500; - for(i=0;iy = ((i+1)%3)*(61%(i+1))+100; rn->v = v; if(i == 18) common = rn; + grid_insertRoadNode(rn); addRoadNode(roada,rn); }