[GRASS-SVN] r51796 - in grass/trunk: include include/defs include/vect lib/gis lib/vector/Vlib lib/vector/diglib

svn_grass at osgeo.org svn_grass at osgeo.org
Sat May 26 10:55:38 EDT 2012


Author: huhabla
Date: 2012-05-26 07:55:37 -0700 (Sat, 26 May 2012)
New Revision: 51796

Added:
   grass/trunk/lib/gis/ilist.c
Modified:
   grass/trunk/include/defs/gis.h
   grass/trunk/include/gis.h
   grass/trunk/include/vect/dig_externs.h
   grass/trunk/include/vect/dig_structs.h
   grass/trunk/lib/gis/adj_cellhd.c
   grass/trunk/lib/vector/Vlib/bridges.c
   grass/trunk/lib/vector/Vlib/rtree_search.c
   grass/trunk/lib/vector/Vlib/select.c
   grass/trunk/lib/vector/Vlib/sindex.c
   grass/trunk/lib/vector/Vlib/snap.c
   grass/trunk/lib/vector/diglib/list.c
   grass/trunk/lib/vector/diglib/spindex.c
Log:
Moved ilist from vector lib into libgis


Modified: grass/trunk/include/defs/gis.h
===================================================================
--- grass/trunk/include/defs/gis.h	2012-05-26 14:50:26 UTC (rev 51795)
+++ grass/trunk/include/defs/gis.h	2012-05-26 14:55:37 UTC (rev 51796)
@@ -307,6 +307,10 @@
 const char *G_home(void);
 const char *G__home(void);
 
+/* ilist.c */
+void G_init_ilist(struct ilist *);
+void G_ilist_add(struct ilist *, int);
+
 /* intersect.c */
 int G_intersect_line_segments(double, double, double, double, double, double,
 			      double, double, double *, double *, double *,

Modified: grass/trunk/include/gis.h
===================================================================
--- grass/trunk/include/gis.h	2012-05-26 14:50:26 UTC (rev 51795)
+++ grass/trunk/include/gis.h	2012-05-26 14:55:37 UTC (rev 51796)
@@ -506,6 +506,25 @@
     int organizing;
 };
 
+/*!
+  \brief List of integers
+*/
+struct ilist
+{
+    /*!
+      \brief Array of values
+    */
+    int *value;
+    /*!
+      \brief Number of values in the list
+    */
+    int n_values;
+    /*!
+      \brief Allocated space for values
+    */
+    int alloc_values;
+};
+
 /*============================== Prototypes ================================*/
 
 /* Since there are so many prototypes for the gis library they are stored */

Modified: grass/trunk/include/vect/dig_externs.h
===================================================================
--- grass/trunk/include/vect/dig_externs.h	2012-05-26 14:50:26 UTC (rev 51795)
+++ grass/trunk/include/vect/dig_externs.h	2012-05-26 14:55:37 UTC (rev 51796)
@@ -1,3 +1,9 @@
+#include <grass/gis.h>
+
+#ifndef  DIG___EXTERNS___
+#define DIG___EXTERNS___
+
+
 /*!
   \file include/vect/dig_externs.h
 
@@ -83,8 +89,6 @@
 int dig_set_distance_to_line_tolerance(double);
 
 /* list.c */
-int dig_init_list(struct ilist *);
-int dig_list_add(struct ilist *, int);
 int dig_init_boxlist(struct boxlist *, int);
 int dig_boxlist_add(struct boxlist *, int, struct bound_box);
 
@@ -324,3 +328,4 @@
 int dig_struct_copy(void *, void *, int);
 int dig_rmcr(char *);
 
+#endif /* DIG__EXTERNS__ */

Modified: grass/trunk/include/vect/dig_structs.h
===================================================================
--- grass/trunk/include/vect/dig_structs.h	2012-05-26 14:50:26 UTC (rev 51795)
+++ grass/trunk/include/vect/dig_structs.h	2012-05-26 14:55:37 UTC (rev 51796)
@@ -1705,27 +1705,6 @@
 };
 
 /*!
-  \brief List of integers
-  
-  \todo To be moved to gislib?
-*/
-struct ilist
-{
-    /*!
-      \brief Array of values
-    */
-    int *value;
-    /*!
-      \brief Number of values in the list
-    */
-    int n_values;
-    /*!
-      \brief Allocated space for values
-    */
-    int alloc_values;
-};
-
-/*!
    \brief List of bounding boxes with id
 */
 struct boxlist

Modified: grass/trunk/lib/gis/adj_cellhd.c
===================================================================
--- grass/trunk/lib/gis/adj_cellhd.c	2012-05-26 14:50:26 UTC (rev 51795)
+++ grass/trunk/lib/gis/adj_cellhd.c	2012-05-26 14:55:37 UTC (rev 51796)
@@ -295,10 +295,10 @@
     }
     if (cellhd->east <= cellhd->west)
 	G_fatal_error(_("East must be larger than West"));
