Skip to content

Commit

Permalink
r.geomorphon: Untangle other min/max code
Browse files Browse the repository at this point in the history
In exposition() and range() the hard-coded constants delivered the right
result for the data, but it was not immediately obvious, so just
initialize the holding variable with the first value for clarity. In
exposition() rewrite the assignment so it does not look like a standard
maximum expression, because it is not one.
  • Loading branch information
infrastation authored and wenzeslaus committed Oct 28, 2020
1 parent b04b106 commit d024f3c
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions raster/r.geomorphon/geom.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,21 +129,24 @@ float intensity(float *elevation, int pattern_size)
float exposition(float *elevation)
{
/* calculate relative elevation of the central cell against its visibility */
float max = 0.;
float max;
int i;

for (i = 0; i < NUM_DIRS; i++)
max = fabs(elevation[i]) > fabs(max) ? elevation[i] : max;
max = elevation[0];
for (i = 1; i < NUM_DIRS; i++)
if (fabs(elevation[i]) > fabs(max))
max = elevation[i];
return -max;
}

float range(float *elevation)
{
/* calculate relative difference in visible range of central cell */
float max = -90000000000., min = 9000000000000.; /* should be enough */
float max, min;
int i;

for (i = 0; i < NUM_DIRS; i++) {
max = min = elevation[0];
for (i = 1; i < NUM_DIRS; i++) {
max = MAX(elevation[i], max);
min = MIN(elevation[i], min);
}
Expand Down

0 comments on commit d024f3c

Please sign in to comment.