[cairo-commit] roadster/src db.c, 1.13, 1.14 layers.c, 1.11, 1.12 map.c, 1.23, 1.24 map_draw_cairo.c, 1.9, 1.10

Ian McIntosh commit at pdx.freedesktop.org
Sun Mar 13 11:24:29 PST 2005


Committed by: ian

Update of /cvs/cairo/roadster/src
In directory gabe:/tmp/cvs-serv13461/src

Modified Files:
	db.c layers.c map.c map_draw_cairo.c 
Log Message:
	* src/layers.c: Add warning for bad color strings in layers.xml file.
	* src/map.c: Read map in fixed-location tiles to take advantage of MySQL query caching.
	* src/db.c: Enable query cache in embedded MySQL server.
	* src/map_draw_cairo.c: Allowing drawing of more road labels by permitting label to go over end of road slightly (scenemanager still prevents overlapping with other labels).


Index: db.c
===================================================================
RCS file: /cvs/cairo/roadster/src/db.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- db.c	10 Mar 2005 06:12:03 -0000	1.13
+++ db.c	13 Mar 2005 19:24:27 -0000	1.14
@@ -78,8 +78,8 @@
 		"--skip-innodb",	// don't bother with table types we don't use
 		"--skip-bdb",		//
 
-//                 "--query_cache_type=1",
-//                 "--query_cache_size=40MB",
+                "--query-cache-type=1",
+                "--query-cache-size=40MB",
 
 //		"--flush",			// seems like a good idea since users can quickly kill the app/daemon
 		pszSetDataDirCommand
@@ -423,7 +423,7 @@
 //
 // insert / select state
 //
-// lookup numerical ID of a city by name
+// lookup numerical ID of a state by name
 gboolean db_state_get_id(const gchar* pszName, gint* pnReturnID)
 {
 	gint nReturnID = 0;

Index: layers.c
===================================================================
RCS file: /cvs/cairo/roadster/src/layers.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- layers.c	4 Mar 2005 04:06:35 -0000	1.11
+++ layers.c	13 Mar 2005 19:24:27 -0000	1.12
@@ -78,13 +78,13 @@
 
 }
 
-void 
+void
 layers_deinit(void)
 {
 	xmlCleanupParser();
 }
 
-void 
+void
 layers_reload(void)
 {
 	layers_load_from_file();
@@ -135,7 +135,7 @@
 
 
 /*****************************************************************
- * layers_parse_* functions for parsing the xml 
+ * layers_parse_* functions for parsing the xml
  *****************************************************************/
 static void
 layers_parse_layers(xmlDocPtr doc, xmlNodePtr node)
@@ -307,9 +307,12 @@
 	ptr = value;
 	if (*ptr == '#') ptr++;
 
-	if (strlen(ptr) < 8)
+	if (strlen(ptr) < 8) {
+		g_warning("bad color value found: %s\n", value);
 		return;
+	}
 
+	// Read RGBA hex doubles (eg. "H8") in reverse order
 	ptr += 6;
 	color->m_fAlpha = (gfloat)strtol(ptr, NULL, 16)/255.0;
 	*ptr = '\0';

Index: map.c
===================================================================
RCS file: /cvs/cairo/roadster/src/map.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- map.c	13 Mar 2005 19:11:57 -0000	1.23
+++ map.c	13 Mar 2005 19:24:27 -0000	1.24
@@ -45,13 +45,28 @@
 #include "locationset.h"
 #include "scenemanager.h"
 
+// NOTE on choosing tile size.
+// A) It is arbitrary and could be changed (even at runtime, although this would render useless everything in the cache)
+// B) Too big, and you'll see noticable pauses while scrolling.
+// C) Too small, and you make a ton of extra work with all the extra queries.
+// D) The current value is the result of some casual testing.
+
+// XXX: The names below aren't very clear.
+#define TILE_SHIFT			(1000.0)	// the units we care about (1000ths of a degree)
+#define TILE_MODULUS			(23)		// how many of the above units each tile is on a side
+#define MAP_TILE_WIDTH			(TILE_MODULUS / TILE_SHIFT)	// width and height of a tile, in degrees
+
+//#define ROUND_FLOAT_TO_DECIMAL_PLACE(f,d)	(floor((f)*(d))/(d))	// d should be like 10 or 100.  10 will drop all but the first decimal.
+
 // ADD:
 // 'Mal' - ?
 // 'Trce - Trace
 
 /* Prototypes */
 
+static gboolean map_data_load_tiles(map_t* pMap, maprect_t* pRect);	// ensure tiles
 static gboolean map_data_load(map_t* pMap, maprect_t* pRect);
+
 static void map_data_clear(map_t* pMap);
 void map_get_render_metrics(map_t* pMap, rendermetrics_t* pMetrics);
 
@@ -176,7 +191,8 @@
 	// Load geometry
 	//
 	TIMER_BEGIN(loadtimer, "--- BEGIN ALL DB LOAD");
-	map_data_load(pMap, &(pRenderMetrics->m_rWorldBoundingBox));
+	map_data_clear(pMap);
+	map_data_load_tiles(pMap, &(pRenderMetrics->m_rWorldBoundingBox));
 //	locationset_load_locations(&(pRenderMetrics->m_rWorldBoundingBox));
 	TIMER_END(loadtimer, "--- END ALL DB LOAD");
 
@@ -441,8 +457,78 @@
 }
 */
 