+
     if (cellhd->top <= cellhd->bottom)
 	G_fatal_error(_("Top must be larger than Bottom"));
 
-
     /* compute rows and columns, if not set */
     if (!row_flag) {
 	cellhd->rows =

Added: grass/trunk/lib/gis/ilist.c
===================================================================
--- grass/trunk/lib/gis/ilist.c	                        (rev 0)
+++ grass/trunk/lib/gis/ilist.c	2012-05-26 14:55:37 UTC (rev 51796)
@@ -0,0 +1,57 @@
+/*
+ ****************************************************************************
+ *
+ * MODULE:       gis library 
+ *              
+ * AUTHOR(S):    Original author CERL, probably Dave Gerdes.
+ *               Update to GRASS 5.7 Radim Blazek.
+ *
+ * PURPOSE:      Lower level functions for reading and manipulating integer list
+ *
+ * COPYRIGHT:    (C) 2001 by the GRASS Development Team
+ *
+ *               This program is free software under the GNU General Public
+ *              License (>=v2). Read the file COPYING that comes with GRASS
+ *              for details.
+ *
+ *****************************************************************************/
+#include <stdlib.h>
+#include <grass/gis.h>
+
+/** 
+ * Init an integer list  
+ *
+ * \param list The pointer to an integer list
+ *
+ * */
+void G_init_ilist(struct ilist *list)
+{
+    list->value = NULL;
+    list->n_values = 0;
+    list->alloc_values = 0;
+}
+
+/** 
+ * \brief Add item to ilist
+ *
+ *  This function adds an integer to the list but does not check for duplicates.
+ *  In case reallocation fails, G_fatal_error() will be invoked by the
+ *  allocation function.
+ *
+ * \param ilist The ilist pointer
+ * \param val The value to attach
+ *
+ * */
+void G_ilist_add(struct ilist *list, int val)
+{
+    if (list->n_values == list->alloc_values) {
+	size_t size = (list->n_values + 1000) * sizeof(int);
+	void *p = G_realloc((void *)list->value, size);
+
+	list->value = (int *)p;
+	list->alloc_values = list->n_values + 1000;
+    }
+
+    list->value[list->n_values] = val;
+    list->n_values++;
+}

Modified: grass/trunk/lib/vector/Vlib/bridges.c
===================================================================
--- grass/trunk/lib/vector/Vlib/bridges.c	2012-05-26 14:50:26 UTC (rev 51795)
+++ grass/trunk/lib/vector/Vlib/bridges.c	2012-05-26 14:55:37 UTC (rev 51796)
@@ -141,7 +141,7 @@
 	    if (Vect_val_in_list(CycleList, abs(next_line)))	/* other side -> bridge chain */
 		Vect_list_append(BridgeList, abs(next_line));
 	    else
-		dig_list_add(CycleList, abs(next_line)); /* not in list, can add new line fast */
+		G_ilist_add(CycleList, abs(next_line)); /* not in list, can add new line fast */
 
 	    if (abs(next_line) == abs(current_line)) {
 		G_debug(4, "  dangle -> no bridge");

Modified: grass/trunk/lib/vector/Vlib/rtree_search.c
===================================================================
--- grass/trunk/lib/vector/Vlib/rtree_search.c	2012-05-26 14:50:26 UTC (rev 51795)
+++ grass/trunk/lib/vector/Vlib/rtree_search.c	2012-05-26 14:55:37 UTC (rev 51796)
@@ -22,7 +22,7 @@
 static int add_id_to_list(int id, struct RTree_Rect rect, void *list)
 {
     struct ilist *l = (struct ilist*)list;
-    dig_list_add(l, id);
+    G_ilist_add(l, id);
     return 1;
 }
 
@@ -39,7 +39,7 @@
 {
     assert(r && t);
 
-    dig_init_list(list);
+    G_init_ilist(list);
 
     return t->search_rect(t, r, add_id_to_list, (void*)list);
 }

Modified: grass/trunk/lib/vector/Vlib/select.c
===================================================================
--- grass/trunk/lib/vector/Vlib/select.c	2012-05-26 14:50:26 UTC (rev 51795)
+++ grass/trunk/lib/vector/Vlib/select.c	2012-05-26 14:55:37 UTC (rev 51796)
@@ -108,7 +108,7 @@
 /* This function is called by  RTreeSearch() to add selected item to the list */
 static int _add_item(int id, struct RTree_Rect rect, struct ilist *list)
 {
-    dig_list_add(list, id);
+    G_ilist_add(list, id);
     return 1;
 }
 

Modified: grass/trunk/lib/vector/Vlib/sindex.c
===================================================================
--- grass/trunk/lib/vector/Vlib/sindex.c	2012-05-26 14:50:26 UTC (rev 51795)
+++ grass/trunk/lib/vector/Vlib/sindex.c	2012-05-26 14:55:37 UTC (rev 51796)
@@ -240,14 +240,14 @@
 	    }
 	}
 	if (intersect) {
-	    dig_list_add(List, line);
+	    G_ilist_add(List, line);
 	    continue;
 	}
 
 	/* Check intersections of the line with area/isles boundary */
 	/* Outer boundary */
 	if (Vect_line_check_intersection(LPoints, Polygon, 0)) {
-	    dig_list_add(List, line);
+	    G_ilist_add(List, line);
 	    continue;
 	}
 
