[GRASS-SVN] r31524 - in grass/branches/develbranch_6: include lib/vector lib/vector/Vlib

svn_grass at osgeo.org svn_grass at osgeo.org
Mon May 26 03:58:34 EDT 2008


Author: martinl
Date: 2008-05-26 03:58:34 -0400 (Mon, 26 May 2008)
New Revision: 31524

Modified:
   grass/branches/develbranch_6/include/Vect.h
   grass/branches/develbranch_6/lib/vector/Vlib/remove_duplicates.c
   grass/branches/develbranch_6/lib/vector/vectorlib.dox
Log:
vectlib: Vect_line_check_duplicate() added (derived from Vect_remove_duplicates()

Modified: grass/branches/develbranch_6/include/Vect.h
===================================================================
--- grass/branches/develbranch_6/include/Vect.h	2008-05-26 06:52:09 UTC (rev 31523)
+++ grass/branches/develbranch_6/include/Vect.h	2008-05-26 07:58:34 UTC (rev 31524)
@@ -273,6 +273,8 @@
 int Vect_break_lines_list (struct Map_info *, struct ilist *, int, struct Map_info *, FILE *);
 void Vect_break_polygons ( struct Map_info *, int, struct Map_info *, FILE * );
 void Vect_remove_duplicates ( struct Map_info *, int, struct Map_info *, FILE * );
+int Vect_line_check_duplicate ( const struct line_pnts *,
+				const struct line_pnts *, int );
 void Vect_snap_lines ( struct Map_info *, int, double, struct Map_info *, FILE * );
 void Vect_snap_lines_list (struct Map_info *, struct ilist *, double, struct Map_info *, FILE *);
 void Vect_remove_dangles ( struct Map_info *, int, double, struct Map_info *, FILE * );

Modified: grass/branches/develbranch_6/lib/vector/Vlib/remove_duplicates.c
===================================================================
--- grass/branches/develbranch_6/lib/vector/Vlib/remove_duplicates.c	2008-05-26 06:52:09 UTC (rev 31523)
+++ grass/branches/develbranch_6/lib/vector/Vlib/remove_duplicates.c	2008-05-26 07:58:34 UTC (rev 31524)
@@ -40,12 +40,11 @@
 {
 	struct line_pnts *APoints, *BPoints;
 	struct line_cats *ACats, *BCats, *Cats;
-        int    i, j, k, c, atype, btype, bline;
-	int    nlines, npoints, nbcats_orig;
+        int    i, j, c, atype, btype, bline;
+	int    nlines, nbcats_orig;
 	BOUND_BOX  ABox; 
 	struct ilist *List; 
 	int ndupl;
-	int forw, backw;
 
 	
         APoints = Vect_new_line_struct ();
@@ -84,34 +83,10 @@
 		if ( i == bline ) continue; 
 		
 	        btype = Vect_read_line (Map, BPoints, BCats, bline);
-	
-		/* Check if the lines are identical */
-		if ( APoints->n_points != BPoints->n_points ) continue;
 
-		npoints = APoints->n_points;
-		/* Forward */
-		forw = 1;
-	        for ( k = 0; k <  APoints->n_points; k++ ){ 
-                    if ( APoints->x[k] != BPoints->x[k] ||
-			 APoints->y[k] != BPoints->y[k] ||
-			 (Vect_is_3d(Map) && APoints->z[k] != BPoints->z[k])) {
-                        forw = 0;
-			break;
-		    }	
-		}
-		
-		/* Backward */
-		backw = 1;
-	        for ( k = 0; k <  APoints->n_points; k++ ){ 
-                    if ( APoints->x[k] != BPoints->x[npoints - k - 1] || 
-			 APoints->y[k] != BPoints->y[npoints - k - 1] ||
- 			 (Vect_is_3d(Map) && APoints->z[k] != BPoints->z[npoints - k - 1])) {
-			backw = 0;
-			break;
-		    }	
-		}
-		
-		if ( !forw && !backw ) continue;
+		/* check for duplicates */
+		if (!Vect_line_check_duplicate (APoints, BPoints, Vect_is_3d(Map)))
+		    continue;
 
 		/* Lines area identical -> remove current */
 		if ( Err ) {
@@ -148,3 +123,52 @@
 
 	return;
 }
+
+/*!
+  \brief Check for duplicate lines
+
+  \param APoints first line geometry
+  \param BPoints second line geometry
+
+  \return 1 duplicate
+  \return 0 not duplicate
+*/
+int Vect_line_check_duplicate(const struct line_pnts *APoints,
+			      const struct line_pnts *BPoints, int with_z)
+{
+    int k;
+    int npoints;
+    int forw, backw;
+
+    if ( APoints->n_points != BPoints->n_points )
+	return 0;
+    
+    npoints = APoints->n_points;
+
+    /* Forward */
+    forw = 1;
+    for (k = 0; k < APoints->n_points; k++) { 
+	if (APoints->x[k] != BPoints->x[k] ||
+	    APoints->y[k] != BPoints->y[k] ||
+	    (with_z && APoints->z[k] != BPoints->z[k])) {
+	    forw = 0;
+	    break;
+	}   
+    }
+
+    /* Backward */
+    backw = 1;
+    for (k = 0; k < APoints->n_points; k++) { 
+	if (APoints->x[k] != BPoints->x[npoints - k - 1] || 
+	    APoints->y[k] != BPoints->y[npoints - k - 1] ||
+	    (with_z && APoints->z[k] != BPoints->z[npoints - k - 1])) {
+	    backw = 0;
+	    break;
+	}   
+    }
+ 
+    if (!forw && !backw)
+	return 0;
+    
+    return 1;
+}

Modified: grass/branches/develbranch_6/lib/vector/vectorlib.dox
===================================================================
--- grass/branches/develbranch_6/lib/vector/vectorlib.dox	2008-05-26 06:52:09 UTC (rev 31523)
+++ grass/branches/develbranch_6/lib/vector/vectorlib.dox	2008-05-26 07:58:34 UTC (rev 31524)
@@ -1438,6 +1438,8 @@
 
 \section remove_duplicates Vector remove_duplicates functions
 
+Vect_line_check_duplicate();
+
 Vect_remove_duplicates();
 
 



More information about the grass-commit mailing list