+static gboolean map_data_load_tiles(map_t* pMap, maprect_t* pRect)
+{
+//         g_print("*****\n"
+//                 "rect is (%f,%f)(%f,%f)\n", pRect->m_A.m_fLatitude,pRect->m_A.m_fLongitude, pRect->m_B.m_fLatitude,pRect->m_B.m_fLongitude);
+	gint32 nLatStart = (gint32)(pRect->m_A.m_fLatitude * TILE_SHIFT);
+	// round it DOWN (south)
+	if(pRect->m_A.m_fLatitude > 0) {
+		nLatStart -= (nLatStart % TILE_MODULUS);
+	}
+	else {
+		nLatStart -= (nLatStart % TILE_MODULUS);
+		nLatStart -= TILE_MODULUS;
+	}
+
+	gint32 nLonStart = (gint32)(pRect->m_A.m_fLongitude * TILE_SHIFT);
+	// round it DOWN (west)
+	if(pRect->m_A.m_fLongitude > 0) {
+		nLonStart -= (nLonStart % TILE_MODULUS);
+	}
+	else {
+		nLonStart -= (nLonStart % TILE_MODULUS);
+		nLonStart -= TILE_MODULUS;
+	}
+
+	gint32 nLatEnd = (gint32)(pRect->m_B.m_fLatitude * TILE_SHIFT);
+	// round it UP (north)
+	if(pRect->m_B.m_fLatitude > 0) {
+		nLatEnd -= (nLatEnd % TILE_MODULUS);
+		nLatEnd += TILE_MODULUS;
+	}
+	else {
+		nLatEnd -= (nLatEnd % TILE_MODULUS);
+	}
+
+	gint32 nLonEnd = (gint32)(pRect->m_B.m_fLongitude * TILE_SHIFT);
+	// round it UP (east)
+	if(pRect->m_B.m_fLongitude > 0) {
+		nLonEnd -= (nLonEnd % TILE_MODULUS);
+		nLonEnd += TILE_MODULUS;
+	}
+	else {
+		nLonEnd -= (nLonEnd % TILE_MODULUS);
+	}
+
+	// how many tiles are we loading in each direction?  (nice and safe as integer math...)
+	gint nLatNumTiles = (nLatEnd - nLatStart) / TILE_MODULUS;
+	gint nLonNumTiles = (nLonEnd - nLonStart) / TILE_MODULUS;
+
+	gdouble fLatStart = (gdouble)nLatStart / TILE_SHIFT;
+	gdouble fLonStart = (gdouble)nLonStart / TILE_SHIFT;
+
+	g_assert(fLatStart <= pRect->m_A.m_fLatitude);
+        g_assert(fLonStart <= pRect->m_A.m_fLongitude);
+
+	gint nLat,nLon;
+	for(nLat = 0 ; nLat < nLatNumTiles ; nLat++) {
+		for(nLon = 0 ; nLon < nLonNumTiles ; nLon++) {
+
+			maprect_t rect;
+			rect.m_A.m_fLatitude = fLatStart + ((gdouble)(nLat) * MAP_TILE_WIDTH);
+			rect.m_A.m_fLongitude = fLonStart + ((gdouble)(nLon) * MAP_TILE_WIDTH);
+			rect.m_B.m_fLatitude = fLatStart + ((gdouble)(nLat+1) * MAP_TILE_WIDTH);
+			rect.m_B.m_fLongitude = fLonStart + ((gdouble)(nLon+1) * MAP_TILE_WIDTH);
+
+			map_data_load(pMap, &rect);
+		}
+	}
+}
+
 static gboolean map_data_load(map_t* pMap, maprect_t* pRect)
 {
+	g_return_val_if_fail(pMap != NULL, FALSE);
 	g_return_val_if_fail(pRect != NULL, FALSE);
 
 	db_resultset_t* pResultSet = NULL;
@@ -450,8 +536,6 @@
 
 	gint nZoomLevel = map_get_zoomlevel(pMap);
 
-	map_data_clear(pMap);
-
 	TIMER_BEGIN(mytimer, "BEGIN Geometry LOAD");
 
 	// HACKY: make a list of layer IDs "2,3,5,6"
@@ -481,15 +565,15 @@
 	// Assinging it to a temp variable alleviates that problem.
 
 	gchar* pszSQL;
-	pszSQL = g_strdup_printf("SET @wkb=GeomFromText('Polygon((%f %f,%f %f,%f %f,%f %f,%f %f))')",
-		pRect->m_A.m_fLatitude, pRect->m_A.m_fLongitude, 	// upper left
-		pRect->m_A.m_fLatitude, pRect->m_B.m_fLongitude, 	// upper right
-		pRect->m_B.m_fLatitude, pRect->m_B.m_fLongitude, 	// bottom right
-		pRect->m_B.m_fLatitude, pRect->m_A.m_fLongitude, 	// bottom left
-		pRect->m_A.m_fLatitude, pRect->m_A.m_fLongitude		// upper left again
-		);
-	db_query(pszSQL, NULL);
-	g_free(pszSQL);
+//         pszSQL = g_strdup_printf("SET @wkb=GeomFromText('Polygon((%f %f,%f %f,%f %f,%f %f,%f %f))')",
+//                 pRect->m_A.m_fLatitude, pRect->m_A.m_fLongitude,        // upper left
+//                 pRect->m_A.m_fLatitude, pRect->m_B.m_fLongitude,        // upper right
+//                 pRect->m_B.m_fLatitude, pRect->m_B.m_fLongitude,        // bottom right
+//                 pRect->m_B.m_fLatitude, pRect->m_A.m_fLongitude,        // bottom left
+//                 pRect->m_A.m_fLatitude, pRect->m_A.m_fLongitude         // upper left again
+//                 );
+//         db_query(pszSQL, NULL);
+//         g_free(pszSQL);
 
 	// generate SQL
 	pszSQL = g_strdup_printf(
@@ -497,9 +581,15 @@
 		" FROM Road "
 		" LEFT JOIN RoadName ON (Road.RoadNameID=RoadName.ID)"
 		" WHERE"
-//		" TypeID IN (%s) AND"
-		" MBRIntersects(@wkb, Coordinates)"
+		//" TypeID IN (%s) AND"
+                //" MBRIntersects(@wkb, Coordinates)"
+		" MBRIntersects(GeomFromText('Polygon((%f %f,%f %f,%f %f,%f %f,%f %f))'), Coordinates)"
 //		azLayerNumberList,
+		,pRect->m_A.m_fLatitude, pRect->m_A.m_fLongitude, 	// upper left
+		pRect->m_A.m_fLatitude, pRect->m_B.m_fLongitude, 	// upper right
+		pRect->m_B.m_fLatitude, pRect->m_B.m_fLongitude, 	// bottom right
+		pRect->m_B.m_fLatitude, pRect->m_A.m_fLongitude, 	// bottom left
+		pRect->m_A.m_fLatitude, pRect->m_A.m_fLongitude		// upper left again
 		);
 	//g_print("sql: %s\n", pszSQL);
 

Index: map_draw_cairo.c
===================================================================
RCS file: /cvs/cairo/roadster/src/map_draw_cairo.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- map_draw_cairo.c	10 Mar 2005 11:01:05 -0000	1.9
+++ map_draw_cairo.c	13 Mar 2005 19:24:27 -0000	1.10
@@ -25,6 +25,8 @@
 
 #define RENDERING_THREAD_YIELD	// do nothing
 
+#define	ACCEPTABLE_LINE_LABEL_OVERDRAW_IN_PIXELS_SQUARED (25*25)
+
 #define HACK_AROUND_CAIRO_LINE_CAP_BUG	// enable to ensure roads have rounded caps if the style dictates
 
 #define ROAD_FONT	"Bitstream Vera Sans"
@@ -197,12 +199,13 @@
 	// get total width of string
 	cairo_text_extents_t extents;
 	cairo_text_extents(pCairo, pszLabel, &extents);
+
 	cairo_font_extents_t font_extents;
 	cairo_current_font_extents(pCairo, &font_extents);
 
 	// text too big for line?
 //	if(extents.width > fLineLength) {
-	if((extents.width * extents.width) > fLineLengthSquared) {
+	if((extents.width * extents.width) > (fLineLengthSquared + (ACCEPTABLE_LINE_LABEL_OVERDRAW_IN_PIXELS_SQUARED))) {
 		cairo_restore(pCairo);
 		return;
 	}




More information about the cairo-commit mailing list