Skip to content

Fix NaN region when -Ra determines a degenerate (zero-range) region from data - #9164

Merged
Esteban82 merged 2 commits into
masterfrom
fix-round-wesn-zero-range
Aug 28, 2026
Merged

Fix NaN region when -Ra determines a degenerate (zero-range) region from data#9164
Esteban82 merged 2 commits into
masterfrom
fix-round-wesn-zero-range

Conversation

@Esteban82

@Esteban82 Esteban82 commented Aug 28, 2026

Copy link
Copy Markdown
Member

Description of proposed changes

Move the existing w==e/s==n safety valve fixing a NaN region when -Ra determines the region from a single data point (or points that only vary in one dimension).

Tested with:

echo "0 0" | gmt plot -Gred -Sc0.1c -JX3c -Ba -Ra -png lixo

Assisted-by: Claude Sonnet 5 (Medium effort)

…ounding

The dataset branch of gmtinit_get_region_from_data() already guarded
against a degenerate region (west==east and/or south==north, e.g. a
single input point, or points that only vary in one dimension) by
padding it to +/-1 (or +/-10%) — but that safety valve ran *after*
gmt_round_wesn(), which is what -Ra (approximate/rounded region) uses
to pick a "nice" region from the data.

gmt_round_wesn() takes log10() of the (zero) range while choosing a
rounding increment, which turns wesn into NaNs. By the time the
safety valve runs, wesn[XLO] and wesn[XHI] are both NaN, and
"NaN == NaN" is false, so the valve never fires and the NaN region is
used as-is, e.g.:

  echo "0 0" | gmt plot -Sc0.1c -Gred -JX3c -Ba -Ra -Vd
  ...
  plot [ERROR]: Could not parse -nan into ... coordinates!
  plot [ERROR]: Offending option -R-nan/-nan/-nan/-nan

Meanwhile -Re (exact region) was unaffected, since it skips
gmt_round_wesn() entirely and lets the safety valve run on the
original (non-NaN) degenerate range, giving -R-1/1/-1/1.

Move the safety valve above the gmt_round_wesn() call so -Ra now sees
the same already-padded, non-degenerate range that -Re does, and
rounds *that* instead of the original zero-width box. Verified with
the above command (now succeeds), a single point away from the origin
(gives a region centered on the point), and that regular multi-point
inputs are unaffected (still -0.2/5.2/-0.2/5.2 for two points 5 units
apart).

This affects every module that can determine -R from input data
("d"/"g" in THIS_MODULE_NEEDS), not just one module.

Assisted-by: Claude Sonnet 5 (Medium effort)
@Esteban82
Esteban82 requested review from joa-quim and seisman August 28, 2026 16:40
@Esteban82 Esteban82 added add-changelog Add PR to the changelog AI-assisted All (or most) of the code was written by Artificial Intelligence. labels Aug 28, 2026
@Esteban82 Esteban82 added this to the 6.8.0 milestone Aug 28, 2026
@Esteban82
Esteban82 merged commit 83cca51 into master Aug 28, 2026
10 of 14 checks passed
@Esteban82
Esteban82 deleted the fix-round-wesn-zero-range branch August 28, 2026 23:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

add-changelog Add PR to the changelog AI-assisted All (or most) of the code was written by Artificial Intelligence.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants