Browse Source

Moved ilist from vector lib into libgis

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@51796 15284696-431f-4ddb-bdfa-cd5b030d7da7
Soeren Gebbert 13 years ago
parent
commit
8397d5e329

+ 4 - 0
include/defs/gis.h

@@ -307,6 +307,10 @@ void G__call_error_handlers(void);
 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 *,

+ 19 - 0
include/gis.h

@@ -506,6 +506,25 @@ struct Colors
     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 */

+ 7 - 2
include/vect/dig_externs.h

@@ -1,3 +1,9 @@
+#include <grass/gis.h>
+
+#ifndef  DIG___EXTERNS___
+#define DIG___EXTERNS___
+
+
 /*!
   \file include/vect/dig_externs.h
 
@@ -83,8 +89,6 @@ double dig_distance2_point_to_line(double, double, double, double, double,
 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_read_head_ascii(FILE *, struct dig_head *);
 int dig_struct_copy(void *, void *, int);
 int dig_rmcr(char *);
 
+#endif /* DIG__EXTERNS__ */

+ 0 - 21
include/vect/dig_structs.h

@@ -1705,27 +1705,6 @@ struct cat_list
 };
 
 /*!
-  \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

+ 1 - 1
lib/gis/adj_cellhd.c

@@ -295,10 +295,10 @@ void G_adjust_Cell_head3(struct Cell_head *cellhd, int row_flag,
     }
     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 =

+ 57 - 0
lib/gis/ilist.c

@@ -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++;
+}

+ 1 - 1
lib/vector/Vlib/bridges.c

@@ -141,7 +141,7 @@ remove_bridges(struct Map_info *Map, int chtype, struct Map_info *Err)
 	    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");

+ 2 - 2
lib/vector/Vlib/rtree_search.c

@@ -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 @@ int RTreeSearch2(struct RTree *t, struct RTree_Rect *r, struct ilist *list)
 {
     assert(r && t);
 
-    dig_init_list(list);
+    G_init_ilist(list);
 
     return t->search_rect(t, r, add_id_to_list, (void*)list);
 }

+ 1 - 1
lib/vector/Vlib/select.c

@@ -108,7 +108,7 @@ void Vect_spatial_index_del_item(struct spatial_index * si, int id,
 /* 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;
 }
 

+ 8 - 8
lib/vector/Vlib/sindex.c

@@ -240,14 +240,14 @@ Vect_select_lines_by_polygon(struct Map_info *Map, struct line_pnts *Polygon,
 	    }
 	}
 	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 @@ Vect_select_lines_by_polygon(struct Map_info *Map, struct line_pnts *Polygon,
 	    }
 	}
 	if (intersect) {
-	    dig_list_add(List, line);
+	    G_ilist_add(List, line);
 	}
     }
 
@@ -313,23 +313,23 @@ Vect_select_areas_by_polygon(struct Map_info *Map, struct line_pnts *Polygon,
 	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 @@ Vect_select_areas_by_polygon(struct Map_info *Map, struct line_pnts *Polygon,
      * 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);
 

+ 3 - 3
lib/vector/Vlib/snap.c

@@ -43,7 +43,7 @@ typedef struct
 /* 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 @@ Vect_snap_lines(struct Map_info *Map, int type, double thresh,
 	    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);

+ 0 - 29
lib/vector/diglib/list.c

@@ -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 @@ int dig_init_boxlist(struct boxlist *list, int have_boxes)
     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)
 {

+ 1 - 1
lib/vector/diglib/spindex.c

@@ -511,7 +511,7 @@ int dig_spidx_del_isle(struct Plus_head *Plus, int isle)
 /* 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;
 }