changeset 33474:e7feb17db34e

view.m: Produce compatible viewpoint for z-vector input (bug #65641). * view.m: Add check for z-axis aligned viewpoint and force ouput to an azimuth of +0. Add BIST to check compatible output for [+/-0, +/-0, +/-1] inputs.
author Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
date Fri, 26 Apr 2024 15:40:10 -0400
parents c35b564573db
children 7451f7f896d3 0fbf06e4b460
files scripts/plot/appearance/view.m
diffstat 1 files changed, 31 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/plot/appearance/view.m	Fri Apr 26 20:45:13 2024 +0200
+++ b/scripts/plot/appearance/view.m	Fri Apr 26 15:40:10 2024 -0400
@@ -79,6 +79,13 @@
       if (x(2) == 0)
         ## special case for negative 0
         [az, el] = cart2sph (x(2), x(1), x(3));
+
+        if (x(1) == 0)
+          ## Compatability change to force +0 azimuth instead of +/-0 or
+          ## +/-180deg azimuth for z-aligned vector.
+          az = 0;
+        endif
+
       else
         [az, el] = cart2sph (-x(2), x(1), x(3));
       endif
@@ -181,6 +188,30 @@
 %!   close (hf);
 %! end_unwind_protect
 
+%!test <*65641> # Verify compatible z-vector viewpoint.
+%! hf = figure ("visible", "off");
+%! unwind_protect
+%!   ml_out = [0, 90, Inf] .* ones (8, 1);
+%!   ml_out(1:2:end-1, 2) = -90;
+%!   output = NaN (8, 3);
+%!   plot3 ([0,1], [0,1], [0,1]);
+%!   idx = 1;
+%!   for x1 = [-0, 0]
+%!     for x2 = [-0, 0]
+%!       for x3 = [-1, 1]
+%!         view ([x1, x2, x3]);
+%!         [az, el] = view ();
+%!         output(idx, :) = [az, el, 1/az];
+%!         idx++;
+%!       endfor
+%!     endfor
+%!   endfor
+%!   assert (isequaln (output, ml_out));
+%! unwind_protect_cleanup
+%!   close (hf);
+%! end_unwind_protect
+
+
 ## Test input validation
 %!error <Invalid call> view (0, 0, 1)
 %!error <cannot simultaneously get and set> [a, b] = view ([1, 1, 1])