@@ -259,7 +259,7 @@
 	    }
 	}
 	if (intersect) {
-	    dig_list_add(List, line);
+	    G_ilist_add(List, line);
 	}
     }
 
@@ -313,23 +313,23 @@
 	G_debug(4, "boundary = %d left = %d right = %d", line, left, right);
 
 	if (left > 0) {
-	    dig_list_add(List, left);
+	    G_ilist_add(List, left);
 	}
 	else if (left < 0) {	/* island */
 	    area = Vect_get_isle_area(Map, abs(left));
 	    G_debug(4, "  left island -> area = %d", area);
 	    if (area > 0)
-		dig_list_add(List, area);
+		G_ilist_add(List, area);
 	}
 
 	if (right > 0) {
-	    dig_list_add(List, right);
+	    G_ilist_add(List, right);
 	}
 	else if (right < 0) {	/* island */
 	    area = Vect_get_isle_area(Map, abs(right));
 	    G_debug(4, "  right island -> area = %d", area);
 	    if (area > 0)
-		dig_list_add(List, area);
+		G_ilist_add(List, area);
 	}
     }
 
@@ -337,7 +337,7 @@
      * we find the area by one polygon point and add it to the list */
     area = Vect_find_area(Map, Polygon->x[0], Polygon->y[0]);
     if (area > 0)
-	dig_list_add(List, area);
+	G_ilist_add(List, area);
 
     G_debug(3, "  %d areas selected by polygon", List->n_values);
 

Modified: grass/trunk/lib/vector/Vlib/snap.c
===================================================================
--- grass/trunk/lib/vector/Vlib/snap.c	2012-05-26 14:50:26 UTC (rev 51795)
+++ grass/trunk/lib/vector/Vlib/snap.c	2012-05-26 14:55:37 UTC (rev 51796)
@@ -43,7 +43,7 @@
 /* This function is called by RTreeSearch() to add selected node/line/area/isle to the list */
 int add_item(int id, struct RTree_Rect rect, struct ilist *list)
 {
-    dig_list_add(list, id);
+    G_ilist_add(list, id);
     return 1;
 }
 
@@ -488,8 +488,8 @@
 	    continue;
 
 	/* no need to check for duplicates:
-	 * use dig_list_add() instead of Vect_list_append() */
-	dig_list_add(List, line);
+	 * use G_ilist_add() instead of Vect_list_append() */
+	G_ilist_add(List, line);
     }
 
     Vect_snap_lines_list(Map, List, thresh, Err);

Modified: grass/trunk/lib/vector/diglib/list.c
===================================================================
--- grass/trunk/lib/vector/diglib/list.c	2012-05-26 14:50:26 UTC (rev 51795)
+++ grass/trunk/lib/vector/diglib/list.c	2012-05-26 14:55:37 UTC (rev 51796)
@@ -18,16 +18,6 @@
 #include <stdlib.h>
 #include <grass/vector.h>
 
-/* Init int_list */
-int dig_init_list(struct ilist *list)
-{
-    list->value = NULL;
-    list->n_values = 0;
-    list->alloc_values = 0;
-
-    return 1;
-}
-
 /* Init box list */
 int dig_init_boxlist(struct boxlist *list, int have_boxes)
 {
@@ -40,25 +30,6 @@
     return 1;
 }
 
-/* Add item to list, does not check for duplicates */
-int dig_list_add(struct ilist *list, int val)
-{
-    if (list->n_values == list->alloc_values) {
-	size_t size = (list->n_values + 1000) * sizeof(int);
-	void *p = G_realloc((void *)list->value, size);
-
-	if (p == NULL)
-	    return 0;
-	list->value = (int *)p;
-	list->alloc_values = list->n_values + 1000;
-    }
-
-    list->value[list->n_values] = val;
-    list->n_values++;
-
-    return 1;
-}
-
 /* Add item to box list, does not check for duplicates */
 int dig_boxlist_add(struct boxlist *list, int id, struct bound_box box)
 {

Modified: grass/trunk/lib/vector/diglib/spindex.c
===================================================================
--- grass/trunk/lib/vector/diglib/spindex.c	2012-05-26 14:50:26 UTC (rev 51795)
+++ grass/trunk/lib/vector/diglib/spindex.c	2012-05-26 14:55:37 UTC (rev 51796)
@@ -511,7 +511,7 @@
 /* This function is called by RTreeSearch() to add selected node/line/area/isle to the list */
 static int _add_item(int id, struct RTree_Rect rect, struct ilist *list)
 {
-    dig_list_add(list, id);
+    G_ilist_add(list, id);
     return 1;
 }
 



More information about the grass-commit mailing list