[GRASS-SVN] r54956 - grass/trunk/raster/r.random

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Feb 6 08:12:19 PST 2013


Author: mmetz
Date: 2013-02-06 08:12:19 -0800 (Wed, 06 Feb 2013)
New Revision: 54956

Modified:
   grass/trunk/raster/r.random/random.c
Log:
r.random: fix #1082 and #1874

Modified: grass/trunk/raster/r.random/random.c
===================================================================
--- grass/trunk/raster/r.random/random.c	2013-02-06 15:26:25 UTC (rev 54955)
+++ grass/trunk/raster/r.random/random.c	2013-02-06 16:12:19 UTC (rev 54956)
@@ -31,6 +31,7 @@
     struct line_cats *Cats;
     int cat;
     RASTER_MAP_TYPE type;
+    int do_check;
 
     G_get_window(&window);
 
@@ -130,9 +131,17 @@
 	}
 
 	for (col = 0; col < ncols && nt; col++) {
-	    if ((theState->use_nulls || !is_null_value(theState->buf, col)) &&
-		(!theState->docover || theState->use_nulls || !is_null_value(theState->cover, col)) &&
-		(make_rand() % nc < nt)) {
+	    do_check = 0;
+
+	    if (theState->use_nulls || !is_null_value(theState->buf, col))
+		do_check = 1;
+	    if (do_check && theState->docover == TRUE) {	/* skip no data cover points */
+		if (!theState->use_nulls &&
+		    is_null_value(theState->cover, col))
+		    do_check = 0;
+	    }
+
+	    if (do_check && make_rand() % nc < nt) {
 		nt--;
 		if (is_null_value(theState->buf, col))
 		    cpvalue(&theState->nulls, 0, &theState->buf, col);
@@ -184,14 +193,15 @@
 		    cat++;
 		}
 		G_percent((theState->nRand - nt), theState->nRand, 2);
-
-		nc--;
 	    }
 	    else {
 		set_to_null(&theState->buf, col);
 		if (theState->docover == 1)
 		    set_to_null(&theState->cover, col);
 	    }
+
+	    if (do_check)
+		nc--;
 	}
 
 	while (col < ncols) {



More information about the grass-commit mailing list