commit eb20bcf0be50ba27b065569a3ac6d8111208ce67
parent 12d74c410cb7d61ec3f80b53d39f47a8c7ca6ad2
Author: Yoann <yoann.b87@voila.fr>
Date: Fri, 21 Oct 2011 11:20:03 +0200
Insertion d'un segment de route avec. Le segment peut s'accrocher à un
nœd edistant ci celui-ci est proche du point d'arrivé et qu'il
n'implique pas une élongation du segment de route.
Pour le moment il n'y a pas de création de nœds sur un segment ni de
gestion des intersections entre segments.
Diffstat:
| M | roads.c | | | 40 | +++++++++++++++++++++++++++++++++++----- |
1 file changed, 35 insertions(+), 5 deletions(-)
diff --git a/roads.c b/roads.c
@@ -162,6 +162,32 @@ roadNodeY* grid_getNearestRoadNode(Vertex *v) {
return nearestNode;
}
+roadNodeY* insertRoadSegment(roadPointY *road, roadNodeY *rnb, roadNodeY *rne, int lag) {
+ int segLength = distBetween(rnb->v, rne->v);
+ float coef = ((float)segLength-lag)/(float)segLength;
+ roadNodeY *nearestNode = NULL;
+ Vertex tmpEnd;
+ tmpEnd.x = rnb->v->x+coef*(rne->v->x - rnb->v->x);
+ tmpEnd.y = rnb->v->y+coef*(rne->v->y - rnb->v->y);
+ fprintf(stderr,"segLength : %d\n",segLength);
+ fprintf(stderr," ostart : %d %d\t oend : %d %d\n",rnb->v->x,rnb->v->y,rne->v->x,rne->v->y);
+ fprintf(stderr," end : %d %d\n",tmpEnd.x,tmpEnd.y);
+ nearestNode = grid_getNearestRoadNode(&tmpEnd);
+
+ fprintf(stderr,"--11\n");
+
+ if(nearestNode != NULL && distBetween(nearestNode->v,rne->v) < lag)
+ rne = nearestNode;
+ fprintf(stderr,"--AA\n");
+ grid_insertRoadNode(rnb);
+ fprintf(stderr,"--BB\n");
+ grid_insertRoadNode(rne);
+ fprintf(stderr,"--CC\n");
+ addRoadNode(road,rne);
+ fprintf(stderr,"--DD\n");
+ return rne;
+}
+
int distBetween(Vertex *v, Vertex *u) {
return sqrt((v->x-u->x)*(v->x-u->x)+(v->y-u->y)*(v->y-u->y));
}
@@ -180,7 +206,7 @@ void carreY() {
roadPointY *roadb = (roadPointY*) malloc(sizeof(roadPointY));
roadNodeY *rn;
Vertex *v;
- //roadNodeY *common = NULL;
+ roadNodeY *lastNode = NULL;
int i;
for(i=0;i<36;i++) {
@@ -205,10 +231,14 @@ void carreY() {
if(i==4) {fprintf(stderr,"x : %d y : %d\n",toX(v),toY(v));}
if(v->x < 800 && v->y < 600) {
fprintf(stderr,"Noed : %d\n",i);
- if(i != 0) if(grid_getNearestRoadNode(v) != NULL)
- rn = grid_getNearestRoadNode(v);
- //rn = rn;
- addRoadNode(roadb,rn);
+ if(i==0) {
+ addRoadNode(roadb,rn);
+ lastNode = rn;
+ }
+ else {
+ insertRoadSegment(roadb,lastNode,rn,10);
+ lastNode = rn;
+ }
}
}