Просмотр исходного кода

r.random: fix https://trac.osgeo.org/grass/ticket/1082 and https://trac.osgeo.org/grass/ticket/1874

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@54956 15284696-431f-4ddb-bdfa-cd5b030d7da7
Markus Metz 12 лет назад
Родитель
Сommit
1bfefa2d0d
1 измененных файлов с 15 добавлено и 5 удалено
  1. 15 5
      raster/r.random/random.c

+ 15 - 5
raster/r.random/random.c

@@ -31,6 +31,7 @@ int execute_random(struct rr_state *theState)
     struct line_cats *Cats;
     int cat;
     RASTER_MAP_TYPE type;
+    int do_check;
 
     G_get_window(&window);
 
@@ -130,9 +131,17 @@ int execute_random(struct rr_state *theState)
 	}
 
 	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 @@ int execute_random(struct rr_state *theState)
 		    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) {