
quadrillage. Le modèle de donnée est pour l'instant trop simple pour stocker toute les informations nécessaires.
107 lines
2.4 KiB
C
107 lines
2.4 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
typedef struct Vertex {
|
|
int x;
|
|
int y;
|
|
} Vertex;
|
|
|
|
typedef Vertex Polygon;
|
|
|
|
void svg_start(int w, int h) {
|
|
printf("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
|
|
printf("<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width=\"%d\" height=\"%d\">", w, h);
|
|
}
|
|
|
|
void svg_end() {
|
|
printf("</svg>");
|
|
}
|
|
|
|
void svg_line(Vertex* a, Vertex* b) {
|
|
printf("<line x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" stroke=\"black\" />", a->x, a->y, b->x, b->y);
|
|
}
|
|
|
|
void roads(Polygon* quartier) {
|
|
quartier = quartier;
|
|
Vertex center = { .x=400, .y=300 };
|
|
svg_line(¢er, &(quartier[0]));
|
|
}
|
|
|
|
/* Fonctions de Yoann suffixée par "Y" */
|
|
typedef struct roadNodeY {
|
|
Vertex *v;
|
|
struct roadNodeY *next;
|
|
struct roadNodeY *previous;
|
|
} roadNodeY;
|
|
|
|
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;
|
|
}
|
|
|
|
// Transforme des coordonnées du plan en coordonées du tableau sur y.
|
|
int toY(int y) {
|
|
return y/maxSubDivision;
|
|
}
|
|
|
|
void carreY() {
|
|
roadNodeY ***nodesGrid = (roadNodeY***) malloc(sizeof(roadNodeY**)*maxSubDivision);
|
|
int i = 0;
|
|
int j = 0;
|
|
int size = 500;
|
|
for(i=0;i<maxSubDivision;i++) {
|
|
nodesGrid[i] = (roadNodeY**) malloc(sizeof(roadNodeY*)*maxSubDivision);
|
|
for(j=0;j<maxSubDivision;j++) {
|
|
roadNodeY *rn = (roadNodeY*) malloc(sizeof(roadNodeY));
|
|
rn->v = (Vertex*) malloc(sizeof(Vertex));
|
|
rn->v->x = i*size/maxSubDivision;
|
|
rn->v->y = j*size/maxSubDivision;
|
|
rn->next = NULL;
|
|
rn->previous = NULL;
|
|
nodesGrid[i][j] = rn;
|
|
}
|
|
}
|
|
|
|
int a,b;
|
|
for(i=0;i<maxSubDivision;i++) {
|
|
for(j=0;j<maxSubDivision;j++) {
|
|
roadNodeY *rn = nodesGrid[i][j];
|
|
while(rn != NULL) {
|
|
for(a=i-1;a<=i+1;a++) {
|
|
for(b=j-1;b<=j+1;b++) {
|
|
if(a >= 0 && a < maxSubDivision && b >= 0 && b < maxSubDivision) {
|
|
svg_line(rn->v,nodesGrid[a][b]->v);
|
|
}
|
|
}
|
|
}
|
|
rn = NULL;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
int main() {
|
|
Vertex points[] = {
|
|
{ .x=10, .y=10 },
|
|
{ .x=790, .y=10 },
|
|
{ .x=600, .y=300 },
|
|
{ .x=790, .y=590 },
|
|
{ .x=10, .y=590 },
|
|
};
|
|
int n = 5;
|
|
svg_start(800,600);
|
|
carreY();
|
|
//int i;
|
|
//for (i = 0; i < n; i++) {
|
|
// svg_line(&(points[i]), &(points[(i+1)%n]));
|
|
// }
|
|
n=n;
|
|
//roads(points);
|
|
points[0] = points[0];
|
|
svg_end();
|
|
return 0;
|
|
}
|