2 * Hic Est Leo -- Map Simplification
4 * (c) 2022 Martin Mares <mj@ucw.cz>
10 #include <ucw/clists.h>
11 #include <ucw/mempool.h>
20 static struct mempool *simp_pool;
26 struct simp_node_ref {
40 byte raw_coords[sizeof(struct coords)];
47 static void simp_hash_init_data(struct simp_node *s)
49 clist_init(&s->node_refs);
50 clist_init(&s->way_refs);
51 s->can_be_merged = false;
54 #define HASH_NODE struct simp_node
55 #define HASH_PREFIX(x) simp_hash_##x
56 #define HASH_KEY_MEMORY raw_coords
57 #define HASH_KEY_SIZE sizeof(struct coords)
58 #define HASH_WANT_LOOKUP
59 #define HASH_GIVE_INIT_DATA
60 #define HASH_USE_POOL simp_pool
61 #define HASH_TABLE_ALLOC
62 #include <ucw/hashtable.h>
64 static bool simp_can_be_merged(struct simp_node *s)
66 uint num_nodes = clist_size(&s->node_refs);
67 uint num_ways = clist_size(&s->way_refs);
72 msg(L_WARN, "Simplify: Multiple (%u) nodes at [%f, %f]", num_nodes, s->c.x, s->c.y);
82 static void simplify_source(struct data_source *ds)
84 msg(L_INFO, "Simplifying source %s", ds->file);
85 simp_pool = mp_new(65536);
89 CLIST_FOR_EACH(struct osm_way *, w, osm_this->obj_list[OSM_TYPE_WAY])
91 struct osm_node *n_first = (struct osm_node *) osm_ref_head(&w->nodes);
92 struct osm_node *n_last = (struct osm_node *) osm_ref_tail(&w->nodes);
94 OSM_FOR_EACH_BEGIN(struct osm_node *, n, w->nodes)
96 struct coords c = { .x = n->x, .y = n->y };
97 struct simp_node *s = simp_hash_lookup((byte *) &c);
99 struct simp_node_ref *nref = mp_alloc(simp_pool, sizeof(*nref));
101 clist_add_tail(&s->node_refs, &nref->n);
103 struct simp_way_ref *wref = mp_alloc(simp_pool, sizeof(*wref));
105 wref->is_end = (n == n_first || n == n_last);
106 clist_add_tail(&s->way_refs, &wref->n);
111 HASH_FOR_ALL(simp_hash, s)
113 s->can_be_merged = simp_can_be_merged(s);
117 mp_delete(simp_pool);
122 CLIST_FOR_EACH(struct data_source *, ds, map_sources)