From 0a27ca6b47ff0e65662c44398623ed56a216c6a2 Mon Sep 17 00:00:00 2001 From: Esteban82 Date: Tue, 20 Oct 2026 10:37:20 -0300 Subject: [PATCH] Fix upside-down x/y annotations in perspective views gmt_xy_axis rotated x/y annotations by 180 degrees whenever cos(azimuth) > 0, which is only right for text running along the map x-direction. Annotations parallel to the y-axis (MAP_ANNOT_ORTHO without w/e), orthogonal x-axis annotations (MAP_ANNOT_ORTHO with s/n) and +a slanted ones came out upside down for some azimuths, e.g. the y annotations of -pz60/30 in test/psbasemap/rotalign.sh, the case reported in the old forum topic 7776. Decide the flip from the actual text angle: rotate when the projected text direction cos(angle + azimuth) points right-to-left, breaking exact ties so vertical text reads upward. For angle 0 this reproduces the old cos(az) > 0 test, so the default annotations are unchanged. Drop the known-failure flag from rotalign.sh and add its baseline. Co-Authored-By: Claude Opus 5.5 --- src/gmt_plot.c | 10 +++++++++- test/baseline/psbasemap.dvc | 6 +++--- test/psbasemap/rotalign.sh | 5 +---- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/gmt_plot.c b/src/gmt_plot.c index 7f71d825e6c..8dc27f8455b 100644 --- a/src/gmt_plot.c +++ b/src/gmt_plot.c @@ -5657,6 +5657,13 @@ void gmt_map_text (struct GMT_CTRL *GMT, double x, double y, struct GMT_FONT *fo PSL_plottext (PSL, x, y, font->size, label, angle, just, form); } +GMT_LOCAL bool gmtplot_upside_down_3D (struct GMT_CTRL *GMT, double angle) { + /* True if text at this x-y plane angle would read right-to-left (or downward) in the perspective view */ + double s, c; + sincosd (angle + GMT->current.proj.z_project.view_azimuth, &s, &c); + return (c > GMT_CONV8_LIMIT || (fabs (c) <= GMT_CONV8_LIMIT && s > 0.0)); +} + void gmt_xy_axis (struct GMT_CTRL *GMT, double x0, double y0, double length, double val0, double val1, struct GMT_PLOT_AXIS *A, bool below, unsigned side) { unsigned int k, i, nx, nx1, np = 0;/* Misc. variables */ unsigned int annot_pos; /* Either 0 for upper annotation or 1 for lower annotation */ @@ -5765,8 +5772,9 @@ void gmt_xy_axis (struct GMT_CTRL *GMT, double x0, double y0, double length, dou } } flip = (GMT->current.setting.map_frame_type & GMT_IS_INSIDE); /* Inside annotation */ - if (axis != GMT_Z && GMT->current.proj.three_D && GMT->current.proj.z_project.cos_az > 0) { /* Rotate x/y-annotations when seen "from North" */ + if (axis != GMT_Z && GMT->current.proj.three_D) { /* Rotate x/y-annotations that would appear upside down */ for (pr = GMT_PRIMARY; pr <= GMT_SECONDARY; pr++) { + if (!gmtplot_upside_down_3D (GMT, text_angle[pr])) continue; if (!flip) justify[pr] = gmt_flip_justify (GMT, justify[pr]); text_angle[pr] += 180.0; } diff --git a/test/baseline/psbasemap.dvc b/test/baseline/psbasemap.dvc index 2e6c774ab54..49c7ee0b956 100644 --- a/test/baseline/psbasemap.dvc +++ b/test/baseline/psbasemap.dvc @@ -1,6 +1,6 @@ outs: -- md5: ea7d3e81d00ae837430f398584d9fb7c.dir - nfiles: 59 +- md5: d415fbb0fff01cc3673b11ce5585b1ea.dir + nfiles: 60 path: psbasemap hash: md5 - size: 3023798 + size: 3059086 diff --git a/test/psbasemap/rotalign.sh b/test/psbasemap/rotalign.sh index cd83cb89528..e50acb2c267 100755 --- a/test/psbasemap/rotalign.sh +++ b/test/psbasemap/rotalign.sh @@ -1,8 +1,5 @@ #!/usr/bin/env bash -# GMT_KNOWN_FAILURE -# The failure pointed out in http://gmt.soest.hawaii.edu/boards/1/topics/7776 -# The axes labels and annotations are 180 out of phase. -# +# Check that x/y annotations and labels are not upside down in perspective views ps=rotalign.ps gmt set MAP_ANNOT_ORTHO ""