Skip to content

Fix division by zero (NaN) in gmt_extend_region when +r/+e increment is 0 - #9127

Open
Esteban82 wants to merge 1 commit into
masterfrom
fix_6434_-Rcode+r/e0
Open

Fix division by zero (NaN) in gmt_extend_region when +r/+e increment is 0#9127
Esteban82 wants to merge 1 commit into
masterfrom
fix_6434_-Rcode+r/e0

Conversation

@Esteban82

Copy link
Copy Markdown
Member

Done with Claude Sonnet 5

Problem

-Rcode+r<inc> and -Rcode+e<inc> allow specifying 0 for one axis to mean "don't adjust that axis" (e.g. +e1/0 to only round/extend in x). However, gmt_extend_region() divided by inc[...] unconditionally when rounding to multiples of the increment, so a 0 increment produced a division by zero → -nan propagated into the resulting region (wesn[YLO]/wesn[YHI]).

Fix

In gmt_extend_region(), skip the floor/ceil rounding for any axis whose increment is 0, leaving that axis's bound untouched instead of dividing by zero.

Tested with

gmt begin test_6434 png
	gmt coast -Bf -W -RIT+r0/2 -Vi
	gmt coast -Bf -W -RIT+e2/0 -Vi -Xw
	gmt coast -Bf -W -RIT+e0/0/0/2 -Vi -Xw
gmt end

The figure is now generated correctly, and the region is reported correctly in the terminal:

coast [INFORMATION]: Region implied by DCW polygons is 6.6149/18.5135/34/48
coast [INFORMATION]: Region implied by DCW polygons is 6/20/35.4922/47.0952
coast [INFORMATION]: Region implied by DCW polygons is 6.6149/18.5135/35.4922/48

Closes #6434

@Esteban82
Esteban82 requested review from a team, joa-quim and seisman August 11, 2026 16:11
@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 11, 2026
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.

-Rcode+e/r and 2 values: Let yinc be 0

1 participant