9 #include "projection.h"
11 * @defgroup coord Coordinate handling functions
18 * @param p Pointer to the coordinate
19 * @returns the coordinate
23 coord_get(unsigned char **p)
25 struct coord *ret=(struct coord *)(*p);
31 coord_new(int x, int y)
33 struct coord *c=g_new(struct coord, 1);
42 coord_destroy(struct coord *c)
48 coord_rect_new(struct coord *lu, struct coord *rl)
50 struct coord_rect *r=g_new(struct coord_rect, 1);
52 g_assert(lu->x <= rl->x);
53 g_assert(lu->y >= rl->y);
63 coord_rect_destroy(struct coord_rect *r)
69 coord_rect_overlap(struct coord_rect *r1, struct coord_rect *r2)
71 g_assert(r1->lu.x <= r1->rl.x);
72 g_assert(r1->lu.y >= r1->rl.y);
73 g_assert(r2->lu.x <= r2->rl.x);
74 g_assert(r2->lu.y >= r2->rl.y);
75 if (r1->lu.x > r2->rl.x)
77 if (r1->rl.x < r2->lu.x)
79 if (r1->lu.y < r2->rl.y)
81 if (r1->rl.y > r2->lu.y)
87 coord_rect_contains(struct coord_rect *r, struct coord *c)
89 g_assert(r->lu.x <= r->rl.x);
90 g_assert(r->lu.y >= r->rl.y);
103 coord_rect_extend(struct coord_rect *r, struct coord *c)
115 /* [Proj:][Ð]DMM.ss[S][S]... N/S [D][D]DMM.ss[S][S]... E/W */
116 /* [Proj:][-][D]D.d[d]... [-][D][D]D.d[d]... */
117 /* [Proj:][-]0xX [-]0xX */
120 coord_parse(const char *c_str, enum projection pro, struct coord *c_ret)
123 char *proj=NULL,*s,*co;
124 const char *str=c_str;
128 enum projection str_pro=projection_none;
130 dbg(1,"enter('%s',%d,%p)\n", c_str, pro, c_ret);
134 proj=malloc(co-str+1);
135 strncpy(proj, str, co-str);
137 dbg(1,"projection=%s\n", proj);
144 if (!strncmp(str, "0x", 2) || !strncmp(str,"-0x", 3)) {
145 args=sscanf(str, "%i %i%n",&c.x, &c.y, &ret);
148 dbg(1,"str='%s' x=0x%x y=0x%x c=%d\n", str, c.x, c.y, ret);
149 dbg(1,"rest='%s'\n", str+ret);
151 if (str_pro == projection_none)
152 str_pro=projection_mg;
153 if (str_pro == projection_mg) {
158 } else if (*s == 'N' || *s == 'n' || *s == 'S' || *s == 's') {
159 dbg(1,"str='%s'\n", str);
162 args=sscanf(str, "%lf %c %lf %c%n", &lat, &ns, &lng, &ew, &ret);
165 if (str_pro == projection_none) {
166 g.lat=floor(lat/100);
169 g.lng=floor(lng/100);
172 transform_from_geo(pro, &g, c_ret);
175 printf("str='%s' x=%f ns=%c y=%f ew=%c c=%d\n", str, lng, ns, lat, ew, ret);
176 printf("rest='%s'\n", str+ret);
180 args=sscanf(str, "%lf %lf%n", &lng, &lat, &ret);
183 printf("str='%s' x=%f y=%f c=%d\n", str, lng, lat, ret);
184 printf("rest='%s'\n", str+ret);
187 printf("rest='%s'\n", str+ret);
190 printf("args=%d\n", args);
191 printf("ret=%d delta=%d ret_str='%s'\n", ret, str-c_str, c_str+ret);