From ee1041114e3bc0fe7a801f972aa48007aea4b41d Mon Sep 17 00:00:00 2001 From: Paul Wessel Date: Thu, 9 Dec 2021 12:54:21 -1000 Subject: [PATCH] COrrectly compute contour length for wrapped contours 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. --- src/grdcontour.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/grdcontour.c b/src/grdcontour.c index 8896690ecea..1a50f305db2 100644 --- a/src/grdcontour.c +++ b/src/grdcontour.c @@ -540,7 +540,7 @@ GMT_LOCAL void grdcontour_sort_and_plot_ticks (struct GMT_CTRL *GMT, struct PSL_ double add, dx, dy, x_back, y_back, x_front, y_front, x_end, y_end, x_lbl, y_lbl; double xmin, xmax, ymin, ymax, inc, dist, a, this_lon, this_lat, sa, ca; double *s = NULL, *xp = NULL, *yp = NULL; - double da, db, dc, dd; + double da, db, dc, dd, L, L_cut; double tick_gap = I->dim[GMT_X]; 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_ if (np == 0) continue; s = gmt_M_memory (GMT, NULL, np, double); /* Compute distance along the contour */ - for (j = 1, s[0] = 0.0; j < np; j++) - s[j] = s[j-1] + hypot (xp[j]-xp[j-1], yp[j]-yp[j-1]); + for (j = 1, s[0] = 0.0; j < np; j++) { + L = hypot (xp[j]-xp[j-1], yp[j]-yp[j-1]); + L_cut = gmt_half_map_width (GMT, 0.5 * (yp[j]+yp[j-1])); + if (L > L_cut) /* Eliminate horizontal jumps exceeding half mapwidth at this y-value */ + L = 0.0; + s[j] = s[j-1] + L; + } n_ticks = irint (floor (s[np-1] / tick_gap)); if (s[np-1] < GRDCONTOUR_MIN_LENGTH || n_ticks == 0) { /* Contour is too short to be ticked or labeled */ save[pol].do_it = false;