Skip to content

Commit

Permalink
v.perturb: Modify points for all types
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
wenzeslaus committed Feb 23, 2023
1 parent 50815f9 commit 347bc12
Showing 1 changed file with 29 additions and 28 deletions.
57 changes: 29 additions & 28 deletions vector/v.perturb/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down

0 comments on commit 347bc12

Please sign in to comment.