From 11c33ae1f6c210e01caffd7712edec646ab90c31 Mon Sep 17 00:00:00 2001 From: Esteban82 Date: Tue, 20 Oct 2026 15:58:24 -0300 Subject: [PATCH 1/7] Remove the known-failure flag from psxy/nojump Co-Authored-By: Claude Opus 5.5 --- test/psxy/nojump.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/test/psxy/nojump.sh b/test/psxy/nojump.sh index 7c3e43adb3f..0501c7a4427 100755 --- a/test/psxy/nojump.sh +++ b/test/psxy/nojump.sh @@ -1,5 +1,4 @@ #!/usr/bin/env bash -# GMT_KNOWN_FAILURE # Added after issue #672 which exposed a map jump that should not happen # Fixed in r14052 but we keep this test in case it resurfaces # Well, bottom panel plots the wrong closed polygon From dc8a22293c915b55dda01ea9cacaf52a9bd439eb Mon Sep 17 00:00:00 2001 From: Esteban82 Date: Tue, 20 Oct 2026 15:58:24 -0300 Subject: [PATCH 2/7] Restore the 180-degree jump test in gmtmap_jump_x Commit 0370cd83d6 (2018) compared the longitude separation of two consecutive points against half the -R width instead of 180 degrees, so in regions 90-360 degrees wide any segment longer than half the region was treated as a map jump and drawn the other way (test psxy/nojump, bottom panel). For 360-degree regions the threshold was already 180. Co-Authored-By: Claude Opus 5.5 --- src/gmt_map.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/gmt_map.c b/src/gmt_map.c index 8d0b6f5baad..40616a04f63 100644 --- a/src/gmt_map.c +++ b/src/gmt_map.c @@ -1148,7 +1148,7 @@ GMT_LOCAL unsigned int gmtmap_genper_crossing (struct GMT_CTRL *GMT, double lon1 GMT_LOCAL int gmtmap_jump_x (struct GMT_CTRL *GMT, double x0, double y0, double x1, double y1) { /* true if x-distance between points exceeds 1/2 map width at this y value */ - double dx, map_half_size, half_lon_range; + double dx, map_half_size; if (!(gmt_M_is_cylindrical (GMT) || gmt_M_is_perspective (GMT) || gmt_M_is_misc (GMT))) return (0); /* Only projections with periodic boundaries may apply */ @@ -1157,7 +1157,6 @@ GMT_LOCAL int gmtmap_jump_x (struct GMT_CTRL *GMT, double x0, double y0, double map_half_size = MAX (gmt_half_map_width (GMT, y0), gmt_half_map_width (GMT, y1)); if (fabs (map_half_size) < GMT_CONV4_LIMIT) return (0); - half_lon_range = (GMT->common.R.oblique) ? 180.0 : 0.5 * (GMT->common.R.wesn[XHI] - GMT->common.R.wesn[XLO]); dx = x1 - x0; if (fabs (dx) > map_half_size) { /* Possible jump; let's see how far apart those longitudes really are */ /* This test on longitudes was added to deal with issue #672, also see test/psxy/nojump.sh */ @@ -1165,7 +1164,7 @@ GMT_LOCAL int gmtmap_jump_x (struct GMT_CTRL *GMT, double x0, double y0, double gmt_xy_to_geo (GMT, &last_lon, &dummy, x0, y0); gmt_xy_to_geo (GMT, &this_lon, &dummy, x1, y1); gmt_M_set_delta_lon (last_lon, this_lon, dlon); /* Beware of jumps due to sign differences */ - if (fabs (dlon) < half_lon_range) /* Not going the long way so we judge this to be no jump */ + if (fabs (dlon) < 180.0) /* Not going the long way so we judge this to be no jump */ return (0); /* Jump it is */ if (dx > map_half_size) return (-1); /* Cross left/west boundary */ From be217a203a5bb23ca6e6502036a6e80a054e8e84 Mon Sep 17 00:00:00 2001 From: Esteban82 Date: Tue, 20 Oct 2026 18:43:17 -0300 Subject: [PATCH 3/7] Regenerate the psxy/nojump baseline The 2015 baseline has the old degree symbol and hyphen-minus in the axis annotations (changed in 586758f64b, 2018-12-06), so it fails on every platform even though the lines are now drawn correctly. Co-Authored-By: Claude Opus 5.5 --- test/baseline/psxy.dvc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/baseline/psxy.dvc b/test/baseline/psxy.dvc index a2018e0e636..b1c26a3594e 100644 --- a/test/baseline/psxy.dvc +++ b/test/baseline/psxy.dvc @@ -1,5 +1,6 @@ outs: -- md5: fd04135cb8226c86f8f109e5dca463fe.dir +- md5: 6dbbc75aa2f8752b1450e4f22b7656f2.dir nfiles: 147 path: psxy hash: md5 + size: 9555170 From df71eea613e402d589e68b1668594231e3c87567 Mon Sep 17 00:00:00 2001 From: Esteban82 Date: Tue, 20 Oct 2026 23:49:56 -0300 Subject: [PATCH 4/7] gmtmap_jump_x: Keep the regional jump test, skip it when the straight path is the short way Returning to 180 degrees alone (previous commit) loses the jump detection for regional maps: an -A line from -110 to 110 in -R-120/120 must go the short way through the gap outside the region, and a filled polygon in -R0/200 must not become self-crossing. Restore the half-width test and only add: if the longitudes taken relative to the central meridian are less than 180 degrees apart, the straight path is the short way and there is no jump. This can only remove jumps the old code reported. Co-Authored-By: Claude Sonnet 5.5 --- src/gmt_map.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/gmt_map.c b/src/gmt_map.c index 40616a04f63..4392c280e90 100644 --- a/src/gmt_map.c +++ b/src/gmt_map.c @@ -1148,7 +1148,7 @@ GMT_LOCAL unsigned int gmtmap_genper_crossing (struct GMT_CTRL *GMT, double lon1 GMT_LOCAL int gmtmap_jump_x (struct GMT_CTRL *GMT, double x0, double y0, double x1, double y1) { /* true if x-distance between points exceeds 1/2 map width at this y value */ - double dx, map_half_size; + double dx, map_half_size, half_lon_range; if (!(gmt_M_is_cylindrical (GMT) || gmt_M_is_perspective (GMT) || gmt_M_is_misc (GMT))) return (0); /* Only projections with periodic boundaries may apply */ @@ -1157,14 +1157,19 @@ GMT_LOCAL int gmtmap_jump_x (struct GMT_CTRL *GMT, double x0, double y0, double map_half_size = MAX (gmt_half_map_width (GMT, y0), gmt_half_map_width (GMT, y1)); if (fabs (map_half_size) < GMT_CONV4_LIMIT) return (0); + half_lon_range = (GMT->common.R.oblique) ? 180.0 : 0.5 * (GMT->common.R.wesn[XHI] - GMT->common.R.wesn[XLO]); dx = x1 - x0; if (fabs (dx) > map_half_size) { /* Possible jump; let's see how far apart those longitudes really are */ /* This test on longitudes was added to deal with issue #672, also see test/psxy/nojump.sh */ - double last_lon = 0.0, this_lon = 0.0, dummy = 0.0, dlon; + double last_lon = 0.0, this_lon = 0.0, dummy = 0.0, dlon, d0, d1; gmt_xy_to_geo (GMT, &last_lon, &dummy, x0, y0); gmt_xy_to_geo (GMT, &this_lon, &dummy, x1, y1); gmt_M_set_delta_lon (last_lon, this_lon, dlon); /* Beware of jumps due to sign differences */ - if (fabs (dlon) < 180.0) /* Not going the long way so we judge this to be no jump */ + if (fabs (dlon) < half_lon_range) /* Not going the long way so we judge this to be no jump */ + return (0); + gmt_M_set_delta_lon (GMT->current.proj.central_meridian, last_lon, d0); /* Longitudes relative to the central meridian */ + gmt_M_set_delta_lon (GMT->current.proj.central_meridian, this_lon, d1); + if (fabs (d1 - d0) < 180.0) /* The straight path is the short way, so no jump */ return (0); /* Jump it is */ if (dx > map_half_size) return (-1); /* Cross left/west boundary */ From 99f8324890b2dcf8f295dede8bc59688daad57c3 Mon Sep 17 00:00:00 2001 From: Esteban82 Date: Wed, 28 Oct 2026 18:11:10 -0300 Subject: [PATCH 5/7] gmtmap_jump_x: Measure the short way from the middle of -R, not the central meridian With a central meridian away from the middle of the region (e.g. -R-30/150 -JQ0) the previous commit could drop a real jump, and an -A fill was then drawn on the wrong side, because gmtmap_wesn_clip wraps longitudes around the middle of -R. Also update a stale comment and drop the nojump.sh line that described the old bug. Co-Authored-By: Claude Opus 5.5 --- src/gmt_map.c | 9 +++++---- test/psxy/nojump.sh | 1 - 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/gmt_map.c b/src/gmt_map.c index 4392c280e90..f74504272a4 100644 --- a/src/gmt_map.c +++ b/src/gmt_map.c @@ -1161,14 +1161,15 @@ GMT_LOCAL int gmtmap_jump_x (struct GMT_CTRL *GMT, double x0, double y0, double dx = x1 - x0; if (fabs (dx) > map_half_size) { /* Possible jump; let's see how far apart those longitudes really are */ /* This test on longitudes was added to deal with issue #672, also see test/psxy/nojump.sh */ - double last_lon = 0.0, this_lon = 0.0, dummy = 0.0, dlon, d0, d1; + double last_lon = 0.0, this_lon = 0.0, dummy = 0.0, dlon, d0, d1, mid_lon; gmt_xy_to_geo (GMT, &last_lon, &dummy, x0, y0); gmt_xy_to_geo (GMT, &this_lon, &dummy, x1, y1); gmt_M_set_delta_lon (last_lon, this_lon, dlon); /* Beware of jumps due to sign differences */ - if (fabs (dlon) < half_lon_range) /* Not going the long way so we judge this to be no jump */ + if (fabs (dlon) < half_lon_range) /* Gap is less than half the region width so we judge this to be no jump */ return (0); - gmt_M_set_delta_lon (GMT->current.proj.central_meridian, last_lon, d0); /* Longitudes relative to the central meridian */ - gmt_M_set_delta_lon (GMT->current.proj.central_meridian, this_lon, d1); + mid_lon = 0.5 * (GMT->common.R.wesn[XLO] + GMT->common.R.wesn[XHI]); + gmt_M_set_delta_lon (mid_lon, last_lon, d0); /* Longitudes relative to the middle of the region */ + gmt_M_set_delta_lon (mid_lon, this_lon, d1); if (fabs (d1 - d0) < 180.0) /* The straight path is the short way, so no jump */ return (0); /* Jump it is */ diff --git a/test/psxy/nojump.sh b/test/psxy/nojump.sh index 0501c7a4427..be6e8f9194a 100755 --- a/test/psxy/nojump.sh +++ b/test/psxy/nojump.sh @@ -1,7 +1,6 @@ #!/usr/bin/env bash # Added after issue #672 which exposed a map jump that should not happen # Fixed in r14052 but we keep this test in case it resurfaces -# Well, bottom panel plots the wrong closed polygon ps=nojump.ps cat << EOF > t.txt 115 -20 From 6a79234bdb610c372941d19e66ffbdee417e0897 Mon Sep 17 00:00:00 2001 From: Esteban82 Date: Fri, 30 Oct 2026 19:03:36 -0300 Subject: [PATCH 6/7] plot -A: Join geographic points by straight lines on the map and never split them The documentation (#9284) says that with -A the points are joined by straight lines on the map, as in a Cartesian plot, and that these lines are not split at the map edges. The code still split or wrapped them in several places: the half-width jump test, the global wrap-around check, the short-way crossing and overlap tests, and the clipper that wrapped vertices around the middle of -R. Add a GMT_STRAIGHT_PATH mode for -A (without a stair directive) and, for cylindrical, perspective and miscellaneous projections only, use the longitudes as they are plotted (relative to the central meridian) and skip all splitting. Azimuthal maps and lines drawn without -A are unchanged. Co-Authored-By: Claude Sonnet 5.5 --- src/gmt_constants.h | 3 ++- src/gmt_map.c | 36 ++++++++++++++++++++++++++++-------- src/gmt_vector.c | 2 +- src/psxy.c | 2 +- 4 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/gmt_constants.h b/src/gmt_constants.h index 84f85b57beb..4672e02b6ef 100644 --- a/src/gmt_constants.h +++ b/src/gmt_constants.h @@ -694,7 +694,8 @@ enum GMT_enum_inonout {GMT_IOO_UNKNOWN = 0, /* Decide based on range and type */ GMT_IOO_SPHERICAL}; /* Use spherical inside function */ enum GMT_enum_path {GMT_RESAMPLE_PATH = 0, /* Default: Resample geographic paths based in a max gap allowed (path_step) */ - GMT_LEAVE_PATH}; /* Options like -A can turn off this resampling, where available */ + GMT_LEAVE_PATH, /* Options like -A can turn off this resampling, where available */ + GMT_STRAIGHT_PATH}; /* As GMT_LEAVE_PATH, and geographic points are also joined by straight lines on the map (-A) */ enum GMT_enum_stairpath {GMT_STAIRS_OFF = 0, /* Default: No stairclimbing */ GMT_STAIRS_Y, /* Move vertically (meridian) to next point along y, then horizontally along x */ diff --git a/src/gmt_map.c b/src/gmt_map.c index f74504272a4..0028d7f7499 100644 --- a/src/gmt_map.c +++ b/src/gmt_map.c @@ -134,6 +134,9 @@ #include "gmt_dev.h" #include "gmt_internals.h" +/* With -A geographic points are joined by straight lines on the map, so these are never split or wrapped */ +#define gmtmap_straight_path(GMT) (GMT->current.map.path_mode == GMT_STRAIGHT_PATH && gmt_M_is_geographic (GMT, GMT_IN) && (gmt_M_is_cylindrical (GMT) || gmt_M_is_perspective (GMT) || gmt_M_is_misc (GMT))) + /* We put all the declaration of external functions from gmt_proj.h here since * (a) they are only called in gmt_map.c so no need to go in gmt_internals.h * (b) this will change completely when proj4 is relacing gmt_proj in GMT 6. @@ -658,7 +661,10 @@ GMT_LOCAL bool gmtmap_wesn_outside (struct GMT_CTRL *GMT, double lon, double lat * 360 degrees. In that case GMT->current.map.lon_wrap will be temporarily set to false. */ - if (GMT->current.map.lon_wrap) { + if (gmtmap_straight_path (GMT)) { /* Straight lines on the map: use the longitude as it is plotted */ + gmt_M_set_delta_lon (GMT->current.proj.central_meridian, lon, lon); lon += GMT->current.proj.central_meridian; + } + else if (GMT->current.map.lon_wrap) { while (lon < GMT->common.R.wesn[XLO] && (lon + GMT->current.map.lon_wrap_range) <= GMT->common.R.wesn[XHI]) lon += GMT->current.map.lon_wrap_range; while (lon > GMT->common.R.wesn[XHI] && (lon - GMT->current.map.lon_wrap_range) >= GMT->common.R.wesn[XLO]) lon -= GMT->current.map.lon_wrap_range; } @@ -806,7 +812,11 @@ GMT_LOCAL unsigned int gmtmap_wesn_crossing (struct GMT_CTRL *GMT, double lon0, * then move the western-most point east if it is further than 180 degrees away. * This may cause the points to span the eastern boundary */ - if (GMT->current.map.lon_wrap) { + if (gmtmap_straight_path (GMT)) { /* Straight lines on the map: use the longitudes as they are plotted, no short-way wrapping */ + gmt_M_set_delta_lon (GMT->current.proj.central_meridian, lon0, lon0); lon0 += GMT->current.proj.central_meridian; + gmt_M_set_delta_lon (GMT->current.proj.central_meridian, lon1, lon1); lon1 += GMT->current.proj.central_meridian; + } + else if (GMT->current.map.lon_wrap) { while (lon0 < GMT->common.R.wesn[XLO]) lon0 += GMT->current.map.lon_wrap_range; while (lon0 > GMT->common.R.wesn[XHI]) lon0 -= GMT->current.map.lon_wrap_range; while (lon1 < GMT->common.R.wesn[XLO]) lon1 += GMT->current.map.lon_wrap_range; @@ -855,7 +865,7 @@ GMT_LOCAL unsigned int gmtmap_wesn_crossing (struct GMT_CTRL *GMT, double lon0, } /* Now adjust the longitudes so that they might span the western boundary */ - if (GMT->current.map.lon_wrap && MAX(lon0, lon1) > GMT->common.R.wesn[XHI]) { + if (GMT->current.map.lon_wrap && !gmtmap_straight_path (GMT) && MAX(lon0, lon1) > GMT->common.R.wesn[XHI]) { lon0 -= GMT->current.map.lon_wrap_range; lon1 -= GMT->current.map.lon_wrap_range; } else if (GMT->current.map.lat_wrap && MAX(lat0, lat1) > GMT->common.R.wesn[YHI]) { @@ -1150,6 +1160,8 @@ GMT_LOCAL int gmtmap_jump_x (struct GMT_CTRL *GMT, double x0, double y0, double /* true if x-distance between points exceeds 1/2 map width at this y value */ double dx, map_half_size, half_lon_range; + if (gmtmap_straight_path (GMT)) return (0); /* Straight lines are never split */ + if (!(gmt_M_is_cylindrical (GMT) || gmt_M_is_perspective (GMT) || gmt_M_is_misc (GMT))) return (0); /* Only projections with periodic boundaries may apply */ if (gmt_M_is_cartesian (GMT, GMT_IN) || fabs (GMT->common.R.wesn[XLO] - GMT->common.R.wesn[XHI]) < 90.0) return (0); @@ -1184,6 +1196,8 @@ GMT_LOCAL int gmtmap_jump_xy (struct GMT_CTRL *GMT, double x0, double y0, double bool periodic; double dx, dy, map_half_width, map_half_height; + if (gmtmap_straight_path (GMT)) return (0); /* Straight lines are never split */ + if (!(gmt_M_is_cylindrical (GMT) || gmt_M_is_perspective (GMT) || gmt_M_is_misc (GMT))) return (0); /* Only projections with periodic boundaries may apply */ if (gmt_M_is_cartesian (GMT, GMT_IN) || fabs (GMT->common.R.wesn[XLO] - GMT->common.R.wesn[XHI]) < 90.0) return (0); @@ -1804,7 +1818,7 @@ uint64_t gmt_map_wesn_clip (struct GMT_CTRL *GMT, double *lon, double *lat, uint } } else { /* Don't let points be > 180 from center longitude */ - double mid_lon = 0.5 * (border[GMT_LEFT] + border[GMT_RIGHT]), diff; + double mid_lon = (gmtmap_straight_path (GMT)) ? GMT->current.proj.central_meridian : 0.5 * (border[GMT_LEFT] + border[GMT_RIGHT]), diff; for (i = 0; i < n; i++) { diff = lon[i] - mid_lon; if (diff > 180.0) lon[i] -= 360.0; @@ -2223,9 +2237,15 @@ GMT_LOCAL bool gmtmap_rect_overlap (struct GMT_CTRL *GMT, double lon0, double la /*! . */ GMT_LOCAL bool gmtmap_wesn_overlap (struct GMT_CTRL *GMT, double lon0, double lat0, double lon1, double lat1) { /* Return true if either of the points (lon0,lat0) and (lon1,lat1) is inside (not on) the rectangular lon/lat boundaries */ + bool straight = gmtmap_straight_path (GMT); + if (straight) { /* Straight lines on the map: use the longitudes as they are plotted, no short-way wrapping */ + gmt_M_set_delta_lon (GMT->current.proj.central_meridian, lon0, lon0); lon0 += GMT->current.proj.central_meridian; + gmt_M_set_delta_lon (GMT->current.proj.central_meridian, lon1, lon1); lon1 += GMT->current.proj.central_meridian; + } if (lon0 > lon1) gmt_M_double_swap (lon0, lon1); if (lat0 > lat1) gmt_M_double_swap (lat0, lat1); - if (lon1 - GMT->common.R.wesn[XLO] < -GMT_CONV8_LIMIT) { + if (straight) { /* Nothing */ } + else if (lon1 - GMT->common.R.wesn[XLO] < -GMT_CONV8_LIMIT) { lon0 += 360.0; lon1 += 360.0; } @@ -5649,7 +5669,7 @@ GMT_LOCAL bool gmtmap_will_it_wrap_x (struct GMT_CTRL *GMT, double *x, double *y bool wrap; double w_last, w_this; - if (!GMT->current.map.is_world) return (false); + if (!GMT->current.map.is_world || gmtmap_straight_path (GMT)) return (false); //if (!GMT->current.map.is_world) // f = (2.0 - GMT_CONV8_LIMIT); w_this = gmt_half_map_width (GMT, y[0]); @@ -8286,7 +8306,7 @@ GMT_LOCAL bool gmtmap_accept_the_jump (struct GMT_CTRL *GMT, double lon1, double double dlon0, dlon1, dlon; int xm, ym; gmt_M_unused(xx); - if (cartesian) return true; /* No wrap issues if Cartesian x,y */ + if (cartesian || gmtmap_straight_path (GMT)) return true; /* No wrap issues if Cartesian x,y or straight lines */ xm = GMT->current.map.this_x_status - GMT->current.map.prev_x_status; ym = GMT->current.map.this_y_status - GMT->current.map.prev_y_status; gmt_M_set_delta_lon (lon0, GMT->current.proj.central_meridian, dlon0); @@ -8371,7 +8391,7 @@ uint64_t gmt_geo_to_xy_line(struct GMT_CTRL *GMT, double *lon, double *lat, uint } if ((nx = gmtmap_crossing (GMT, lon[j-1], lat[j-1], lon[j], lat[j], xlon, xlat, xx, yy, sides))) { /* Do nothing if we get crossings*/ } - else if (GMT->current.map.is_world && /* Check global wrapping if 360 range */ + else if (GMT->current.map.is_world && !gmtmap_straight_path (GMT) && /* Check global wrapping if 360 range */ !(gmt_M_is_azimuthal (GMT) && !gmt_M_is_perspective (GMT))) /* Azimuthal projections (except ortho/genper) have a closed boundary; cylindrical wrap check makes spurious chord crossings (#8684) */ nx = (*GMT->current.map.wrap_around_check) (GMT, dummy, last_x, last_y, this_x, this_y, xx, yy, sides); diff --git a/src/gmt_vector.c b/src/gmt_vector.c index da7ff7c4289..f1c393547df 100644 --- a/src/gmt_vector.c +++ b/src/gmt_vector.c @@ -1529,7 +1529,7 @@ void gmt_set_line_resampling (struct GMT_CTRL *GMT, bool active, unsigned int mo * By default, path_mode = GMT_RESAMPLE_PATH = 0. */ if (gmt_M_is_geographic (GMT, GMT_IN)) { /* Geographic data: Default is to resample along great circles unless -A given */ - if (active && mode == GMT_STAIRS_OFF) GMT->current.map.path_mode = GMT_LEAVE_PATH; /* Turn off resampling */ + if (active && mode == GMT_STAIRS_OFF) GMT->current.map.path_mode = GMT_STRAIGHT_PATH; /* Turn off resampling and join points by straight lines on the map */ } else { /* Cartesian data: Default is to leave alone unless -Ax|y was set */ if (!active) GMT->current.map.path_mode = GMT_LEAVE_PATH; /* Turn off resampling */ diff --git a/src/psxy.c b/src/psxy.c index 058b30eed1c..421d85ba740 100644 --- a/src/psxy.c +++ b/src/psxy.c @@ -2491,7 +2491,7 @@ EXTERN_MSC int GMT_psxy (void *V_API, int mode, void *args) { struct GMT_DATASET_HIDDEN *DH = NULL; struct GMT_DATASEGMENT_HIDDEN *SH = NULL; - if (Ctrl->W.pen.mode == PSL_BEZIER && GMT->current.map.path_mode != GMT_LEAVE_PATH) /* Turn off path-resampling if Bezier */ + if (Ctrl->W.pen.mode == PSL_BEZIER && GMT->current.map.path_mode == GMT_RESAMPLE_PATH) /* Turn off path-resampling if Bezier */ GMT->current.map.path_mode = GMT_LEAVE_PATH; if (!no_line_clip) gmt_map_clip_on (GMT, GMT->session.no_rgb, 3); From 4dd4304a2768e035b14ff132a535229e3ad0a310 Mon Sep 17 00:00:00 2001 From: Esteban82 Date: Fri, 30 Oct 2026 21:57:51 -0300 Subject: [PATCH 7/7] plot -A: Fold longitudes once with gmt_M_wind_lon and keep symbols out of it Fold the longitudes about the central meridian once, where they enter gmt_map_outside and gmtmap_crossing, using the existing gmt_M_wind_lon, instead of separately in the outside, crossing and overlap functions; this also matches the projection at the +-180 boundary. Do not turn on the straight-path mode for psxy symbols (e.g. -S= vectors), so they keep wrapping at the Dateline as before. Co-Authored-By: Claude Opus 5.5 --- src/gmt_map.c | 26 ++++++++++---------------- src/psxy.c | 1 + 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/gmt_map.c b/src/gmt_map.c index 0028d7f7499..cf17578c81d 100644 --- a/src/gmt_map.c +++ b/src/gmt_map.c @@ -661,10 +661,7 @@ GMT_LOCAL bool gmtmap_wesn_outside (struct GMT_CTRL *GMT, double lon, double lat * 360 degrees. In that case GMT->current.map.lon_wrap will be temporarily set to false. */ - if (gmtmap_straight_path (GMT)) { /* Straight lines on the map: use the longitude as it is plotted */ - gmt_M_set_delta_lon (GMT->current.proj.central_meridian, lon, lon); lon += GMT->current.proj.central_meridian; - } - else if (GMT->current.map.lon_wrap) { + if (GMT->current.map.lon_wrap) { while (lon < GMT->common.R.wesn[XLO] && (lon + GMT->current.map.lon_wrap_range) <= GMT->common.R.wesn[XHI]) lon += GMT->current.map.lon_wrap_range; while (lon > GMT->common.R.wesn[XHI] && (lon - GMT->current.map.lon_wrap_range) >= GMT->common.R.wesn[XLO]) lon -= GMT->current.map.lon_wrap_range; } @@ -812,11 +809,7 @@ GMT_LOCAL unsigned int gmtmap_wesn_crossing (struct GMT_CTRL *GMT, double lon0, * then move the western-most point east if it is further than 180 degrees away. * This may cause the points to span the eastern boundary */ - if (gmtmap_straight_path (GMT)) { /* Straight lines on the map: use the longitudes as they are plotted, no short-way wrapping */ - gmt_M_set_delta_lon (GMT->current.proj.central_meridian, lon0, lon0); lon0 += GMT->current.proj.central_meridian; - gmt_M_set_delta_lon (GMT->current.proj.central_meridian, lon1, lon1); lon1 += GMT->current.proj.central_meridian; - } - else if (GMT->current.map.lon_wrap) { + if (GMT->current.map.lon_wrap && !gmtmap_straight_path (GMT)) { /* No short-way wrapping for straight lines */ while (lon0 < GMT->common.R.wesn[XLO]) lon0 += GMT->current.map.lon_wrap_range; while (lon0 > GMT->common.R.wesn[XHI]) lon0 -= GMT->current.map.lon_wrap_range; while (lon1 < GMT->common.R.wesn[XLO]) lon1 += GMT->current.map.lon_wrap_range; @@ -1359,6 +1352,10 @@ GMT_LOCAL int gmtmap_eqdist_crossing (struct GMT_CTRL *GMT, double lon1, double /*! . */ GMT_LOCAL unsigned int gmtmap_crossing (struct GMT_CTRL *GMT, double lon1, double lat1, double lon2, double lat2, double *xlon, double *xlat, double *xx, double *yy, unsigned int *sides) { + if (gmtmap_straight_path (GMT)) { /* Use the longitudes as plotted */ + gmt_M_wind_lon (GMT, lon1); lon1 += GMT->current.proj.central_meridian; + gmt_M_wind_lon (GMT, lon2); lon2 += GMT->current.proj.central_meridian; + } if (GMT->current.map.prev_x_status == GMT->current.map.this_x_status && GMT->current.map.prev_y_status == GMT->current.map.this_y_status) { /* This is naive. We could have two points outside with a line drawn between crossing the plotting area. */ return (0); @@ -2237,15 +2234,9 @@ GMT_LOCAL bool gmtmap_rect_overlap (struct GMT_CTRL *GMT, double lon0, double la /*! . */ GMT_LOCAL bool gmtmap_wesn_overlap (struct GMT_CTRL *GMT, double lon0, double lat0, double lon1, double lat1) { /* Return true if either of the points (lon0,lat0) and (lon1,lat1) is inside (not on) the rectangular lon/lat boundaries */ - bool straight = gmtmap_straight_path (GMT); - if (straight) { /* Straight lines on the map: use the longitudes as they are plotted, no short-way wrapping */ - gmt_M_set_delta_lon (GMT->current.proj.central_meridian, lon0, lon0); lon0 += GMT->current.proj.central_meridian; - gmt_M_set_delta_lon (GMT->current.proj.central_meridian, lon1, lon1); lon1 += GMT->current.proj.central_meridian; - } if (lon0 > lon1) gmt_M_double_swap (lon0, lon1); if (lat0 > lat1) gmt_M_double_swap (lat0, lat1); - if (straight) { /* Nothing */ } - else if (lon1 - GMT->common.R.wesn[XLO] < -GMT_CONV8_LIMIT) { + if (lon1 - GMT->common.R.wesn[XLO] < -GMT_CONV8_LIMIT) { lon0 += 360.0; lon1 += 360.0; } @@ -7671,6 +7662,9 @@ bool gmt_map_outside (struct GMT_CTRL *GMT, double lon, double lat) { GMT_Report (GMT->parent, GMT_MSG_ERROR, "gmt_map_outside: FATAL ERROR - the pointer to the projection function is NULL.\n"); return GMT_NOTSET; } + if (gmtmap_straight_path (GMT)) { /* Use the longitude as plotted */ + gmt_M_wind_lon (GMT, lon); lon += GMT->current.proj.central_meridian; + } return ((*GMT->current.map.outside) (GMT, lon, lat)); } diff --git a/src/psxy.c b/src/psxy.c index 421d85ba740..327c8ccf26c 100644 --- a/src/psxy.c +++ b/src/psxy.c @@ -1432,6 +1432,7 @@ EXTERN_MSC int GMT_psxy (void *V_API, int mode, void *args) { } gmt_set_line_resampling (GMT, Ctrl->A.active, Ctrl->A.mode); /* Possibly change line resampling mode */ + if (not_line && GMT->current.map.path_mode == GMT_STRAIGHT_PATH) GMT->current.map.path_mode = GMT_LEAVE_PATH; /* -A only makes lines straight, not symbols */ #ifdef DEBUG /* Change default step size (in degrees) used for interpolation of line segments along great circles (if requested) */ if (Ctrl->A.active) Ctrl->A.step = Ctrl->A.step / GMT->current.proj.scale[GMT_X] / GMT->current.proj.M_PR_DEG;