Skip to content

Commit

Permalink
r.geomorphon: Use MIN and MAX properly
Browse files Browse the repository at this point in the history
Define the macros only if not already defined, and use each where it
belongs.
  • Loading branch information
infrastation authored and wenzeslaus committed Oct 28, 2020
1 parent 8df5294 commit b04b106
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
24 changes: 12 additions & 12 deletions raster/r.geomorphon/geom.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ unsigned int ternary_rotate(unsigned int value)
tmp_rev_code += tmp_rev_pattern[i] * power;
power *= 3;
}
code = tmp_code < code ? tmp_code : code;
rev_code = tmp_rev_code < rev_code ? tmp_rev_code : rev_code;
code = MIN(tmp_code, code);
rev_code = MIN(tmp_rev_code, rev_code);
}
return code < rev_code ? code : rev_code;
return MIN(code, rev_code);
}

FORMS determine_form(int num_minus, int num_plus)
Expand Down Expand Up @@ -81,7 +81,7 @@ int determine_binary(int *pattern, int sign)
test = binary;
else
test = (binary << i) | (binary >> (NUM_DIRS - i));
result = (result < test) ? result : test;
result = MIN(result, test);
}
return (int)result;
}
Expand All @@ -98,7 +98,7 @@ int rotate(unsigned char binary)
test = binary;
else
test = (binary << i) | (binary >> (NUM_DIRS - i));
result = (result < test) ? result : test;
result = MIN(result, test);
}
return (int)result;
}
Expand Down Expand Up @@ -144,8 +144,8 @@ float range(float *elevation)
int i;

for (i = 0; i < NUM_DIRS; i++) {
max = elevation[i] > max ? elevation[i] : max;
min = elevation[i] < min ? elevation[i] : min;
max = MAX(elevation[i], max);
min = MIN(elevation[i], min);
}

return max - min;
Expand Down Expand Up @@ -235,15 +235,15 @@ int shape(PATTERN * pattern, int pattern_size, float *azimuth,
for (i = 1; i < NUM_DIRS; ++i) {
rx = pattern->x[i] * cosine - pattern->y[i] * sine;
ry = pattern->x[i] * sine + pattern->y[i] * cosine;
rxmin = rx < rxmin ? rx : rxmin;
rxmax = rx > rxmax ? rx : rxmax;
rymin = ry < rymin ? ry : rymin;
rymax = ry > rymax ? ry : rymax;
rxmin = MIN(rx, rxmin);
rxmax = MAX(rx, rxmax);
rymin = MIN(ry, rymin);
rymax = MAX(ry, rymax);
}
rx = (rxmax - rxmin);
ry = (rymax - rymin);
*elongation = rx > ry ? (float)rx / ry : (float)ry / rx;
*width = rx > ry ? ry : rx;
*width = MIN(rx, ry);

return 0;
}
7 changes: 5 additions & 2 deletions raster/r.geomorphon/local_proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,13 @@
#define DEGREE2RAD(a) ((a)/(180/PI))
#define RAD2DEGREE(a) ((a)*(180/PI))

#undef MIN
#undef MAX
#ifndef MAX
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#endif

#ifndef MIN
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#endif

/* Number of cardinal directions. */
#define NUM_DIRS 8
Expand Down
2 changes: 1 addition & 1 deletion raster/r.geomorphon/multires.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ int pattern_matching(int *pattern)
test = binary;
else
test = (binary << i) | (binary >> (NUM_DIRS - i));
result = (result < test) ? result : test;
result = MIN(result, test);
}
return ((result & source) == source) ? 1 : 0;

Expand Down

0 comments on commit b04b106

Please sign in to comment.