[cairo-commit] roadster/src db.c, 1.30, 1.31 db.h, 1.12, 1.13 main.c, 1.29, 1.30 map.c, 1.48, 1.49 map_draw_cairo.c, 1.24, 1.25 map_draw_gdk.c, 1.22, 1.23 point.c, 1.8, NONE point.h, 1.1, NONE pointstring.c, 1.8, NONE pointstring.h, 1.3, NONE road.c, 1.7, 1.8 road.h, 1.4, 1.5 search_road.c, 1.26, 1.27

Ian McIntosh commit at pdx.freedesktop.org
Fri Sep 30 17:56:22 PDT 2005


Committed by: ian

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

Modified Files:
	db.c db.h main.c map.c map_draw_cairo.c map_draw_gdk.c road.c 
	road.h search_road.c 
Removed Files:
	point.c point.h pointstring.c pointstring.h 
Log Message:
	* src/road.c: Removed alloc/dealloc of road_t.
	* src/point.c:
	* src/point.h:
	* src/pointstring.c:
	* src/pointstring.h: Removed, since road_t now has a basic GArray of mappoint_t objects.
	* src/*.c: Use new road_t format.


Index: db.c
===================================================================
RCS file: /cvs/cairo/roadster/src/db.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- db.c	30 Sep 2005 23:55:31 -0000	1.30
+++ db.c	1 Oct 2005 00:56:20 -0000	1.31
@@ -520,7 +520,7 @@
 	data += sizeof(double);
 }
 
-void db_parse_wkb_linestring(const gint8* data, GPtrArray* pPointsArray, gboolean (*callback_alloc_point)(mappoint_t**))
+void db_parse_wkb_linestring(const gint8* data, GArray* pPointsArray)
 {
 	g_assert(sizeof(double) == 8);	// mysql gives us 8 bytes per point
 
@@ -534,18 +534,20 @@
 	gint nNumPoints = *((gint32*)data);	// NOTE for later: this field doesn't exist for type POINT
 	data += sizeof(gint32);
 
+    g_array_set_size(pPointsArray, nNumPoints);
+
+	gint i = 0;
 	while(nNumPoints > 0) {
-		mappoint_t* pPoint = NULL;
-		if(!callback_alloc_point(&pPoint)) return;
+		mappoint_t* p = &g_array_index(pPointsArray, mappoint_t, i);
 
-		pPoint->fLatitude = *((double*)data);
+		p->fLatitude = *((double*)data);
 		data += sizeof(double);
-		pPoint->fLongitude = *((double*)data);
+		p->fLongitude = *((double*)data);
 		data += sizeof(double);
 
-		g_ptr_array_add(pPointsArray, pPoint);
-
+//		g_array_append_val(pPointsArray, p);
 		nNumPoints--;
+		i++;
 	}
 }
 

Index: db.h
===================================================================
RCS file: /cvs/cairo/roadster/src/db.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- db.h	25 Sep 2005 19:02:37 -0000	1.12
+++ db.h	1 Oct 2005 00:56:20 -0000	1.13
@@ -79,7 +79,8 @@
 gchar* db_make_escaped_string(const gchar* pszString);
 void db_free_escaped_string(gchar* pszString);
 
-void db_parse_wkb_linestring(const gint8* data, GPtrArray* pPointsArray, gboolean (*callback_alloc_point)(mappoint_t**));
+//void db_parse_wkb_linestring(const gint8* data, GPtrArray* pPointsArray, gboolean (*callback_alloc_point)(mappoint_t**));
+void db_parse_wkb_linestring(const gint8* data, GArray* pPointsArray);
 void db_parse_wkb_point(const gint8* data, mappoint_t* pPoint);
 
 void db_enable_keys(void);

Index: main.c
===================================================================
RCS file: /cvs/cairo/roadster/src/main.c,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- main.c	30 Sep 2005 23:55:31 -0000	1.29
+++ main.c	1 Oct 2005 00:56:20 -0000	1.30
@@ -32,7 +32,6 @@
 #include "map.h"
 #include "gpsclient.h"
 #include "scenemanager.h"
-#include "road.h"
 #include "locationset.h"
 #include "location.h"
 #include "search.h"
@@ -138,13 +137,10 @@
 	g_free(pszApplicationDir);
 #endif
 
-	g_print("initializing points\n");
-	point_init();
-	g_print("initializing pointstrings\n");
-	pointstring_init();
-
-	g_print("initializing roads\n");
-	road_init();
+//     g_print("initializing points\n");
+//     point_init();
+//     g_print("initializing pointstrings\n");
+//     pointstring_init();
 
 	g_print("initializing map styles\n");
 	map_style_init();

Index: map.c
===================================================================
RCS file: /cvs/cairo/roadster/src/map.c,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -d -r1.48 -r1.49
--- map.c	30 Sep 2005 05:09:51 -0000	1.48
+++ map.c	1 Oct 2005 00:56:20 -0000	1.49
@@ -603,7 +603,6 @@
 			// aRow[6] is road address left end
 			// aRow[7] is road address right start 
 			// aRow[8] is road address right end
-//			g_print("data: %s, %s, %s, %s, %s\n", aRow[0], aRow[1], aRow[2], aRow[3], aRow[4]);
 
 			// Get layer type that this belongs on
 			gint nTypeID = atoi(aRow[1]);
@@ -612,49 +611,31 @@
 				continue;
 			}
 
-			if(nTypeID == 12) g_warning("(got a 12)");
-
-			road_t* pNewRoad = NULL;
-			road_alloc(&pNewRoad);
+			//road_t* pNewRoad = NULL;
+			//road_alloc(&pNewRoad);
+			road_t* pNewRoad = g_new0(road_t, 1);
 
 			// Build name by adding suffix, if one is present
-			gchar azFullName[100] = "";
-
-			// does it have a name?			
 			if(aRow[3] != NULL && aRow[4] != NULL) {
-				gint nSuffixID = atoi(aRow[4]);
-				const gchar* pszSuffix = road_suffix_itoa(nSuffixID, ROAD_SUFFIX_LENGTH_SHORT);
-				g_snprintf(azFullName, 100, "%s%s%s",
-					aRow[3], (pszSuffix[0] != '\0') ? " " : "", pszSuffix);
+				const gchar* pszSuffix = road_suffix_itoa(atoi(aRow[4]), ROAD_SUFFIX_LENGTH_SHORT);
+				pNewRoad->pszName = g_strdup_printf("%s%s%s", aRow[3], (pszSuffix[0] != '\0') ? " " : "", pszSuffix);
+			}
+			else {
+				pNewRoad->pszName = g_strdup("");	// XXX: could we maybe not do this?
 			}
 			pNewRoad->nAddressLeftStart = atoi(aRow[5]);
 			pNewRoad->nAddressLeftEnd = atoi(aRow[6]);
 			pNewRoad->nAddressRightStart = atoi(aRow[7]);
 			pNewRoad->nAddressRightEnd = atoi(aRow[8]);
 
-			pNewRoad->pszName = g_strdup(azFullName);
-
-#ifdef	ENABLE_RIVER_SMOOTHING
-			if(nTypeID == MAP_OBJECT_TYPE_RIVER) {
-				// XXX: Hacky. Add randomness to river lines
-				GPtrArray* pTempArray = g_ptr_array_new();
-				db_parse_wkb_linestring(aRow[2], pTempArray, point_alloc);
-				map_enhance_linestring(pTempArray, pNewRoad->pPointsArray, point_alloc,
-									   0.00025,      // distance between points
-									   0.000060); 	// randomness
-				g_ptr_array_free(pTempArray, TRUE);
-			}
-			else {
-				db_parse_wkb_linestring(aRow[2], pNewRoad->pPointsArray, point_alloc);
-             }
-#else
-			db_parse_wkb_linestring(aRow[2], pNewRoad->pPointsArray, point_alloc);
-#endif
+			// perhaps let the wkb parser create the array (at the perfect size)
+			pNewRoad->pMapPointsArray = g_array_new(FALSE, FALSE, sizeof(road_t));
+			db_parse_wkb_linestring(aRow[2], pNewRoad->pMapPointsArray);
 
 #ifdef ENABLE_RIVER_TO_LAKE_LOADTIME_HACK	// XXX: combine this and above hack and you get lakes with squiggly edges. whoops. :)
 			if(nTypeID == MAP_OBJECT_TYPE_RIVER) {
-				mappoint_t* pPointA = g_ptr_array_index(pNewRoad->pPointsArray, 0);
-				mappoint_t* pPointB = g_ptr_array_index(pNewRoad->pPointsArray, pNewRoad->pPointsArray->len-1);
+				mappoint_t* pPointA = &g_array_index(pNewRoad->pMapPointsArray, mappoint_t, 0);
+				mappoint_t* pPointB = &g_array_index(pNewRoad->pMapPointsArray, mappoint_t, pNewRoad->pMapPointsArray->len-1);
 
 				if(pPointA->fLatitude == pPointB->fLatitude && pPointA->fLongitude == pPointB->fLongitude) {
 					nTypeID = MAP_OBJECT_TYPE_LAKE;
@@ -675,7 +656,7 @@
 		return TRUE;
 	}
 	else {
-//		g_print(" no rows\n");
+		//g_print(" no rows\n");
 		return FALSE;
 	}	
 }
@@ -769,7 +750,8 @@
 		// Free each
 		for(j = (pLayerData->pRoadsArray->len - 1) ; j>=0 ; j--) {
 			road_t* pRoad = g_ptr_array_remove_index_fast(pLayerData->pRoadsArray, j);
-			road_free(pRoad);
+			g_array_free(pRoad->pMapPointsArray, TRUE);
+			g_free(pRoad);
 		}
 		g_assert(pLayerData->pRoadsArray->len == 0);
 	}
@@ -916,13 +898,13 @@
 	gint iString;
 	for(iString=0 ; iString<pRoadsArray->len ; iString++) {
 		road_t* pRoad = g_ptr_array_index(pRoadsArray, iString);
-		if(pRoad->pPointsArray->len < 2) continue;
+		if(pRoad->pMapPointsArray->len < 2) continue;
 
 		// start on 1 so we can do -1 trick below
 		gint iPoint;
-		for(iPoint=1 ; iPoint<pRoad->pPointsArray->len ; iPoint++) {
-			mappoint_t* pPoint1 = g_ptr_array_index(pRoad->pPointsArray, iPoint-1);
-			mappoint_t* pPoint2 = g_ptr_array_index(pRoad->pPointsArray, iPoint);
+		for(iPoint=1 ; iPoint<pRoad->pMapPointsArray->len ; iPoint++) {
+			mappoint_t* pPoint1 = &g_array_index(pRoad->pMapPointsArray, mappoint_t, iPoint-1);
+			mappoint_t* pPoint2 = &g_array_index(pRoad->pMapPointsArray, mappoint_t, iPoint);
 
 			mappoint_t pointClosest;
 			gdouble fPercentAlongLine;

Index: map_draw_cairo.c
===================================================================
RCS file: /cvs/cairo/roadster/src/map_draw_cairo.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- map_draw_cairo.c	30 Sep 2005 05:09:51 -0000	1.24
+++ map_draw_cairo.c	1 Oct 2005 00:56:20 -0000	1.25
@@ -70,8 +70,8 @@
 //static void map_draw_cairo_locationselection(map_t* pMap, cairo_t *pCairo, rendermetrics_t* pRenderMetrics, GPtrArray* pLocationSelectionArray);
 
 // Draw labels for a single line/polygon
-static void map_draw_cairo_road_label(map_t* pMap, cairo_t *pCairo, maplayerstyle_t* pLayerStyle, rendermetrics_t* pRenderMetrics, GPtrArray* pPointsArray, const gchar* pszLabel);
-static void map_draw_cairo_polygon_label(map_t* pMap, cairo_t *pCairo, maplayerstyle_t* pLayerStyle, rendermetrics_t* pRenderMetrics, GPtrArray* pPointsArray, const gchar* pszLabel);
+static void map_draw_cairo_road_label(map_t* pMap, cairo_t *pCairo, maplayerstyle_t* pLayerStyle, rendermetrics_t* pRenderMetrics, GArray* pMapPointsArray, const gchar* pszLabel);
+static void map_draw_cairo_polygon_label(map_t* pMap, cairo_t *pCairo, maplayerstyle_t* pLayerStyle, rendermetrics_t* pRenderMetrics, GArray* pMapPointsArray, const gchar* pszLabel);
 
 // Draw map extras
 static void map_draw_cairo_map_scale(map_t* pMap, cairo_t *pCairo, rendermetrics_t* pRenderMetrics);
@@ -142,7 +142,7 @@
 		gint i;
 		for(i=pMap->pLayersArray->len-1 ; i>=0 ; i--) {
 			maplayer_t* pLayer = g_ptr_array_index(pMap->pLayersArray, i);
-	
+
 			if(pLayer->nDrawType == MAP_LAYER_RENDERTYPE_LINES) {
 				if(nDrawFlags & DRAWFLAG_GEOMETRY) {
 					map_draw_cairo_layer_roads(pMap, pCairo, pRenderMetrics,
@@ -237,7 +237,7 @@
 
 	if(pLayerStyle->fFontSize == 0) return;
 
-	gchar* pszFontFamily = ROAD_FONT;	// XXX: remove hardcoded font
+	gchar* pszFontFamily = ROAD_FONT;   // XXX: remove hardcoded font
 
 	// set font for whole layer
 	cairo_save(pCairo);
@@ -247,7 +247,7 @@
 	for(i=0 ; i<pRoadsArray->len ; i++) {
 		road_t* pRoad = g_ptr_array_index(pRoadsArray, i);
 		if(pRoad->pszName[0] != '\0') {
-			map_draw_cairo_road_label(pMap, pCairo, pLayerStyle, pRenderMetrics, pRoad->pPointsArray, pRoad->pszName);
+			map_draw_cairo_road_label(pMap, pCairo, pLayerStyle, pRenderMetrics, pRoad->pMapPointsArray, pRoad->pszName);
 		}
 	}
 	cairo_restore(pCairo);
@@ -273,7 +273,7 @@
 	for(i=0 ; i<pRoadsArray->len ; i++) {
 		road_t* pRoad = g_ptr_array_index(pRoadsArray, i);
 		if(pRoad->pszName[0] != '\0') {
-			map_draw_cairo_polygon_label(pMap, pCairo, pLayerStyle, pRenderMetrics, pRoad->pPointsArray, pRoad->pszName);
+			map_draw_cairo_polygon_label(pMap, pCairo, pLayerStyle, pRenderMetrics, pRoad->pMapPointsArray, pRoad->pszName);
 		}
 	}
 	cairo_restore(pCairo);
@@ -331,8 +331,8 @@
 	for(iString=0 ; iString<pRoadsArray->len ; iString++) {
 		pRoad = g_ptr_array_index(pRoadsArray, iString);
 
-		if(pRoad->pPointsArray->len >= 2) {
-			pPoint = g_ptr_array_index(pRoad->pPointsArray, 0);
+		if(pRoad->pMapPointsArray->len >= 2) {
+			pPoint = &g_array_index(pRoad->pMapPointsArray, mappoint_t, 0);
 
 			// go to index 0
 			cairo_move_to(pCairo, 
@@ -340,8 +340,8 @@
 						  pLayerStyle->nPixelOffsetY + SCALE_Y(pRenderMetrics, pPoint->fLatitude));
 
 			// start at index 1 (0 was used above)
-			for(iPoint=1 ; iPoint<pRoad->pPointsArray->len ; iPoint++) {
-				pPoint = g_ptr_array_index(pRoad->pPointsArray, iPoint);//~ g_print("  point (%.05f,%.05f)\n", ScaleX(pPoint->fLongitude), ScaleY(pPoint->fLatitude));
+			for(iPoint=1 ; iPoint<pRoad->pMapPointsArray->len ; iPoint++) {
+				pPoint = &g_array_index(pRoad->pMapPointsArray, mappoint_t, iPoint);//~ g_print("  point (%.05f,%.05f)\n", ScaleX(pPoint->fLongitude), ScaleY(pPoint->fLatitude));
 				cairo_line_to(pCairo, 
 							  pLayerStyle->nPixelOffsetX + SCALE_X(pRenderMetrics, pPoint->fLongitude), 
 							  pLayerStyle->nPixelOffsetY + SCALE_Y(pRenderMetrics, pPoint->fLatitude));
@@ -384,16 +384,16 @@
 	for(iString=0 ; iString<pRoadsArray->len ; iString++) {
 		pRoad = g_ptr_array_index(pRoadsArray, iString);
 
-		if(pRoad->pPointsArray->len >= 3) {
-			pPoint = g_ptr_array_index(pRoad->pPointsArray, 0);
+		if(pRoad->pMapPointsArray->len >= 3) {
+			pPoint = &g_array_index(pRoad->pMapPointsArray, mappoint_t, 0);
 
 			// move to index 0
 			cairo_move_to(pCairo, SCALE_X(pRenderMetrics, pPoint->fLongitude), SCALE_Y(pRenderMetrics, pPoint->fLatitude));
 
 			// start at index 1 (0 was used above)
 			gint iPoint;
-			for(iPoint=1 ; iPoint<pRoad->pPointsArray->len ; iPoint++) {
-				pPoint = g_ptr_array_index(pRoad->pPointsArray, iPoint);				
+			for(iPoint=1 ; iPoint<pRoad->pMapPointsArray->len ; iPoint++) {
+				pPoint = &g_array_index(pRoad->pMapPointsArray, mappoint_t, iPoint);				
 				cairo_line_to(pCairo, SCALE_X(pRenderMetrics, pPoint->fLongitude), SCALE_Y(pRenderMetrics, pPoint->fLatitude));
 			}
 		}
@@ -465,15 +465,15 @@
 //
 // Draw a label along a 2-point line
 //
-static void map_draw_cairo_road_label_one_segment(map_t* pMap, cairo_t *pCairo, maplayerstyle_t* pLayerStyle, rendermetrics_t* pRenderMetrics, GPtrArray* pPointsArray, const gchar* pszLabel)
+static void map_draw_cairo_road_label_one_segment(map_t* pMap, cairo_t *pCairo, maplayerstyle_t* pLayerStyle, rendermetrics_t* pRenderMetrics, GArray* pMapPointsArray, const gchar* pszLabel)
 {
 	// get permission to draw this label
 	if(FALSE == scenemanager_can_draw_label_at(pMap->pSceneManager, pszLabel, NULL, SCENEMANAGER_FLAG_PARTLY_ON_SCREEN)) {
 		return;
 	}
 
-	mappoint_t* pMapPoint1 = g_ptr_array_index(pPointsArray, 0);
-	mappoint_t* pMapPoint2 = g_ptr_array_index(pPointsArray, 1);
+	mappoint_t* pMapPoint1 = &g_array_index(pMapPointsArray, mappoint_t, 0);
+	mappoint_t* pMapPoint2 = &g_array_index(pMapPointsArray, mappoint_t, 1);
 
 	// swap first and second points such that the line goes left-to-right
 	if(pMapPoint2->fLongitude < pMapPoint1->fLongitude) {
@@ -632,17 +632,17 @@
 	return 1;
 }
 
-static void map_draw_cairo_road_label(map_t* pMap, cairo_t *pCairo, maplayerstyle_t* pLayerStyle, rendermetrics_t* pRenderMetrics, GPtrArray* pPointsArray, const gchar* pszLabel)
+static void map_draw_cairo_road_label(map_t* pMap, cairo_t *pCairo, maplayerstyle_t* pLayerStyle, rendermetrics_t* pRenderMetrics, GArray* pMapPointsArray, const gchar* pszLabel)
 {
-	if(pPointsArray->len < 2) return;
+	if(pMapPointsArray->len < 2) return;
 
 	// pass off single segments to a specialized function
-	if(pPointsArray->len == 2) {
-		map_draw_cairo_road_label_one_segment(pMap, pCairo, pLayerStyle, pRenderMetrics, pPointsArray, pszLabel);
+	if(pMapPointsArray->len == 2) {
+		map_draw_cairo_road_label_one_segment(pMap, pCairo, pLayerStyle, pRenderMetrics, pMapPointsArray, pszLabel);
 		return;
 	}
 
-	if(pPointsArray->len > ROAD_MAX_SEGMENTS) {
+	if(pMapPointsArray->len > ROAD_MAX_SEGMENTS) {
 		g_warning("not drawing label for road '%s' with > %d segments.\n", pszLabel, ROAD_MAX_SEGMENTS);
 		return;
 	}
@@ -668,7 +668,7 @@
 	gdouble aSlopes[ROAD_MAX_SEGMENTS];
 
 	mappoint_t* apPoints[ROAD_MAX_SEGMENTS];
-	gint nNumPoints = pPointsArray->len;
+	gint nNumPoints = pMapPointsArray->len;
 
 	mappoint_t* pMapPoint1;
 	mappoint_t* pMapPoint2;
@@ -676,7 +676,7 @@
 	// load point string into an array
 	gint iRead;
 	for(iRead=0 ; iRead<nNumPoints ; iRead++) {
-		apPoints[iRead] = g_ptr_array_index(pPointsArray, iRead);
+		apPoints[iRead] = &g_array_index(pMapPointsArray, mappoint_t, iRead);
 	}
 
 	// measure total line length
@@ -803,7 +803,7 @@
 			// reverse the array
 			gint iRead,iWrite;
 			for(iWrite=0, iRead=nNumPoints-1 ; iRead>= 0 ; iWrite++, iRead--) {
-				apPoints[iWrite] = g_ptr_array_index(pPointsArray, iRead);
+				apPoints[iWrite] = &g_array_index(pMapPointsArray, mappoint_t, iRead);
 			}
 		}
 
@@ -1135,9 +1135,9 @@
 //
 // Draw a single polygon label
 //
-void map_draw_cairo_polygon_label(map_t* pMap, cairo_t *pCairo, maplayerstyle_t* pLayerStyle, rendermetrics_t* pRenderMetrics, GPtrArray* pPointsArray, const gchar* pszLabel)
+void map_draw_cairo_polygon_label(map_t* pMap, cairo_t *pCairo, maplayerstyle_t* pLayerStyle, rendermetrics_t* pRenderMetrics, GArray* pMapPointsArray, const gchar* pszLabel)
 {
-	if(pPointsArray->len < 3) return;
+	if(pMapPointsArray->len < 3) return;
 
 	if(FALSE == scenemanager_can_draw_label_at(pMap->pSceneManager, pszLabel, NULL, SCENEMANAGER_FLAG_PARTLY_ON_SCREEN)) {
 		return;
@@ -1149,8 +1149,8 @@
 	gdouble fMinLon = MAX_LONGITUDE;
 	
 	gint i;
-	for(i=0 ; i<pPointsArray->len ; i++) {
-		mappoint_t* pMapPoint = g_ptr_array_index(pPointsArray, i);
+	for(i=0 ; i<pMapPointsArray->len ; i++) {
+		mappoint_t* pMapPoint = &g_array_index(pMapPointsArray, mappoint_t, i);
 
 		// find polygon bounding box for visibility test below
 		fMaxLat = max(pMapPoint->fLatitude,fMaxLat);
@@ -1683,7 +1683,6 @@
 #endif
 
 #ifdef ROADSTER_DEAD_CODE
-
 /*
 =======
 //
@@ -1798,10 +1797,5 @@
 		cairo_stroke(pCairo);
 	}
 }
-
-
-#if 0	this is the curvy road labeler
-void map_draw_cairo_road_label(...)
-{
 */
 #endif

