Skip to content

Commit

Permalink
Fix bug and allow +apangle for decorated lines (#8182)
Browse files Browse the repository at this point in the history
* Fix failure to honor +a angle in decorated lines

Simply did not pass the fixed angle when it was set and ended up passing the line angle which was zero.

* Fix bug and allow +apangle for decorated lines

This fixes the bug in #7591. While at it, we allow +apangle to let the symbol angle deviate by angle from the line's angle.+aangle still sets a fixed angle regardless of angle contortions.
  • Loading branch information
PaulWessel committed Dec 11, 2023
1 parent 53b0412 commit a40741f
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 8 deletions.
3 changes: 2 additions & 1 deletion doc/rst/source/explain_symbols.rst_
Expand Up @@ -616,7 +616,8 @@

**+a**\ *angle*
Force symbols at a fixed angle, **+an** for line-normal, or
**+ap** for line-parallel [Default].
**+ap** for line-parallel [Default]. Use **p**\ *angle* to set a
constant deviation from line-parallel.

**+d**\ [*pen*]
Turn on debug, which will draw helper points and lines to illustrate
Expand Down
3 changes: 2 additions & 1 deletion src/gmt_contour.h
Expand Up @@ -41,7 +41,8 @@ enum GMT_enum_contline {
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 */
GMT_ANGLE_LINE_FIXED, /* Angle is fixed regardless of line direction */
GMT_ANGLE_LINE_DELTA}; /* Angle is a fixed offset from line direction */


/*! Various settings for quoted line/contour label types */
Expand Down
2 changes: 1 addition & 1 deletion src/gmt_decorate.h
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 (GMT_ANGLE_LINE_PARALLEL), 1 = line-normal (GMT_ANGLE_LINE_NORMAL), 2 = fixed angle (GMT_ANGLE_LINE_FIXED) */
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), 3 = fixed delta angle (GMT_ANGLE_LINE_DELTA) */
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
3 changes: 2 additions & 1 deletion src/gmt_init.c
Expand Up @@ -8592,7 +8592,8 @@ void gmt_label_syntax (struct GMT_CTRL *GMT, unsigned int indent, unsigned int k
}
else {
GMT_Usage (API, indent, "+a Place all %s at a fixed <angle>. "
"Or, specify +an (line-normal) or +ap (line-parallel) [Default].", feature[kind]);
"Or, specify +an (line-normal) or +ap (line-parallel) [Default]. If p<angle> is appended then
<angle> is used as a fixed deviation from the line orientation", feature[kind]);
}
if (kind < 2) GMT_Usage (API, indent, "+c Set clearance <dx>[/<dy>] between label and text box [15%%].");
GMT_Usage (API, indent, "+d Debug mode which draws helper points and lines; optionally add a pen [%s].", gmt_putpen (GMT, &GMT->current.setting.map_default_pen));
Expand Down
24 changes: 21 additions & 3 deletions src/gmt_support.c
Expand Up @@ -2233,6 +2233,12 @@ 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 == GMT_ANGLE_LINE_DELTA) { /* Add delta angle to line angle */
if (gmt_M_is_dnan (cangle)) /* Cannot use this angle - default to along-line angle */
angle_type = GMT_ANGLE_LINE_PARALLEL;
else
L->angle = L->line_angle + cangle;
}
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 = GMT_ANGLE_LINE_PARALLEL;
Expand Down Expand Up @@ -3387,6 +3393,7 @@ GMT_LOCAL void gmtsupport_hold_contour_sub (struct GMT_CTRL *GMT, double **xxx,
/*! . */
GMT_LOCAL void gmtsupport_add_decoration (struct GMT_CTRL *GMT, struct GMT_DATASEGMENT *S, struct GMT_LABEL *L, struct GMT_DECORATE *G) {
/* Add a symbol location to the growing segment */
double angle;
struct GMT_DATASEGMENT_HIDDEN *SH = gmt_get_DS_hidden (S);
if (S->n_rows == SH->n_alloc) { /* Need more memory for the segment */
uint64_t col;
Expand All @@ -3411,7 +3418,10 @@ GMT_LOCAL void gmtsupport_add_decoration (struct GMT_CTRL *GMT, struct GMT_DATAS
S->data[GMT_X][S->n_rows] = L->x;
S->data[GMT_Y][S->n_rows] = L->y;
S->data[GMT_Z][S->n_rows] = gmt_M_to_inch (GMT, G->size);
S->data[3][S->n_rows] = L->line_angle; /* Change this in inches internally instead of string */
if (G->angle_type == GMT_ANGLE_LINE_DELTA) angle = G->symbol_angle + L->line_angle;
else if (G->angle_type == GMT_ANGLE_LINE_FIXED) angle = G->symbol_angle;
else angle = L->line_angle;
S->data[3][S->n_rows] = angle;
S->text[S->n_rows++] = strdup (G->symbol_code);
}

Expand Down Expand Up @@ -10959,8 +10969,16 @@ int gmtlib_decorate_specs (struct GMT_CTRL *GMT, char *txt, struct GMT_DECORATE
while ((gmt_strtok (specs, "+", &pos, p))) {
switch (p[0]) {
case 'a': /* Angle specification */
if (p[1] == 'p' || p[1] == 'P') /* Line-parallel label */
G->angle_type = GMT_ANGLE_LINE_PARALLEL;
if (p[1] == 'p' || p[1] == 'P') { /* Line-parallel label */
if (p[2]) { /* Gave optional fixed angle deviation from line-parallel */
G->angle_type = GMT_ANGLE_LINE_DELTA;
G->symbol_angle = atof (&p[2]);
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);
}
else
G->angle_type = GMT_ANGLE_LINE_PARALLEL;
}
else if (p[1] == 'n' || p[1] == 'N') /* Line-normal label */
G->angle_type = GMT_ANGLE_LINE_NORMAL;
else { /* Label at a fixed angle */
Expand Down
2 changes: 1 addition & 1 deletion src/psxy.c
Expand Up @@ -442,7 +442,7 @@ GMT_LOCAL int psxy_plot_decorations (struct GMT_CTRL *GMT, struct GMT_DATASET *D
return (GMT->parent->error);
tmp_file[len] = '.'; /* Restore the ".def" extension so we can delete the file (unless -Vd) */
if (gmt_M_is_verbose (GMT, GMT_MSG_DEBUG)) { /* Leave the symbol def and txt files in the temp directory */
char tmp_file2[GMT_LEN64] = {""};
char tmp_file2[GMT_LEN128] = {""};
bool was = GMT->current.setting.io_header[GMT_OUT]; /* Save current setting */
GMT_Report (GMT->parent, GMT_MSG_DEBUG, "Temporary symbol file for decorated lines saved: %s\n", tmp_file);
if (GMT->parent->tmp_dir) /* Make unique file in tmp dir */
Expand Down

0 comments on commit a40741f

Please sign in to comment.