diff --git a/src/gmt_map.c b/src/gmt_map.c index 373c46c9980..4fbcc82df10 100644 --- a/src/gmt_map.c +++ b/src/gmt_map.c @@ -8011,6 +8011,15 @@ uint64_t gmtlib_lonpath (struct GMT_CTRL *GMT, double lon, double lat1, double l /* Must do general case */ n = 0; min_gap = 0.1 * GMT->current.setting.map_line_step; + if (!isfinite (GMT->current.map.dlat) || GMT->current.map.dlat <= 0.0) { /* Guard against invalid sampling step (e.g., antipodal singularities) */ + gmt_M_malloc2 (GMT, tlon, tlat, 2U, NULL, double); + tlon[0] = tlon[1] = lon; + tlat[0] = lat1; + tlat[1] = lat2; + *x = tlon; + *y = tlat; + return (2ULL); + } if ((n_alloc = lrint (ceil (fabs (lat2 - lat1) / GMT->current.map.dlat))) == 0) return (0); n_alloc++; /* So n_alloc is at least 2 */ @@ -8108,6 +8117,15 @@ uint64_t gmtlib_latpath (struct GMT_CTRL *GMT, double lat, double lon1, double l } /* Here we try to walk along lat for small increment in longitude to make sure our steps are smaller than the line_step */ min_gap = 0.1 * GMT->current.setting.map_line_step; + if (!isfinite (GMT->current.map.dlon) || GMT->current.map.dlon <= 0.0) { /* Guard against invalid sampling step (e.g., antipodal singularities) */ + gmt_M_malloc2 (GMT, tlon, tlat, 2U, NULL, double); + tlat[0] = tlat[1] = lat; + tlon[0] = lon1; + tlon[1] = lon2; + *x = tlon; + *y = tlat; + return (2ULL); + } if ((n_alloc = lrint (ceil (fabs (lon2 - lon1) / GMT->current.map.dlon))) == 0) return (0); /* Initial guess to path length */ n_alloc++; /* n_alloc is at least 2 */