/[zanavi_public1]/navit/navit/coord.c
ZANavi

Diff of /navit/navit/coord.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 30 Revision 31
163} 163}
164 164
165int 165int
166coord_rect_overlap(struct coord_rect *r1, struct coord_rect *r2) 166coord_rect_overlap(struct coord_rect *r1, struct coord_rect *r2)
167{ 167{
168 dbg(1,"0x%x,0x%x - 0x%x,0x%x vs 0x%x,0x%x - 0x%x,0x%x\n", r1->lu.x, r1->lu.y, r1->rl.x, r1->rl.y, r2->lu.x, r2->lu.y, r2->rl.x, r2->rl.y); 168 //dbg(1,"0x%x,0x%x - 0x%x,0x%x vs 0x%x,0x%x - 0x%x,0x%x\n", r1->lu.x, r1->lu.y, r1->rl.x, r1->rl.y, r2->lu.x, r2->lu.y, r2->rl.x, r2->rl.y);
169 169
170 // ****** this sometimes causes a crash at startup!! ******** 170 // ****** this sometimes causes a crash at startup!! ********
171 // ****** this sometimes causes a crash at startup!! ******** 171 // ****** this sometimes causes a crash at startup!! ********
172 // dbg_assert(r1->lu.x <= r1->rl.x); 172 // dbg_assert(r1->lu.x <= r1->rl.x);
173 // dbg_assert(r1->lu.y >= r1->rl.y); 173 // dbg_assert(r1->lu.y >= r1->rl.y);
239 int args,ret = 0; 239 int args,ret = 0;
240 struct coord_geo g; 240 struct coord_geo g;
241 struct coord c; 241 struct coord c;
242 enum projection str_pro=projection_none; 242 enum projection str_pro=projection_none;
243 243
244 dbg(1,"enter('%s',%d,%p)\n", c_str, pro, c_ret); 244 //dbg(1,"enter('%s',%d,%p)\n", c_str, pro, c_ret);
245 s=strchr(str,' '); 245 s=strchr(str,' ');
246 co=strchr(str,':'); 246 co=strchr(str,':');
247 if (co && co < s) { 247 if (co && co < s) {
248 proj=malloc(co-str+1); 248 proj=malloc(co-str+1);
249 strncpy(proj, str, co-str); 249 strncpy(proj, str, co-str);
250 proj[co-str]='\0'; 250 proj[co-str]='\0';
251 dbg(1,"projection=%s\n", proj); 251 //dbg(1,"projection=%s\n", proj);
252 str=co+1; 252 str=co+1;
253 s=strchr(str,' '); 253 s=strchr(str,' ');
254 if (!strcmp(proj, "mg")) 254 if (!strcmp(proj, "mg"))
255 str_pro = projection_mg; 255 str_pro = projection_mg;
256 else if (!strcmp(proj, "garmin")) 256 else if (!strcmp(proj, "garmin"))
271 } 271 }
272 if (!strncmp(s, "0x", 2) || !strncmp(s, "-0x", 3)) { 272 if (!strncmp(s, "0x", 2) || !strncmp(s, "-0x", 3)) {
273 args=sscanf(str, "%i %i%n",&c.x, &c.y, &ret); 273 args=sscanf(str, "%i %i%n",&c.x, &c.y, &ret);
274 if (args < 2) 274 if (args < 2)
275 goto out; 275 goto out;
276 dbg(1,"str='%s' x=0x%x y=0x%x c=%d\n", str, c.x, c.y, ret); 276 //dbg(1,"str='%s' x=0x%x y=0x%x c=%d\n", str, c.x, c.y, ret);
277 dbg(1,"rest='%s'\n", str+ret); 277 //dbg(1,"rest='%s'\n", str+ret);
278 278
279 if (str_pro == projection_none) 279 if (str_pro == projection_none)
280 str_pro=projection_mg; 280 str_pro=projection_mg;
281 if (str_pro != pro) { 281 if (str_pro != pro) {
282 transform_to_geo(str_pro, &c, &g); 282 transform_to_geo(str_pro, &c, &g);
284 } 284 }
285 *c_ret=c; 285 *c_ret=c;
286 } else if (*s == 'N' || *s == 'n' || *s == 'S' || *s == 's') { 286 } else if (*s == 'N' || *s == 'n' || *s == 'S' || *s == 's') {
287 double lng, lat; 287 double lng, lat;
288 char ns, ew; 288 char ns, ew;
289 dbg(1,"str='%s'\n", str); 289 //dbg(1,"str='%s'\n", str);
290 args=sscanf(str, "%lf %c %lf %c%n", &lat, &ns, &lng, &ew, &ret); 290 args=sscanf(str, "%lf %c %lf %c%n", &lat, &ns, &lng, &ew, &ret);
291 dbg(1,"args=%d\n", args); 291 //dbg(1,"args=%d\n", args);
292 dbg(1,"lat=%f %c lon=%f %c\n", lat, ns, lng, ew); 292 //dbg(1,"lat=%f %c lon=%f %c\n", lat, ns, lng, ew);
293 if (args < 4) 293 if (args < 4)
294 goto out; 294 goto out;
295 dbg(1,"projection=%d str_pro=%d projection_none=%d\n", pro, str_pro, projection_none); 295 //dbg(1,"projection=%d str_pro=%d projection_none=%d\n", pro, str_pro, projection_none);
296 if (str_pro == projection_none) { 296 if (str_pro == projection_none) {
297 g.lat=floor(lat/100); 297 g.lat=floor(lat/100);
298 lat-=g.lat*100; 298 lat-=g.lat*100;
299 g.lat+=lat/60; 299 g.lat+=lat/60;
300 g.lng=floor(lng/100); 300 g.lng=floor(lng/100);
302 g.lng+=lng/60; 302 g.lng+=lng/60;
303 if (ns == 's' || ns == 'S') 303 if (ns == 's' || ns == 'S')
304 g.lat=-g.lat; 304 g.lat=-g.lat;
305 if (ew == 'w' || ew == 'W') 305 if (ew == 'w' || ew == 'W')
306 g.lng=-g.lng; 306 g.lng=-g.lng;
307 dbg(1,"transform_from_geo(%f,%f)",g.lat,g.lng); 307 //dbg(1,"transform_from_geo(%f,%f)",g.lat,g.lng);
308 transform_from_geo(pro, &g, c_ret); 308 transform_from_geo(pro, &g, c_ret);
309 dbg(1,"result 0x%x,0x%x\n", c_ret->x,c_ret->y); 309 //dbg(1,"result 0x%x,0x%x\n", c_ret->x,c_ret->y);
310 } 310 }
311 dbg(3,"str='%s' x=%f ns=%c y=%f ew=%c c=%d\n", str, lng, ns, lat, ew, ret); 311 //dbg(3,"str='%s' x=%f ns=%c y=%f ew=%c c=%d\n", str, lng, ns, lat, ew, ret);
312 dbg(3,"rest='%s'\n", str+ret); 312 //dbg(3,"rest='%s'\n", str+ret);
313 } else { 313 } else {
314 double lng, lat; 314 double lng, lat;
315 args=sscanf(str, "%lf %lf%n", &lng, &lat, &ret); 315 args=sscanf(str, "%lf %lf%n", &lng, &lat, &ret);
316 if (args < 2) 316 if (args < 2)
317 goto out; 317 goto out;
318 dbg(1,"str='%s' x=%f y=%f c=%d\n", str, lng, lat, ret); 318 //dbg(1,"str='%s' x=%f y=%f c=%d\n", str, lng, lat, ret);
319 dbg(1,"rest='%s'\n", str+ret); 319 //dbg(1,"rest='%s'\n", str+ret);
320 g.lng=lng; 320 g.lng=lng;
321 g.lat=lat; 321 g.lat=lat;
322 transform_from_geo(pro, &g, c_ret); 322 transform_from_geo(pro, &g, c_ret);
323 } 323 }
324 if (debug) 324 //if (debug)
325 printf("rest='%s'\n", str+ret); 325 // printf("rest='%s'\n", str+ret);
326 ret+=str-c_str; 326 ret+=str-c_str;
327 if (debug) { 327 //if (debug) {
328 printf("args=%d\n", args); 328 // printf("args=%d\n", args);
329 printf("ret=%d delta=%d ret_str='%s'\n", ret, GPOINTER_TO_INT(str-c_str), c_str+ret); 329 // printf("ret=%d delta=%d ret_str='%s'\n", ret, GPOINTER_TO_INT(str-c_str), c_str+ret);
330 } 330 //}
331out: 331out:
332 free(proj); 332 free(proj);
333 return ret; 333 return ret;
334} 334}
335 335
450} 450}
451 451
452unsigned int 452unsigned int
453coord_hash(const void *key) 453coord_hash(const void *key)
454{ 454{
455 const struct coord *c=key; 455 const struct coord *c=key;
456 return c->x^c->y; 456 return c->x^c->y;
457} 457}
458 458
459int 459int
460coord_equal(const void *a, const void *b) 460coord_equal(const void *a, const void *b)
461{ 461{
462 const struct coord *c_a=a; 462 const struct coord *c_a=a;
463 const struct coord *c_b=b; 463 const struct coord *c_b=b;
464
464 if (c_a->x == c_b->x && c_a->y == c_b->y) 465 if (c_a->x == c_b->x && c_a->y == c_b->y)
465 return TRUE; 466 {
466 return FALSE; 467 return TRUE;
468 }
469 return FALSE;
467} 470}
468/** @} */ 471/** @} */

Legend:
Removed from v.30  
changed lines
  Added in v.31

   
Visit the ZANavi Wiki