Index: map_draw_gdk.c
===================================================================
RCS file: /cvs/cairo/roadster/src/map_draw_gdk.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- map_draw_gdk.c	30 Sep 2005 23:55:31 -0000	1.22
+++ map_draw_gdk.c	1 Oct 2005 00:56:20 -0000	1.23
@@ -92,18 +92,18 @@
 			maplayer_t* pLayer = g_ptr_array_index(pMap->pLayersArray, i);
 
 			if(pLayer->nDrawType == MAP_LAYER_RENDERTYPE_FILL) {
-				map_draw_gdk_layer_fill(pMap, pPixmap,	pRenderMetrics,
-										 pLayer->paStylesAtZoomLevels[pRenderMetrics->nZoomLevel-1]);		// style
+				map_draw_gdk_layer_fill(pMap, pPixmap,  pRenderMetrics,
+										 pLayer->paStylesAtZoomLevels[pRenderMetrics->nZoomLevel-1]);       // style
 			}
 			else if(pLayer->nDrawType == MAP_LAYER_RENDERTYPE_LINES) {
-				map_draw_gdk_layer_lines(pMap, pPixmap,	pRenderMetrics,
-										 pMap->apLayerData[pLayer->nDataSource]->pRoadsArray,				// data
-										 pLayer->paStylesAtZoomLevels[pRenderMetrics->nZoomLevel-1]);		// style
+				map_draw_gdk_layer_lines(pMap, pPixmap, pRenderMetrics,
+										 pMap->apLayerData[pLayer->nDataSource]->pRoadsArray,               // data
+										 pLayer->paStylesAtZoomLevels[pRenderMetrics->nZoomLevel-1]);       // style
 			}
 			else if(pLayer->nDrawType == MAP_LAYER_RENDERTYPE_POLYGONS) {
 				map_draw_gdk_layer_polygons(pMap, pPixmap, pRenderMetrics,
 											pMap->apLayerData[pLayer->nDataSource]->pRoadsArray,          // data
-											pLayer->paStylesAtZoomLevels[pRenderMetrics->nZoomLevel-1]); 	// style
+											pLayer->paStylesAtZoomLevels[pRenderMetrics->nZoomLevel-1]);    // style
 			}
 			else if(pLayer->nDrawType == MAP_LAYER_RENDERTYPE_LOCATIONS) {
 				map_draw_gdk_locations(pMap, pPixmap, pRenderMetrics);
@@ -112,7 +112,6 @@
 				//map_draw_gdk_locations(pMap, pPixmap, pRenderMetrics);
 			}
 		}
