gboolean osm_way_get_name(osm_way *w);
gboolean osm_way_get_ref(osm_way *w);
+/* Cache hash tables */
+static GHashTable *_place_cache;
+
+/*****************************************************************************/
+
gboolean
osm_db_prepare(sqlite3 *db)
{
}
gboolean
-osm_init()
+osm_init(void)
{
+_place_cache=g_hash_table_new(g_direct_hash, g_direct_equal);
return TRUE;
}
+void
+osm_deinit(void)
+{
+g_hash_table_destroy(_place_cache);
+}
+
+/*****************************************************************************/
+
+static osm_place *
+osm_place_cache_lookup(guint32 id)
+{
+return g_hash_table_lookup(_place_cache, GINT_TO_POINTER(id));
+}
+
+static void
+osm_place_cache_add(guint32 id, osm_place *p)
+{
+if (osm_place_cache_lookup(id)==NULL)
+ g_hash_table_insert(_place_cache, GINT_TO_POINTER(id), p);
+}
+
+static void
+osm_place_cache_gc(void)
+{
+g_hash_table_foreach_remove(_place_cache, g_free, NULL);
+}
+
+/*****************************************************************************/
+
/**
* Free way nodes list
*/
return sqrt((x*x)+(y*y));
}
-gboolean distance_point_to_line(gint x, gint y, gint x1, gint y1, gint x2, gint y2, gdouble *d)
+gboolean distance_point_to_line(gdouble x, gdouble y, gdouble x1, gdouble y1, gdouble x2, gdouble y2, gdouble *d)
{
gdouble lm,u,tmp;
gdouble ix,iy;
-lm=magnitude((gdouble)x1,(gdouble)y1,(gdouble)x2,(gdouble)y2);
-
-tmp=(gdouble)((x-x1)*(x2-x1))+((y-y1)*(y2-y1));
+lm=magnitude(x1,y1,x2,y2);
+if (lm==0.0f)
+ return FALSE;
+
+tmp=((x-x1)*(x2-x1))+((y-y1)*(y2-y1));
u=tmp/(lm*lm);
if (u<0.0f || u>1.0f)
return FALSE;
-ix=(gdouble)x1+u*(gdouble)(x2-x1);
-iy=(gdouble)y1+u*(gdouble)(y2-y1);
+ix=x1+u*(x2-x1);
+iy=y1+u*(y2-y1);
-*d=magnitude((gdouble)x,(gdouble)y, ix, iy);
+*d=magnitude(x,y, ix, iy);
return TRUE;
}
if (!f || !t)
return FALSE;
-return distance_point_to_line(lon, lat, f->lon, f->lat, t->lon, t->lat, d);
+return distance_point_to_line((gdouble)lon, (gdouble)lat, (gdouble)f->lon, (gdouble)f->lat, (gdouble)t->lon, (gdouble)t->lat, d);
}
/**