Skip to content

Commit

Permalink
r.geomorphon: Fix shape calculations (#1040)
Browse files Browse the repository at this point in the history
The plugin sometimes produced apparently invalid (several orders of
magnitude off or "not a number") values for elongation and width. Add
missing initializations to shape() in geom.c to fix that and the azimuth
calculation as well: when finding a sum of values, initialize the
holding variable with 0; when finding a minimum or a maximum for a set
of values, initialize the holding variable with the first value.
  • Loading branch information
infrastation committed Oct 23, 2020
1 parent 936c83f commit f4bc660
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions raster/r.geomorphon/geom.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ int shape(PATTERN * pattern, int pattern_size, float *azimuth,
int i;
double avg_x = 0, avg_y = 0;
double avg_x_y = 0;
double avg_x_square;
double avg_x_square = 0;
double rx, ry;
double sine, cosine;
double result;
Expand All @@ -242,7 +242,9 @@ int shape(PATTERN * pattern, int pattern_size, float *azimuth,
/* rotation */
sine = sin(result);
cosine = cos(result);
for (i = 0; i < 8; ++i) {
rxmin = rxmax = pattern->x[0] * cosine - pattern->y[0] * sine;
rymin = rymax = pattern->x[0] * sine + pattern->y[0] * cosine;
for (i = 1; i < 8; ++i) {
rx = pattern->x[i] * cosine - pattern->y[i] * sine;
ry = pattern->x[i] * sine + pattern->y[i] * cosine;
rxmin = rx < rxmin ? rx : rxmin;
Expand Down

0 comments on commit f4bc660

Please sign in to comment.