From 347bc127ccd01673d6600c40c9b4e656660b94a4 Mon Sep 17 00:00:00 2001 From: Vaclav Petras Date: Wed, 22 Feb 2023 20:36:29 -0500 Subject: [PATCH] v.perturb: Modify points for all types This modifies points in all feature types not only type GV_POINT. While this may create unexpected results for some data, separate lines work just fine. The current code just does that always, but this should be opt-in (changes behavior) and it can be marked as experimental or just with a good description of what to expect. I test with lines, but not areas. Speed implications of the for loop not tested. --- vector/v.perturb/main.c | 57 +++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/vector/v.perturb/main.c b/vector/v.perturb/main.c index a27873590a1..8f9ddce713b 100644 --- a/vector/v.perturb/main.c +++ b/vector/v.perturb/main.c @@ -208,7 +208,7 @@ int main(int argc, char **argv) } G_percent(line++, nlines, 4); - if (type & GV_POINT) { + if (true) { if (field != -1 && !Vect_cat_get(Cats, field, NULL)) continue; @@ -218,37 +218,38 @@ int main(int argc, char **argv) myrng(numbers2, 1000, rng, p1, p2); i = 0; } - - G_debug(debuglevel, "x: %f y: %f", Points->x[0], - Points->y[0]); - - /* perturb */ - /* TODO: tends to concentrate in box corners when min is used */ - if (numbers2[i] >= 0) { - if (numbers[i] >= 0) { - G_debug(debuglevel, "deltax: %f", numbers[i] + min); - Points->x[0] += numbers[i++] + min; - } - else { - G_debug(debuglevel, "deltax: %f", numbers[i] - min); - Points->x[0] += numbers[i++] - min; - } - Points->y[0] += numbers2[i++]; - } - else { - if (numbers[i] >= 0) { - G_debug(debuglevel, "deltay: %f", numbers[i] + min); - Points->y[0] += numbers[i++] + min; + for (int point = 0; point < Points->n_points; ++point) { + G_debug(debuglevel, "x: %f y: %f", Points->x[0], + Points->y[point]); + + /* perturb */ + /* TODO: tends to concentrate in box corners when min is used */ + if (numbers2[i] >= 0) { + if (numbers[i] >= 0) { + G_debug(debuglevel, "deltax: %f", numbers[i] + min); + Points->x[point] += numbers[i++] + min; + } + else { + G_debug(debuglevel, "deltax: %f", numbers[i] - min); + Points->x[point] += numbers[i++] - min; + } + Points->y[point] += numbers2[i++]; } else { - G_debug(debuglevel, "deltay: %f", numbers[i] - min); - Points->y[0] += numbers[i++] - min; + if (numbers[i] >= 0) { + G_debug(debuglevel, "deltay: %f", numbers[i] + min); + Points->y[point] += numbers[i++] + min; + } + else { + G_debug(debuglevel, "deltay: %f", numbers[i] - min); + Points->y[point] += numbers[i++] - min; + } + Points->x[point] += numbers2[i++]; } - Points->x[0] += numbers2[i++]; - } - G_debug(debuglevel, "x_pert: %f y_pert: %f", Points->x[0], - Points->y[0]); + G_debug(debuglevel, "x_pert: %f y_pert: %f", Points->x[point], + Points->y[point]); + } } Vect_write_line(&Out, type, Points, Cats);