From 4bff190aed2499f622bc004395f26bc9aab2e157 Mon Sep 17 00:00:00 2001 From: Esteban82 Date: Tue, 11 Aug 2026 10:36:05 -0300 Subject: [PATCH] Allow 0 in GMT_REGION_ROUND_EXTEND --- src/gmt_support.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/gmt_support.c b/src/gmt_support.c index b64383b2953..7e960e2f2f4 100644 --- a/src/gmt_support.c +++ b/src/gmt_support.c @@ -18677,10 +18677,12 @@ void gmt_extend_region (struct GMT_CTRL *GMT, double wesn[], unsigned int mode, } else { /* Make region be in multiples of increments, possibly with adjustment */ double adjust = (mode == GMT_REGION_ROUND_EXTEND) ? GMT_REGION_INCFACTOR : 0.0; - wesn[XLO] = floor ((wesn[XLO] - adjust * inc[XLO]) / inc[XLO]) * inc[XLO]; - wesn[YLO] = floor ((wesn[YLO] - adjust * inc[YLO]) / inc[YLO]) * inc[YLO]; - wesn[XHI] = ceil ((wesn[XHI] + adjust * inc[XHI]) / inc[XHI]) * inc[XHI]; - wesn[YHI] = ceil ((wesn[YHI] + adjust * inc[YHI]) / inc[YHI]) * inc[YHI]; + /* A zero increment on either axis means "leave that axis alone" - skip rounding + * for that axis instead of dividing by zero (which produced NaN, see issue #6434) */ + if (inc[XLO] > 0.0) wesn[XLO] = floor ((wesn[XLO] - adjust * inc[XLO]) / inc[XLO]) * inc[XLO]; + if (inc[YLO] > 0.0) wesn[YLO] = floor ((wesn[YLO] - adjust * inc[YLO]) / inc[YLO]) * inc[YLO]; + if (inc[XHI] > 0.0) wesn[XHI] = ceil ((wesn[XHI] + adjust * inc[XHI]) / inc[XHI]) * inc[XHI]; + if (inc[YHI] > 0.0) wesn[YHI] = ceil ((wesn[YHI] + adjust * inc[YHI]) / inc[YHI]) * inc[YHI]; } }