navit 0.5.3-trunk
Loading...
Searching...
No Matches
map.h
Go to the documentation of this file.
1
28#ifndef NAVIT_MAP_H
29#define NAVIT_MAP_H
30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
35#include <stdio.h> // for FILE
36
37#include "attr_type_def.h" // for attr_type
38#include "coord.h" // for coord, coord_rect
39#include "debug.h" // for dbg_assert
40#include "item.h" // for item_range
41#include "item_type_def.h" // for item_type
42#include "point.h" // for point_rect
43#include "projection.h" // for projection
44
45struct attr;
46
47#define WORLD_BOUNDINGBOX_MIN_X -20000000
48#define WORLD_BOUNDINGBOX_MAX_X 20000000
49#define WORLD_BOUNDINGBOX_MIN_Y -20000000
50#define WORLD_BOUNDINGBOX_MAX_Y 20000000
51
65 union {
68 } u;
69 int order;
71};
72
73struct attr_iter;
74struct callback;
87struct map;
93struct map_priv;
110struct map_rect;
117struct map_search;
118
133 char *charset;
135 void (*map_destroy)(struct map_priv *priv);
136 struct map_rect_priv *(*map_rect_new)(
137 struct map_priv *map, struct map_selection *sel);
138 void (*map_rect_destroy)(struct map_rect_priv *mr);
139 struct item *(*map_rect_get_item)(
140 struct map_rect_priv *mr);
141 struct item *(*map_rect_get_item_byid)(
142 struct map_rect_priv *mr, int id_hi,
143 int id_lo);
144 struct map_search_priv *(*map_search_new)(
145 struct map_priv *map, struct item *item, struct attr *search,
146 int partial);
149 struct item *(*map_search_get_item)(struct map_search_priv *ms);
151 struct item *(*map_rect_create_item)(struct map_rect_priv *mr,
152 enum item_type type);
153 int (*map_get_attr)(struct map_priv *priv, enum attr_type type,
154 struct attr *attr);
155 int (*map_set_attr)(struct map_priv *priv, struct attr *attr);
156};
157
170static inline int map_selection_contains_point(struct map_selection *sel, struct coord *c) {
171 struct map_selection *curr = sel;
172 while (curr) {
173 struct coord_rect *r = &curr->u.c_rect;
174 if (c->x >= r->lu.x && c->x <= r->rl.x && c->y <= r->lu.y && c->y >= r->rl.y)
175 return 1;
176 curr = curr->next;
177 }
178 return sel ? 0 : 1;
179}
180
191static inline int map_selection_contains_polyline(struct map_selection *sel, struct coord *c, int count) {
192 int i, x_mi, x_ma, y_mi, y_ma;
193 struct map_selection *curr;
194
195 if (!sel)
196 return 1;
197 for (i = 0; i < count - 1; i++) {
198 x_mi = c[i].x;
199 if (c[i + 1].x < x_mi)
200 x_mi = c[i + 1].x;
201 x_ma = c[i].x;
202 if (c[i + 1].x > x_ma)
203 x_ma = c[i + 1].x;
204 y_mi = c[i].y;
205 if (c[i + 1].y < y_mi)
206 y_mi = c[i + 1].y;
207 y_ma = c[i].y;
208 if (c[i + 1].y > y_ma)
209 y_ma = c[i + 1].y;
210 curr = sel;
211 while (curr) {
212 struct coord_rect *sr = &curr->u.c_rect;
213 if (x_mi <= sr->rl.x && x_ma >= sr->lu.x && y_ma >= sr->rl.y && y_mi <= sr->lu.y)
214 return 1;
215 curr = curr->next;
216 }
217 }
218 return 0;
219}
220
230static inline int map_selection_contains_rect(struct map_selection *sel, struct coord_rect *r) {
231 struct map_selection *curr;
232
233 dbg_assert(r->lu.x <= r->rl.x);
234 dbg_assert(r->lu.y >= r->rl.y);
235
236 if (!sel)
237 return 1;
238 curr = sel;
239 while (curr) {
240 struct coord_rect *sr = &curr->u.c_rect;
241 dbg_assert(sr->lu.x <= sr->rl.x);
242 dbg_assert(sr->lu.y >= sr->rl.y);
243 if (r->lu.x <= sr->rl.x && r->rl.x >= sr->lu.x && r->lu.y >= sr->rl.y && r->rl.y <= sr->lu.y)
244 return 1;
245 curr = curr->next;
246 }
247 return 0;
248}
249
260static inline int map_selection_contains_polygon(struct map_selection *sel, struct coord *c, int count) {
261 struct coord_rect r;
262 int i;
263
264 if (!sel)
265 return 1;
266 if (!count)
267 return 0;
268 r.lu = c[0];
269 r.rl = c[0];
270 for (i = 1; i < count; i++) {
271 if (c[i].x < r.lu.x)
272 r.lu.x = c[i].x;
273 if (c[i].x > r.rl.x)
274 r.rl.x = c[i].x;
275 if (c[i].y < r.rl.y)
276 r.rl.y = c[i].y;
277 if (c[i].y > r.lu.y)
278 r.lu.y = c[i].y;
279 }
280 return map_selection_contains_rect(sel, &r);
281}
282struct map *map_new(struct attr *parent, struct attr **attrs);
283struct map *map_ref(struct map *m);
284void map_unref(struct map *m);
285int map_get_attr(struct map *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter);
286int map_set_attr(struct map *this_, struct attr *attr);
287void map_add_callback(struct map *this_, struct callback *cb);
288void map_remove_callback(struct map *this_, struct callback *cb);
289int map_requires_conversion(struct map *this_);
290char *map_convert_string_tmp(struct map *this_, char *str);
291char *map_convert_string(struct map *this_, char *str);
292char *map_convert_dup(char *str);
293void map_convert_free(char *str);
294enum projection map_projection(struct map *this_);
295void map_set_projection(struct map *this_, enum projection pro);
296void map_destroy(struct map *m);
297struct map_rect *map_rect_new(struct map *m, struct map_selection *sel);
298struct item *map_rect_get_item(struct map_rect *mr);
299struct item *map_rect_get_item_byid(struct map_rect *mr, int id_hi, int id_lo);
300struct item *map_rect_create_item(struct map_rect *mr, enum item_type type_);
301void map_rect_destroy(struct map_rect *mr);
302struct map_search *map_search_new(struct map *m, struct item *item, struct attr *search_attr, int partial);
303struct item *map_search_get_item(struct map_search *this_);
304void map_search_destroy(struct map_search *this_);
305struct map_selection *map_selection_rect_new(struct pcoord *center, int distance, int order);
306struct map_selection *map_selection_dup_pro(struct map_selection *sel, enum projection from, enum projection to);
308void map_selection_destroy(struct map_selection *sel);
310int map_selection_contains_item_range(struct map_selection *sel, int follow, struct item_range *range, int count);
311int map_selection_contains_item(struct map_selection *sel, int follow, enum item_type type);
312int map_priv_is(struct map *map, struct map_priv *priv);
313void map_dump_filedesc(struct map *map, FILE *out);
314void map_dump_file(struct map *map, const char *file);
315void map_dump(struct map *map);
316void map_destroy_do(struct map *m);
317struct maps *maps_new(struct attr *parent, struct attr **attrs);
318/* end of prototypes */
319
320#ifdef __cplusplus
321}
322#endif
323#endif
attr_type
Definition attr_type_def.h:11
#define dbg_assert(expr)
Definition debug.h:65
struct tcoord center
Definition garmin_img.c:2
char type[3]
Definition garmin_img.c:2
item_type
Definition item_type_def.h:8
GList * maps
Definition map.c:29
struct map * map_ref(struct map *m)
void map_unref(struct map *m)
void map_destroy(struct map *m)
Destroys an opened map.
Definition map.c:268
struct item * map_rect_create_item(struct map_rect *mr, enum item_type type_)
Definition map.c:666
void map_destroy_do(struct map *m)
void map_search_destroy(struct map_search *this_)
Destroys a map search struct.
Definition map.c:461
void map_set_projection(struct map *this_, enum projection pro)
Sets the projection of a map.
Definition map.c:258
static int map_selection_contains_rect(struct map_selection *sel, struct coord_rect *r)
Checks if a rectangle is within a map selection.
Definition map.h:230
struct map * map_new(struct attr *parent, struct attr **attrs)
Opens a new map.
Definition map.c:82
static int map_selection_contains_point(struct map_selection *sel, struct coord *c)
Checks if a coordinate is within a map selection.
Definition map.h:170
struct map_selection * map_selection_dup_pro(struct map_selection *sel, enum projection from, enum projection to)
Duplicates a map selection, transforming coordinates.
Definition map.c:506
void map_convert_free(char *str)
Frees the memory allocated for a converted string.
Definition map.c:238
void map_selection_destroy(struct map_selection *sel)
Destroys a map selection.
Definition map.c:540
struct item * map_rect_get_item(struct map_rect *mr)
Gets the next item from a map rect.
Definition map.c:317
char * map_convert_string(struct map *this_, char *str)
Converts a string from a map.
Definition map.c:220
struct map_rect * map_rect_new(struct map *m, struct map_selection *sel)
Creates a new map rect.
Definition map.c:290
char * map_convert_string_tmp(struct map *this_, char *str)
Converts a string from a map into a temporary allocated buffer. Conversion is not performed and origi...
Definition map.c:199
struct map_search * map_search_new(struct map *m, struct item *item, struct attr *search_attr, int partial)
Starts a search on a map.
Definition map.c:404
int map_set_attr(struct map *this_, struct attr *attr)
Sets an attribute of a map.
Definition map.c:144
struct maps * maps_new(struct attr *parent, struct attr **attrs)
Definition maps.c:31
char * map_convert_dup(char *str)
Definition map.c:225
int map_priv_is(struct map *map, struct map_priv *priv)
Checks if a pointer points to the private data of a map.
Definition map.c:638
struct map_selection * map_selection_dup(struct map_selection *sel)
Duplicates a map selection.
Definition map.c:531
struct item * map_search_get_item(struct map_search *this_)
Returns an item from a map search.
Definition map.c:442
struct item * map_rect_get_item_byid(struct map_rect *mr, int id_hi, int id_lo)
Returns the item specified by the ID.
Definition map.c:345
void map_add_callback(struct map *this_, struct callback *cb)
Registers a new callback for attribute-change.
Definition map.c:161
void map_dump_filedesc(struct map *map, FILE *out)
Definition map.c:642
int map_selection_contains_item_range(struct map_selection *sel, int follow, struct item_range *range, int count)
Checks if a selection contains a item range.
Definition map.c:590
static int map_selection_contains_polyline(struct map_selection *sel, struct coord *c, int count)
Checks if a polyline is within a map selection.
Definition map.h:191
enum projection map_projection(struct map *this_)
Returns the projection of a map.
Definition map.c:248
static int map_selection_contains_polygon(struct map_selection *sel, struct coord *c, int count)
Checks if a polygon is within a map selection.
Definition map.h:260
struct map_selection * map_selection_rect_new(struct pcoord *center, int distance, int order)
Creates a new rectangular map selection.
Definition map.c:483
int map_requires_conversion(struct map *this_)
Checks if strings from a map have to be converted.
Definition map.c:185
int map_selection_contains_item(struct map_selection *sel, int follow, enum item_type type)
Checks if a selection contains a item.
Definition map.c:616
int map_selection_contains_item_rect(struct map_selection *sel, struct item *item)
Checks if a selection contains a rectangle containing an item.
Definition map.c:559
void map_dump_file(struct map *map, const char *file)
Definition map.c:651
int map_get_attr(struct map *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
Gets an attribute from a map.
Definition map.c:119
void map_dump(struct map *map)
Definition map.c:661
void map_remove_callback(struct map *this_, struct callback *cb)
Removes a callback from the list of attribute-change callbacks.
Definition map.c:174
void map_rect_destroy(struct map_rect *mr)
Destroys a map rect.
Definition map.c:361
struct navit struct traffic_methods struct attr ** attrs
Definition plugin_def.h:36
static struct pcoord c
Definition popup.c:375
projection
Definition projection.h:23
Definition config_.c:47
Definition attr.h:138
Definition callback.c:27
Definition coord.h:57
struct coord rl
Definition coord.h:59
struct coord lu
Definition coord.h:58
Definition coord.h:33
int y
Definition coord.h:35
int x
Definition coord.h:34
Definition file.h:38
Definition item.h:131
Represents an object on a map.
Definition item.h:122
int id_hi
Definition item.h:124
int id_lo
Definition item.h:125
Holds all functions a map plugin has to implement to be usable.
Definition map.h:131
enum projection pro
Definition map.h:132
void(* map_destroy)(struct map_priv *priv)
Definition map.h:135
void(* map_search_destroy)(struct map_search_priv *ms)
Definition map.h:147
void(* map_rect_destroy)(struct map_rect_priv *mr)
Definition map.h:138
char * charset
Definition map.h:133
int(* map_set_attr)(struct map_priv *priv, struct attr *attr)
Definition map.h:155
int(* map_get_attr)(struct map_priv *priv, enum attr_type type, struct attr *attr)
Definition map.h:153
Represents the map from a single binfile.
Definition binfile.c:103
Implementation-specific map rect data.
Definition binfile.c:135
Definition map.c:62
struct map * m
Definition map.c:63
Represents a search on a map. This struct represents a search on a map; it is created when starting a...
Definition binfile.c:162
Definition map.c:368
struct map * m
Definition map.c:369
struct attr search_attr
Definition map.c:370
Used to select data from a map.
Definition map.h:63
int order
Definition map.h:69
struct map_selection * next
Definition map.h:64
struct point_rect p_rect
Definition map.h:67
union map_selection::@4 u
struct coord_rect c_rect
Definition map.h:66
Definition map.c:55
Definition gpx2navit_txt.h:50
Definition coord.h:51
int y
Definition coord.h:54
int x
Definition coord.h:53
Definition point.h:28
Definition attr.h:134