Skip to content

Commit a81bd3c

Browse files
authored
COrrectly compute contour length for wrapped contours (#6102)
COntours split across periodic boundaries will have jumps across the map. These are not drawn, but the code used them in computing the length which affects how many ticks are set. This corrects the contour length calculations.
1 parent 3486e5c commit a81bd3c

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/grdcontour.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ GMT_LOCAL void grdcontour_sort_and_plot_ticks (struct GMT_CTRL *GMT, struct PSL_
540540
double add, dx, dy, x_back, y_back, x_front, y_front, x_end, y_end, x_lbl, y_lbl;
541541
double xmin, xmax, ymin, ymax, inc, dist, a, this_lon, this_lat, sa, ca;
542542
double *s = NULL, *xp = NULL, *yp = NULL;
543-
double da, db, dc, dd;
543+
double da, db, dc, dd, L, L_cut;
544544

545545
double tick_gap = I->dim[GMT_X];
546546
double tick_length = I->dim[GMT_Y];
@@ -668,8 +668,13 @@ GMT_LOCAL void grdcontour_sort_and_plot_ticks (struct GMT_CTRL *GMT, struct PSL_
668668
if (np == 0) continue;
669669

670670
s = gmt_M_memory (GMT, NULL, np, double); /* Compute distance along the contour */
671-
for (j = 1, s[0] = 0.0; j < np; j++)
672-
s[j] = s[j-1] + hypot (xp[j]-xp[j-1], yp[j]-yp[j-1]);
671+
for (j = 1, s[0] = 0.0; j < np; j++) {
672+
L = hypot (xp[j]-xp[j-1], yp[j]-yp[j-1]);
673+
L_cut = gmt_half_map_width (GMT, 0.5 * (yp[j]+yp[j-1]));
674+
if (L > L_cut) /* Eliminate horizontal jumps exceeding half mapwidth at this y-value */
675+
L = 0.0;
676+
s[j] = s[j-1] + L;
677+
}
673678
n_ticks = irint (floor (s[np-1] / tick_gap));
674679
if (s[np-1] < GRDCONTOUR_MIN_LENGTH || n_ticks == 0) { /* Contour is too short to be ticked or labeled */
675680
save[pol].do_it = false;

0 commit comments

Comments
 (0)