-//		map_draw_gdk_tracks(pMap, pPixmap, pRenderMetrics);
 	}
 
 	// 3. Labels
@@ -159,17 +158,17 @@
 		gdouble fMaxLon = MIN_LONGITUDE;
 		gdouble fMinLon = MAX_LONGITUDE;
 
-		if(pRoad->pPointsArray->len >= 2) {
+		if(pRoad->pMapPointsArray->len >= 2) {
 			GdkPoint aPoints[MAX_GDK_LINE_SEGMENTS];
 
-			if(pRoad->pPointsArray->len > MAX_GDK_LINE_SEGMENTS) {
+			if(pRoad->pMapPointsArray->len > MAX_GDK_LINE_SEGMENTS) {
 				g_warning("not drawing line with > %d segments\n", MAX_GDK_LINE_SEGMENTS);
 				continue;
 			}
 
 			// XXX: the bounding box should be pre-calculated!!!!
-			for(iPoint=0 ; iPoint<pRoad->pPointsArray->len ; iPoint++) {
-				pPoint = g_ptr_array_index(pRoad->pPointsArray, iPoint);
+			for(iPoint=0 ; iPoint<pRoad->pMapPointsArray->len ; iPoint++) {
+				pPoint = &g_array_index(pRoad->pMapPointsArray, mappoint_t, iPoint);
 
 				// find extents
 				fMaxLat = max(pPoint->fLatitude,fMaxLat);
@@ -191,7 +190,7 @@
 			}
 
 			gdk_draw_polygon(pPixmap, pMap->pTargetWidget->style->fg_gc[GTK_WIDGET_STATE(pMap->pTargetWidget)],
-				TRUE, aPoints, pRoad->pPointsArray->len);
+				TRUE, aPoints, pRoad->pMapPointsArray->len);
    		}
 	}
 	if(pLayerStyle->pGlyphFill != NULL) {
@@ -272,7 +271,7 @@
 	for(iString=0 ; iString<pRoadsArray->len ; iString++) {
 		pRoad = g_ptr_array_index(pRoadsArray, iString);
 
-		if(pRoad->pPointsArray->len > MAX_GDK_LINE_SEGMENTS) {
+		if(pRoad->pMapPointsArray->len > MAX_GDK_LINE_SEGMENTS) {
 			//g_warning("not drawing line with > %d segments\n", MAX_GDK_LINE_SEGMENTS);
 			continue;
 		}
@@ -282,12 +281,12 @@
 		gdouble fMaxLon = MIN_LONGITUDE;
 		gdouble fMinLon = MAX_LONGITUDE;
 
-		if(pRoad->pPointsArray->len >= 2) {
+		if(pRoad->pMapPointsArray->len >= 2) {
 			// Copy all points into this array.  Yuuup this is slow. :)
 			GdkPoint aPoints[MAX_GDK_LINE_SEGMENTS];
 
-			for(iPoint=0 ; iPoint<pRoad->pPointsArray->len ; iPoint++) {
-				pPoint = g_ptr_array_index(pRoad->pPointsArray, iPoint);
+			for(iPoint=0 ; iPoint<pRoad->pMapPointsArray->len ; iPoint++) {
+				pPoint = &g_array_index(pRoad->pMapPointsArray, mappoint_t, iPoint);
 
 				// find extents
 				fMaxLat = max(pPoint->fLatitude,fMaxLat);
@@ -310,7 +309,7 @@
 			    continue;	// not visible
 			}
 
-			gdk_draw_lines(pPixmap, pMap->pTargetWidget->style->fg_gc[GTK_WIDGET_STATE(pMap->pTargetWidget)], aPoints, pRoad->pPointsArray->len);
+			gdk_draw_lines(pPixmap, pMap->pTargetWidget->style->fg_gc[GTK_WIDGET_STATE(pMap->pTargetWidget)], aPoints, pRoad->pMapPointsArray->len);
    		}
 	}
 }
@@ -394,7 +393,7 @@
 // {
 //     gint i;
 //     for(i=0 ; i<pMap->pTracksArray->len ; i++) {
-//         gint hTrack = g_array_index(pMap->pTracksArray, gint, i);
+//         gint hTrack = &g_array_index(pMap->pTracksArray, gint, i);
 //
 //         GdkColor clr;
 //         clr.red = (gint)(0.5 * 65535.0);

--- point.c DELETED ---

--- point.h DELETED ---

--- pointstring.c DELETED ---

--- pointstring.h DELETED ---

Index: road.c
===================================================================
RCS file: /cvs/cairo/roadster/src/road.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- road.c	25 Sep 2005 19:02:37 -0000	1.7
+++ road.c	1 Oct 2005 00:56:20 -0000	1.8
@@ -28,45 +28,6 @@
 #include "map.h"
 #include "gfreelist.h"
 
-GFreeList* g_pRoadFreeList = NULL;
-
-void road_init(void)
-{
-	g_pRoadFreeList = g_free_list_new(sizeof(road_t), 1000);
-}
-
-gboolean road_alloc(road_t** ppReturnRoad)
-{
-	g_return_val_if_fail(ppReturnRoad != NULL, FALSE);
-	g_return_val_if_fail(*ppReturnRoad == NULL, FALSE);	// must be a pointer to a NULL pointer
-
-	road_t* pNew = g_free_list_alloc(g_pRoadFreeList);
-	memset(pNew, 0, sizeof(road_t));
-
-	pNew->pPointsArray = g_ptr_array_new();
-
-	// return it
-	*ppReturnRoad = pNew;
-	return TRUE;
-}
-
-void road_free(road_t* pRoad)
-{
-	g_return_if_fail(pRoad != NULL);
-
-	int i;
-	for(i = (pRoad->pPointsArray->len - 1) ; i>=0 ; i--) {
-		mappoint_t* pPoint = g_ptr_array_remove_index_fast(pRoad->pPointsArray, i);
-		point_free(pPoint);
-	}
-	g_assert(pRoad->pPointsArray->len == 0);
-
-	g_ptr_array_free(pRoad->pPointsArray, TRUE);
-
-	// give back to allocator
-	g_free_list_free(g_pRoadFreeList, pRoad);
-}
-
 struct {
 	gchar* pszLong;
 	gchar* pszShort;

Index: road.h
===================================================================
RCS file: /cvs/cairo/roadster/src/road.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- road.h	30 Sep 2005 05:09:51 -0000	1.4
+++ road.h	1 Oct 2005 00:56:20 -0000	1.5
@@ -25,8 +25,7 @@
 #define _ROAD_H_
 
 typedef struct {
-	GPtrArray* pPointsArray;
-//	maprect_t rcMapBoundingBox;
+	GArray* pMapPointsArray;
 
 	gchar* pszName;
 	gint nAddressLeftStart;
@@ -35,11 +34,6 @@
 	gint nAddressRightEnd;
 } road_t;
 
-void road_init(void);
-gboolean road_alloc(road_t** ppReturnRoad);
-void road_free(road_t* pRoad);
-
-
 // ESuffixLength
 typedef enum {
 	ROAD_SUFFIX_LENGTH_SHORT,

Index: search_road.c
===================================================================
RCS file: /cvs/cairo/roadster/src/search_road.c,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- search_road.c	30 Sep 2005 23:55:31 -0000	1.26
+++ search_road.c	1 Oct 2005 00:56:20 -0000	1.27
@@ -84,7 +84,7 @@
 
 void search_road_on_words(gchar** aWords, gint nWordCount);
 void search_road_on_roadsearch_struct(const roadsearch_t* pRoadSearch);
-void search_road_filter_result(const gchar* pszRoadName, gint nRoadNumber, gint nRoadSuffixID, gint nAddressLeftStart, gint nAddressLeftEnd, gint nAddressRightStart, gint nAddressRightEnd, const gchar* pszCityNameLeft, const gchar* pszCityNameRight, const gchar* pszStateNameLeft, const gchar* pszStateNameRight, const gchar* pszZIPLeft, const gchar* pszZIPRight, pointstring_t* pPointString);
+void search_road_filter_result(const gchar* pszRoadName, gint nRoadNumber, gint nRoadSuffixID, gint nAddressLeftStart, gint nAddressLeftEnd, gint nAddressRightStart, gint nAddressRightEnd, const gchar* pszCityNameLeft, const gchar* pszCityNameRight, const gchar* pszStateNameLeft, const gchar* pszStateNameRight, const gchar* pszZIPLeft, const gchar* pszZIPRight, GArray* pMapPointsArray);
 
 // functions
 
@@ -349,14 +349,13 @@
 
 			nCount++;
 			if(nCount <= SEARCH_RESULT_COUNT_LIMIT) {
-				pointstring_t* pPointString = NULL;
-				pointstring_alloc(&pPointString);
 
-				db_parse_wkb_linestring(aRow[3], pPointString->pPointsArray, point_alloc);
-
-				search_road_filter_result(aRow[1], pRoadSearch->nNumber, atoi(aRow[2]), atoi(aRow[4]), atoi(aRow[5]), atoi(aRow[6]), atoi(aRow[7]), aRow[8], aRow[9], aRow[10], aRow[11], aRow[12], aRow[13], pPointString);
+				GArray* pMapPointsArray = g_array_new(FALSE, FALSE, sizeof(mappoint_t));
+				db_parse_wkb_linestring(aRow[3], pMapPointsArray);
+				search_road_filter_result(aRow[1], pRoadSearch->nNumber, atoi(aRow[2]), atoi(aRow[4]), atoi(aRow[5]), atoi(aRow[6]), atoi(aRow[7]), aRow[8], aRow[9], aRow[10], aRow[11], aRow[12], aRow[13], pMapPointsArray);
 				//g_print("%03d: Road.ID='%s' RoadName.Name='%s', Suffix=%s, L:%s-%s, R:%s-%s\n", nCount, aRow[0], aRow[1], aRow[3], aRow[4], aRow[5], aRow[6], aRow[7]);
-				pointstring_free(pPointString);
+				
+				g_array_free(pMapPointsArray, TRUE);
 			}
 		}
 		db_free_result(pResultSet);
@@ -383,10 +382,10 @@
 
 #define HIGHLIGHT_DISTANCE_FROM_ROAD (0.00012)		// this seems like a good amount...
 
-static void pointstring_walk_percentage(pointstring_t* pPointString, gdouble fPercent, ERoadSide eRoadSide, mappoint_t* pReturnPoint)
+static void mappoint_array_walk_percentage(GArray* pMapPointsArray, gdouble fPercent, ERoadSide eRoadSide, mappoint_t* pReturnPoint)
 {
 	gint i;
-	if(pPointString->pPointsArray->len < 2) {
+	if(pMapPointsArray->len < 2) {
 		g_assert_not_reached();
 	}
 
@@ -394,25 +393,25 @@
 	// count total distance
 	//
 	gfloat fTotalDistance = 0.0;
-	mappoint_t* pPointA = g_ptr_array_index(pPointString->pPointsArray, 0);
+	mappoint_t* pPointA = &g_array_index(pMapPointsArray, mappoint_t, 0);
 	mappoint_t* pPointB;
-	for(i=1 ; i<pPointString->pPointsArray->len ; i++) {
-		pPointB = g_ptr_array_index(pPointString->pPointsArray, 1);
+	for(i=1 ; i<pMapPointsArray->len ; i++) {
+		pPointB = &g_array_index(pMapPointsArray, mappoint_t, 1);
 
 		fTotalDistance += point_calc_distance(pPointA, pPointB);
-		
+
 		pPointA = pPointB;
 	}
 
 	gfloat fTargetDistance = (fTotalDistance * fPercent);
 	gfloat fRemainingDistance = fTargetDistance;
 
-	pPointA = g_ptr_array_index(pPointString->pPointsArray, 0);
-	for(i=1 ; i<pPointString->pPointsArray->len ; i++) {
-		pPointB = g_ptr_array_index(pPointString->pPointsArray, 1);
+	pPointA = &g_array_index(pMapPointsArray, mappoint_t, 0);
+	for(i=1 ; i<pMapPointsArray->len ; i++) {
+		pPointB = &g_array_index(pMapPointsArray, mappoint_t, 1);
 
 		gfloat fLineSegmentDistance = point_calc_distance(pPointA, pPointB);
-		if(fRemainingDistance <= fLineSegmentDistance || (i == pPointString->pPointsArray->len-1)) {
+		if(fRemainingDistance <= fLineSegmentDistance || (i == pMapPointsArray->len-1)) {
 			// this is the line segment we are looking for.
 
 			gfloat fPercentOfLine = (fRemainingDistance / fLineSegmentDistance);
@@ -478,8 +477,7 @@
 		const gchar* pszCityNameLeft, const gchar* pszCityNameRight,
 		const gchar* pszStateNameLeft, const gchar* pszStateNameRight,
 		const gchar* pszZIPLeft, const gchar* pszZIPRight,
-
-		pointstring_t* pPointString)
+		GArray* pMapPointsArray)
 {
 	gint nRoadID = 0;
 	gchar azBuffer[BUFFER_SIZE];
@@ -508,7 +506,7 @@
 
 	if(nRoadNumber == ROADSEARCH_NUMBER_NONE) {
 		// Right in the center
-		pointstring_walk_percentage(pPointString, 0.5, ROADSIDE_CENTER, &ptAddress);
+		mappoint_array_walk_percentage(pMapPointsArray, 0.5, ROADSIDE_CENTER, &ptAddress);
 
 //         gint nStart = min4(nAddressLeftStart, nAddressLeftEnd, nAddressRightStart, nAddressRigtEnd);
 //         gint nEnd = min4(nAddressLeftStart, nAddressLeftEnd, nAddressRightStart, nAddressRigtEnd);
@@ -561,11 +559,11 @@
 				gint nRange = (nAddressLeftEnd - nAddressLeftStart);
 				if(nRange == 0) {
 					// just use road center...?
-					pointstring_walk_percentage(pPointString, 0.5, ROADSIDE_LEFT, &ptAddress);
+					mappoint_array_walk_percentage(pMapPointsArray, 0.5, ROADSIDE_LEFT, &ptAddress);
 				}
 				else {
 					gfloat fPercent = (gfloat)(nRoadNumber - nAddressLeftStart) / (gfloat)nRange;
-					pointstring_walk_percentage(pPointString, fPercent, ROADSIDE_LEFT, &ptAddress);
+					mappoint_array_walk_percentage(pMapPointsArray, fPercent, ROADSIDE_LEFT, &ptAddress);
 				}
 				g_snprintf(azBuffer, BUFFER_SIZE, FORMAT_ROAD_RESULT_WITH_NUMBER, nRoadNumber, pszRoadName, road_suffix_itoa(nRoadSuffixID, ROAD_SUFFIX_LENGTH_LONG), pszCSZLeft);
 				searchwindow_add_result(SEARCH_RESULT_TYPE_ROAD, azBuffer, g_SearchResultTypeRoadGlyph, &ptAddress, ROAD_RESULT_SUGGESTED_ZOOMLEVEL);				
@@ -575,13 +573,13 @@
 				gint nRange = (nAddressLeftStart - nAddressLeftEnd);
 				if(nRange == 0) {
 					// just use road center...?
-					pointstring_walk_percentage(pPointString, 0.5, ROADSIDE_RIGHT, &ptAddress);
+					mappoint_array_walk_percentage(pMapPointsArray, 0.5, ROADSIDE_RIGHT, &ptAddress);
 				}
 				else {
 					gfloat fPercent = (gfloat)(nRoadNumber - nAddressLeftEnd) / (gfloat)nRange;
 
 					// flip percent (23 becomes 77, etc.)
-					pointstring_walk_percentage(pPointString, (100.0 - fPercent), ROADSIDE_RIGHT, &ptAddress);
+					mappoint_array_walk_percentage(pMapPointsArray, (100.0 - fPercent), ROADSIDE_RIGHT, &ptAddress);
 				}
 				g_snprintf(azBuffer, BUFFER_SIZE, FORMAT_ROAD_RESULT_WITH_NUMBER, nRoadNumber, pszRoadName, road_suffix_itoa(nRoadSuffixID, ROAD_SUFFIX_LENGTH_LONG), pszCSZLeft);
 				searchwindow_add_result(SEARCH_RESULT_TYPE_ROAD, azBuffer, g_SearchResultTypeRoadGlyph, &ptAddress, ROAD_RESULT_SUGGESTED_ZOOMLEVEL);
@@ -598,11 +596,11 @@
 				gint nRange = (nAddressRightEnd - nAddressRightStart);
 				if(nRange == 0) {
 					// just use road center...?
-					pointstring_walk_percentage(pPointString, 0.5, ROADSIDE_RIGHT, &ptAddress);
+					mappoint_array_walk_percentage(pMapPointsArray, 0.5, ROADSIDE_RIGHT, &ptAddress);
 				}
 				else {
 					gfloat fPercent = (gfloat)(nRoadNumber - nAddressRightStart) / (gfloat)nRange;
-					pointstring_walk_percentage(pPointString, fPercent, ROADSIDE_RIGHT, &ptAddress);
+					mappoint_array_walk_percentage(pMapPointsArray, fPercent, ROADSIDE_RIGHT, &ptAddress);
 				}
 				g_snprintf(azBuffer, BUFFER_SIZE, FORMAT_ROAD_RESULT_WITH_NUMBER, nRoadNumber, pszRoadName, road_suffix_itoa(nRoadSuffixID, ROAD_SUFFIX_LENGTH_LONG), pszCSZRight);
 				searchwindow_add_result(SEARCH_RESULT_TYPE_ROAD, azBuffer, g_SearchResultTypeRoadGlyph, &ptAddress, ROAD_RESULT_SUGGESTED_ZOOMLEVEL);
@@ -612,13 +610,13 @@
 				gint nRange = (nAddressRightStart - nAddressRightEnd);
 				if(nRange == 0) {
 					// just use road center...?
-					pointstring_walk_percentage(pPointString, 0.5, ROADSIDE_LEFT, &ptAddress);
+					mappoint_array_walk_percentage(pMapPointsArray, 0.5, ROADSIDE_LEFT, &ptAddress);
 				}
 				else {
 					gfloat fPercent = (gfloat)(nRoadNumber - nAddressRightEnd) / (gfloat)nRange;
 
 					// flip percent (23 becomes 77, etc.)
-					pointstring_walk_percentage(pPointString, (100.0 - fPercent), ROADSIDE_LEFT, &ptAddress);
+					mappoint_array_walk_percentage(pMapPointsArray, (100.0 - fPercent), ROADSIDE_LEFT, &ptAddress);
 				}
 				g_snprintf(azBuffer, BUFFER_SIZE, FORMAT_ROAD_RESULT_WITH_NUMBER, nRoadNumber, pszRoadName, road_suffix_itoa(nRoadSuffixID, ROAD_SUFFIX_LENGTH_LONG), pszCSZRight);
 				searchwindow_add_result(SEARCH_RESULT_TYPE_ROAD, azBuffer, g_SearchResultTypeRoadGlyph, &ptAddress, ROAD_RESULT_SUGGESTED_ZOOMLEVEL);



More information about the cairo-commit mailing list