[GRASS-SVN] r31525 - in grass/trunk: include lib/vector lib/vector/Vlib

svn_grass at osgeo.org svn_grass at osgeo.org
Mon May 26 04:26:31 EDT 2008


Author: martinl
Date: 2008-05-26 04:26:31 -0400 (Mon, 26 May 2008)
New Revision: 31525

Modified:
   grass/trunk/include/Vect.h
   grass/trunk/lib/vector/Vlib/remove_duplicates.c
   grass/trunk/lib/vector/vectorlib.dox
Log:
vectlib: Vect_line_check_duplicate() added (derived from Vect_remove_duplicates() [merge devbr6, r31524]

Modified: grass/trunk/include/Vect.h
===================================================================
--- grass/trunk/include/Vect.h	2008-05-26 07:58:34 UTC (rev 31524)
+++ grass/trunk/include/Vect.h	2008-05-26 08:26:31 UTC (rev 31525)
@@ -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/trunk/lib/vector/Vlib/remove_duplicates.c
===================================================================
--- grass/trunk/lib/vector/Vlib/remove_duplicates.c	2008-05-26 07:58:34 UTC (rev 31524)
+++ grass/trunk/lib/vector/Vlib/remove_duplicates.c	2008-05-26 08:26:31 UTC (rev 31525)
@@ -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/trunk/lib/vector/vectorlib.dox
===================================================================
--- grass/trunk/lib/vector/vectorlib.dox	2008-05-26 07:58:34 UTC (rev 31524)
+++ grass/trunk/lib/vector/vectorlib.dox	2008-05-26 08:26:31 UTC (rev 31525)
@@ -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