Browse Source

r.geomorphon: Untangle other min/max code

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.
Denis Ovsienko 4 years ago
parent
commit
d024f3c19e
1 changed files with 8 additions and 5 deletions
  1. 8 5
      raster/r.geomorphon/geom.c

+ 8 - 5
raster/r.geomorphon/geom.c

@@ -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);
     }