Skip to content

Commit

Permalink
Use named constants rater than 0-2 (#8074)
Browse files Browse the repository at this point in the history
We have an angle_type that indicates what angle we should use along a contour for label placement or decorated symbol placement. Hard to remember what 0-2 means so this PR just introduces named enums.  No change to any code or behavior (yet).
  • Loading branch information
PaulWessel authored Nov 24, 2023
1 parent 33359fb commit 9f2236e
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 28 deletions.
7 changes: 7 additions & 0 deletions src/gmt_contour.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ enum GMT_enum_contline {
GMT_CONTOUR_XLINE, /* Contour labels where crossing straight lines (via key points) */
GMT_CONTOUR_XCURVE}; /* Contour labels where crossing arbitrary lines (via file) */

/*! Various settings for angles related to contours and decorated lines */
enum GMT_enum_contangle {
GMT_ANGLE_LINE_PARALLEL = 0, /* Angles follows the line locally */
GMT_ANGLE_LINE_NORMAL, /* Angles is normal to the line locally */
GMT_ANGLE_LINE_FIXED}; /* Angle is fixed regardless of line direction */


/*! Various settings for quoted line/contour label types */
enum GMT_enum_label {
GMT_LABEL_IS_NONE = 0, /* No contour/line crossing */
Expand Down
2 changes: 1 addition & 1 deletion src/gmt_decorate.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct GMT_DECORATE {
unsigned int nx; /* Number of crossovers at any time */
unsigned int f_n; /* Number of such points */
unsigned int nudge_flag; /* 0 if off, 1 if nudging relative to x/y axis, 2 if following local line coordinate system */
unsigned int angle_type; /* 0 = line-parallel, 1 = line-normal, 2 = fixed angle */
unsigned int angle_type; /* 0 = line-parallel (GMT_ANGLE_LINE_PARALLEL), 1 = line-normal (GMT_ANGLE_LINE_NORMAL), 2 = fixed angle (GMT_ANGLE_LINE_FIXED) */
int number_placement; /* How the n_cont symbols are distributed [-1/0/+1]*/
bool isolate; /* true if we have a limit on how close symbols may appear (see below) */
bool segmentize; /* true if we should segmentize input lines before plotting */
Expand Down
30 changes: 15 additions & 15 deletions src/gmt_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -2091,13 +2091,13 @@ GMT_LOCAL void gmtsupport_line_angle_ave (struct GMT_CTRL *GMT, double x[], doub
if (fabs (L->line_angle - angle) > 145.0) L->line_angle += 180.0;
}
}
if (angle_type == 2) { /* Just return the fixed angle given (unless NaN) */
if (angle_type == GMT_ANGLE_LINE_FIXED) { /* Just return the fixed angle given (unless NaN) */
if (gmt_M_is_dnan (cangle)) /* Cannot use this angle - default to along-line angle */
angle_type = 0;
angle_type = GMT_ANGLE_LINE_PARALLEL;
else
L->angle = L->line_angle = cangle;
}
if (angle_type != 2) { /* Must base label angle on the contour angle */
if (angle_type != GMT_ANGLE_LINE_FIXED) { /* Must base label angle on the contour angle */
L->angle = L->line_angle + angle_type * 90.0; /* May add 90 to get normal */
if (L->angle < 0.0) L->angle += 360.0;
if (L->angle > 90.0 && L->angle < 270) L->angle -= 180.0;
Expand All @@ -2120,13 +2120,13 @@ GMT_LOCAL void gmtsupport_line_angle_line (struct GMT_CTRL *GMT, double x[], dou
dx = x[stop] - x[start];
dy = y[stop] - y[start];
L->line_angle = d_atan2d (dy, dx);
if (angle_type == 2) { /* Just return the fixed angle given (unless NaN) */
if (angle_type == GMT_ANGLE_LINE_FIXED) { /* Just return the fixed angle given (unless NaN) */
if (gmt_M_is_dnan (cangle)) /* Cannot use this angle - default to along-line angle */
angle_type = 0;
angle_type = GMT_ANGLE_LINE_PARALLEL;
else
L->angle = cangle;
L->angle += cangle;
}
if (angle_type != 2) { /* Must base label angle on the contour angle */
if (angle_type != GMT_ANGLE_LINE_FIXED) { /* Must base label angle on the contour angle */
L->angle = L->line_angle + angle_type * 90.0; /* May add 90 to get normal */
if (L->angle < 0.0) L->angle += 360.0;
if (L->angle > 90.0 && L->angle < 270) L->angle -= 180.0;
Expand Down Expand Up @@ -10454,17 +10454,17 @@ int gmt_contlabel_specs (struct GMT_CTRL *GMT, char *txt, struct GMT_CONTOUR *G)
switch (p[0]) {
case 'a': /* Angle specification */
if (p[1] == 'p' || p[1] == 'P') { /* Line-parallel label */
G->angle_type = G->hill_label = 0;
G->angle_type = G->hill_label = GMT_ANGLE_LINE_PARALLEL;
if (p[2] == 'u' || p[2] == 'U') /* Line-parallel label readable when looking up hill */
G->hill_label = +1;
else if (p[2] == 'd' || p[2] == 'D') /* Line-parallel label readable when looking down hill */
G->hill_label = -1;
}
else if (p[1] == 'n' || p[1] == 'N') /* Line-normal label */
G->angle_type = 1;
G->angle_type = GMT_ANGLE_LINE_NORMAL;
else { /* Label at a fixed angle */
G->label_angle = atof (&p[1]);
G->angle_type = 2;
G->angle_type = GMT_ANGLE_LINE_FIXED;
gmt_lon_range_adjust (GMT_IS_M180_TO_P180_RANGE, &G->label_angle); /* Now -180/+180 */
while (fabs (G->label_angle) > 90.0) G->label_angle -= copysign (180.0, G->label_angle);
}
Expand Down Expand Up @@ -10799,12 +10799,12 @@ int gmtlib_decorate_specs (struct GMT_CTRL *GMT, char *txt, struct GMT_DECORATE
switch (p[0]) {
case 'a': /* Angle specification */
if (p[1] == 'p' || p[1] == 'P') /* Line-parallel label */
G->angle_type = 0;
G->angle_type = GMT_ANGLE_LINE_PARALLEL;
else if (p[1] == 'n' || p[1] == 'N') /* Line-normal label */
G->angle_type = 1;
G->angle_type = GMT_ANGLE_LINE_NORMAL;
else { /* Label at a fixed angle */
G->symbol_angle = atof (&p[1]);
G->angle_type = 2;
G->angle_type = GMT_ANGLE_LINE_FIXED;
gmt_lon_range_adjust (GMT_IS_M180_TO_P180_RANGE, &G->symbol_angle); /* Now -180/+180 */
while (fabs (G->symbol_angle) > 90.0) G->symbol_angle -= copysign (180.0, G->symbol_angle);
}
Expand Down Expand Up @@ -11487,9 +11487,9 @@ int gmt_contlabel_prep (struct GMT_CTRL *GMT, struct GMT_CONTOUR *G, double xyz[
GMT_Report (GMT->parent, GMT_MSG_ERROR, "Option -%c: Map distance options requires a map projection.\n", G->flag);
error++;
}
if (G->angle_type == 0)
if (G->angle_type == GMT_ANGLE_LINE_PARALLEL)
G->no_gap = (G->just < 5 || G->just > 7); /* Don't clip contour if label is not in the way */
else if (G->angle_type == 1)
else if (G->angle_type == GMT_ANGLE_LINE_NORMAL)
G->no_gap = ((G->just + 2)%4 != 0); /* Don't clip contour if label is not in the way */

if (G->crossing == GMT_CONTOUR_XLINE) {
Expand Down
12 changes: 6 additions & 6 deletions src/grdcontour.c
Original file line number Diff line number Diff line change
Expand Up @@ -1218,7 +1218,7 @@ EXTERN_MSC int GMT_grdcontour (void *V_API, int mode, void *args) {
cont[c].type = 'A';
else
cont[c].type = (Ctrl->contour.annot) ? 'A' : 'C';
cont[c].angle = (Ctrl->contour.angle_type == 2) ? Ctrl->contour.label_angle : GMT->session.d_NaN;
cont[c].angle = (Ctrl->contour.angle_type == GMT_ANGLE_LINE_FIXED) ? Ctrl->contour.label_angle : GMT->session.d_NaN;
cont[c].do_tick = (char)Ctrl->T.active;
c++;
}
Expand All @@ -1229,7 +1229,7 @@ EXTERN_MSC int GMT_grdcontour (void *V_API, int mode, void *args) {
cont[c].type = 'A';
else
cont[c].type = (Ctrl->contour.annot) ? 'A' : 'C';
cont[c].angle = (Ctrl->contour.angle_type == 2) ? Ctrl->contour.label_angle : GMT->session.d_NaN;
cont[c].angle = (Ctrl->contour.angle_type == GMT_ANGLE_LINE_FIXED) ? Ctrl->contour.label_angle : GMT->session.d_NaN;
cont[c].do_tick = (char)Ctrl->T.active;
n_contours = c + 1;
}
Expand All @@ -1251,13 +1251,13 @@ EXTERN_MSC int GMT_grdcontour (void *V_API, int mode, void *args) {
cont[c].type = 'C';
cont[c].val = zc[c];
cont[c].do_tick = Ctrl->T.active ? 1 : 0;
cont[c].angle = (Ctrl->contour.angle_type == 2) ? Ctrl->contour.label_angle : GMT->session.d_NaN;
cont[c].angle = (Ctrl->contour.angle_type == GMT_ANGLE_LINE_FIXED) ? Ctrl->contour.label_angle : GMT->session.d_NaN;
}
for (c = 0; c < (int)na; c++) {
cont[c+nc].type = 'A';
cont[c+nc].val = za[c];
cont[c+nc].do_tick = Ctrl->T.active ? 1 : 0;
cont[c+nc].angle = (Ctrl->contour.angle_type == 2) ? Ctrl->contour.label_angle : GMT->session.d_NaN;
cont[c+nc].angle = (Ctrl->contour.angle_type == GMT_ANGLE_LINE_FIXED) ? Ctrl->contour.label_angle : GMT->session.d_NaN;
}
if (za) gmt_M_free (GMT, za);
if (zc) gmt_M_free (GMT, zc);
Expand All @@ -1276,7 +1276,7 @@ EXTERN_MSC int GMT_grdcontour (void *V_API, int mode, void *args) {
cont[n_contours].type = 'A';
cont[n_contours].val = Ctrl->A.info.single_cont;
cont[n_contours].do_tick = Ctrl->T.active ? 1 : 0;
cont[n_contours].angle = (Ctrl->contour.angle_type == 2) ? Ctrl->contour.label_angle : GMT->session.d_NaN;
cont[n_contours].angle = (Ctrl->contour.angle_type == GMT_ANGLE_LINE_FIXED) ? Ctrl->contour.label_angle : GMT->session.d_NaN;
n_contours++;
}
}
Expand All @@ -1302,7 +1302,7 @@ EXTERN_MSC int GMT_grdcontour (void *V_API, int mode, void *args) {
cont[n_contours].type = 'C';
else
cont[n_contours].type = (fabs (cont[n_contours].val - aval) < noise) ? 'A' : 'C';
cont[n_contours].angle = (Ctrl->contour.angle_type == 2) ? Ctrl->contour.label_angle : GMT->session.d_NaN;
cont[n_contours].angle = (Ctrl->contour.angle_type == GMT_ANGLE_LINE_FIXED) ? Ctrl->contour.label_angle : GMT->session.d_NaN;
cont[n_contours].do_tick = (char)Ctrl->T.active;
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/pscontour.c
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,7 @@ EXTERN_MSC int GMT_pscontour (void *V_API, int mode, void *args) {
else
cont[c].type = (Ctrl->contour.annot) ? 'A' : 'C';
cont[c].type = (P->data[i].annot && !Ctrl->A.info.mode) ? 'A' : 'C';
cont[c].angle = (Ctrl->contour.angle_type == 2) ? Ctrl->contour.label_angle : GMT->session.d_NaN;
cont[c].angle = (Ctrl->contour.angle_type == GMT_ANGLE_LINE_FIXED) ? Ctrl->contour.label_angle : GMT->session.d_NaN;
cont[c].do_tick = Ctrl->T.active;
GMT_Report (API, GMT_MSG_DEBUG, "Contour slice %d: Value = %g type = %c angle = %g\n", c, cont[c].val, cont[c].type, cont[c].angle);
c++;
Expand All @@ -921,7 +921,7 @@ EXTERN_MSC int GMT_pscontour (void *V_API, int mode, void *args) {
cont[c].type = 'A';
else
cont[c].type = (Ctrl->contour.annot) ? 'A' : 'C';
cont[c].angle = (Ctrl->contour.angle_type == 2) ? Ctrl->contour.label_angle : GMT->session.d_NaN;
cont[c].angle = (Ctrl->contour.angle_type == GMT_ANGLE_LINE_FIXED) ? Ctrl->contour.label_angle : GMT->session.d_NaN;
cont[c].do_tick = Ctrl->T.active;
c++;
}
Expand All @@ -946,13 +946,13 @@ EXTERN_MSC int GMT_pscontour (void *V_API, int mode, void *args) {
cont[c].type = 'C';
cont[c].val = zc[c];
cont[c].do_tick = Ctrl->T.active ? 1 : 0;
cont[c].angle = (Ctrl->contour.angle_type == 2) ? Ctrl->contour.label_angle : GMT->session.d_NaN;
cont[c].angle = (Ctrl->contour.angle_type == GMT_ANGLE_LINE_FIXED) ? Ctrl->contour.label_angle : GMT->session.d_NaN;
}
for (c = 0; c < na; c++) {
cont[c+nc].type = 'A';
cont[c+nc].val = za[c];
cont[c+nc].do_tick = Ctrl->T.active ? 1 : 0;
cont[c+nc].angle = (Ctrl->contour.angle_type == 2) ? Ctrl->contour.label_angle : GMT->session.d_NaN;
cont[c+nc].angle = (Ctrl->contour.angle_type == GMT_ANGLE_LINE_FIXED) ? Ctrl->contour.label_angle : GMT->session.d_NaN;
}
if (za) gmt_M_free (GMT, za);
if (zc) gmt_M_free (GMT, zc);
Expand All @@ -971,7 +971,7 @@ EXTERN_MSC int GMT_pscontour (void *V_API, int mode, void *args) {
cont[n_contours].type = 'A';
cont[n_contours].val = Ctrl->A.info.single_cont;
cont[n_contours].do_tick = Ctrl->T.active;
cont[n_contours].angle = (Ctrl->contour.angle_type == 2) ? Ctrl->contour.label_angle : GMT->session.d_NaN;
cont[n_contours].angle = (Ctrl->contour.angle_type == GMT_ANGLE_LINE_FIXED) ? Ctrl->contour.label_angle : GMT->session.d_NaN;
n_contours++;
}
}
Expand Down Expand Up @@ -1013,7 +1013,7 @@ EXTERN_MSC int GMT_pscontour (void *V_API, int mode, void *args) {
}
if (Ctrl->contour.annot && (cont[c].val - aval) > noise) aval += Ctrl->A.info.interval;
cont[c].type = (fabs (cont[c].val - aval) < noise) ? 'A' : 'C';
cont[c].angle = (Ctrl->contour.angle_type == 2) ? Ctrl->contour.label_angle : GMT->session.d_NaN;
cont[c].angle = (Ctrl->contour.angle_type == GMT_ANGLE_LINE_FIXED) ? Ctrl->contour.label_angle : GMT->session.d_NaN;
cont[c].do_tick = Ctrl->T.active;
}
n_contours = c;
Expand Down

0 comments on commit 9f2236e

Please sign in to comment.