Skip to content

Let modules called by modules in inset know of shrinking - #6751

Merged
PaulWessel merged 4 commits into
masterfrom
inset-shrink-fix
May 27, 2022
Merged

PaulWessel merged 4 commits into
masterfrom
inset-shrink-fix

Conversation

@PaulWessel

Copy link
Copy Markdown
Contributor

See this post for background. The problem was that the coast module called another module (plot) while inside the inset section but the called module was unaware that because of the -R -J and inset size setting there was a scaling of 0.73 applied. That meant plot was off by that factor (unless we countered that by appending +du to -J, which the user would not know was needed). The same would happen with any other module called inside the inset section that might call another module (e.g., plot calls plot when dealing with decorated lines, for instance).

The solution is to remember the computed inset scale in the API so that when the secondary module is initialized it can apply the same scaling as the mother module; this scaling happens in the belly of gmt_proj_setup.

With those changes, this works correctly:

gmt begin map
    gmt coast -R-74/-69.5/41/43 -JM15c -Baf -Wthin -Clightblue -Glightyellow
    gmt inset begin -DjBL+w3c+o0.5c/0.2c -F+pblack+gwhite
        gmt coast -R-80/-65/35/50 -JM? -Ggray -Cwhite -EUS.MA+gred -W1/thin -N1 -N2
    gmt inset end
gmt end show

See this post for background. The problem was that the coast command called another module (plot) while inside the inset section but the called module was unaware that because of the -R -J and inset size setting there was a scaling of 0.73 applied.  That meant plot was off by that factor.  THe same would happen with any other module called inside the inset section that might call another module.

The solution is to remember the computed inset scale in the API so that when the secondary module is initialized it can apply the same scaling as the mother module.
@PaulWessel PaulWessel added the bug Something isn't working label May 26, 2022
@PaulWessel PaulWessel added this to the 6.4.0 milestone May 26, 2022
@PaulWessel
PaulWessel requested a review from seisman May 26, 2022 18:38
@PaulWessel PaulWessel self-assigned this May 26, 2022
Comment thread src/inset.c
gmt_reload_history (API->GMT);
gmt_reload_settings (API->GMT);
/* Undo any shrink scaling memory */
API->inset_shrink_scale = 1.0;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid this precaution might not be enough as it only happens inside inset.c
Because whatever is set in API carries to other modules calls in Julia/MEX this undoing should be done in end_session as well, I think.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, it is only set when gmt inset is called and shrinking is required, and it is guaranteed there will be a gmt inset end call to follow. So it only lives as long as we are in an inset. It wont hurt to add it to gmt end but not sure if it would make a difference. Can you demonstrate the need?

@joa-quim joa-quim May 26, 2022 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imagine there is an error before the gmt inset end call?
What I know is that there are still some of these shits that manage to survive and there are cases where I'm forced to call a gmt("destroy") to workaround the unknown trouble.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I dont mind. So you think gmt_end (which is called by GMT_Destroy_Session) is the place then?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, probably gmt_end. It's the place where all this kind of stuff is undone.

@PaulWessel

Copy link
Copy Markdown
Contributor Author

As I look at this a bit more, note that this is also a better way to determine the inset: Let gmt inset decide from the -R -J:

gmt begin map
    gmt coast -R-74/-69.5/41/43 -JM15c -Baf -Wthin -Clightblue -Glightyellow
    gmt inset begin -DjBL+o0.5c/0.2c -F+pblack+gwhite -R-80/-65/35/50 -JM3c
        gmt coast -Ggray -Cwhite -EUS.MA+gred -W1/thin -N1 -N2
    gmt inset end
gmt end show

Here, -D does not specify the size but we give the desired -R -J and now the inset is computed correctly with a tight fit. If you dont want a width of 3c but a height of 3c then you append +dh to -J, for instance.

In the original user's case, this is the preferred way of doing things. But, this PR is still useful since it fixes a bug.

@PaulWessel

Copy link
Copy Markdown
Contributor Author

We have one failure (insetlegend.sh) so I will check that one before this can be merged or revised.

@PaulWessel

Copy link
Copy Markdown
Contributor Author

I will let @seisman give this branch a test tonight/tomorrow before merging.

@seisman

seisman commented May 27, 2022

Copy link
Copy Markdown
Member
gmt begin map
    gmt coast -R-74/-69.5/41/43 -JM15c -Baf -Wthin -Clightblue -Glightyellow
    gmt inset begin -DjBL+o0.5c/0.2c -F+pblack+gwhite -R-80/-65/35/50 -JM3c
        gmt coast -Ggray -Cwhite -EUS.MA+gred -W1/thin -N1 -N2
    gmt inset end
gmt end show

Great! It's definitely a better solution!


Just want to let you know that inset may not works well in subplot, as shown by the script below. But I think it can be addressed in a separate PR instead.

gmt begin map
	gmt subplot begin 1x2 -Fs15c/15c
	gmt subplot set 0
		gmt coast -R-74/-69.5/41/43 -JM? -Baf -Wthin -Clightblue -Glightyellow
		gmt inset begin -DjBL+o0.5c/0.2c -F+pblack+gwhite+c0.2c/0.2c -R-80/-65/35/50 -JM3c
			gmt coast -Ggray -Cwhite -EUS.MA+gred -W1/thin -N1 -N2
	    gmt inset end
	gmt subplot set 1
		gmt coast -R-74/-69.5/41/43 -JM? -Baf -Wthin -Clightblue -Glightyellow
	    gmt inset begin -DjBL+o0.5c/0.2c -F+pblack+gwhite+c0.2c/0.2c -R-80/-65/35/50 -JM3c
		    gmt coast -Ggray -Cwhite -EUS.MA+gred -W1/thin -N1 -N2
	    gmt inset end
    gmt subplot end
gmt end show

map

@seisman

seisman commented May 27, 2022

Copy link
Copy Markdown
Member

Just realized that the inset in subplot issue was already reported in #6415. I'll repost the example there.

@PaulWessel

Copy link
Copy Markdown
Contributor Author

Thanks @seisman - we will look at the old sublot + inset issues separately. OK to merge this PR though?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants