# HG changeset patch
# User Markus Mützel <markus.muetzel@gmx.de>
# Date 1549225997 -3600
#      Sun Feb 03 21:33:17 2019 +0100
# Node ID 6db906e66fe2fb96f6f0833a56d31230d1ef3bee
# Parent  879f22ca59c8cced23e52ea19e938fa0176508f0
Improve calculation of zlim and aspect ratios for 2d lines (bug #55634).

* graphics.in.h (line::properties): Change default value for hidden zlim
  property. Always include zlim of line in axes zlim calculation.

* graphics.cc: (default_line_zlim): Add new function.
  (normalized_aspectratios, axes::properties::update_aspectratios): Don't
  include z axis span for calculation of aspect ratios in 2d plots.

diff -r 879f22ca59c8 -r 6db906e66fe2 libinterp/corefcn/graphics.cc
--- a/libinterp/corefcn/graphics.cc	Sun Feb 03 16:35:34 2019 +0100
+++ b/libinterp/corefcn/graphics.cc	Sun Feb 03 21:33:17 2019 +0100
@@ -308,6 +308,19 @@
 }
 
 static Matrix
+default_line_zlim (void)
+{
+  Matrix retval (1, 4);
+
+  retval(0) = -1;
+  retval(1) = 1;
+  retval(2) = octave::numeric_limits<double>::Inf ();
+  retval(3) = -octave::numeric_limits<double>::Inf ();
+
+  return retval;
+}
+
+static Matrix
 default_image_cdata (void)
 {
   Matrix m (64, 64);
@@ -6593,13 +6606,18 @@
 
 static void
 normalized_aspectratios (Matrix& aspectratios, const Matrix& scalefactors,
-                         double xlength, double ylength, double zlength)
+                         double xlength, double ylength, double zlength,
+                         bool is2D = false)
 {
   double xval = xlength / scalefactors(0);
   double yval = ylength / scalefactors(1);
   double zval = zlength / scalefactors(2);
 
-  double minval = octave::math::min (octave::math::min (xval, yval), zval);
+  double minval;
+  if (is2D)
+    minval = octave::math::min (xval, yval);
+  else
+    minval = octave::math::min (octave::math::min (xval, yval), zval);
 
   aspectratios(0) = xval / minval;
   aspectratios(1) = yval / minval;
@@ -6656,12 +6674,12 @@
           plotboxaspectratio.set (pba, false);
         }
 
-      normalized_aspectratios (da, pba, dx, dy, dz);
+      normalized_aspectratios (da, pba, dx, dy, dz, get_is2D ());
       dataaspectratio.set (da, false);
     }
   else if (plotboxaspectratiomode_is ("auto"))
     {
-      normalized_aspectratios (pba, da, dx, dy, dz);
+      normalized_aspectratios (pba, da, dx, dy, dz, get_is2D ());
       plotboxaspectratio.set (pba, false);
     }
   else
@@ -6676,7 +6694,8 @@
           kids = get_children ();
           max_axes_scale (s, xlimits, kids, pba(0), da(0), 'x', true);
           max_axes_scale (s, ylimits, kids, pba(1), da(1), 'y', true);
-          max_axes_scale (s, zlimits, kids, pba(2), da(2), 'z', true);
+          if (! get_is2D ())
+            max_axes_scale (s, zlimits, kids, pba(2), da(2), 'z', true);
         }
       else if (xlimmode_is ("auto") && ylimmode_is ("auto"))
         {
@@ -6705,7 +6724,12 @@
           dy = pba(1) * da(1);
           dz = pba(2) * da(2);
           if (octave::math::isinf (s))
-            s = 1 / octave::math::min (octave::math::min (dx, dy), dz);
+            {
+              if (get_is2D ())
+                s = 1 / octave::math::min (dx, dy);
+              else
+                s = 1 / octave::math::min (octave::math::min (dx, dy), dz);
+            }
 
           if (xlimmode_is ("auto"))
             {
@@ -6736,7 +6760,7 @@
         }
       else
         {
-          normalized_aspectratios (pba, da, dx, dy, dz);
+          normalized_aspectratios (pba, da, dx, dy, dz, get_is2D ());
           plotboxaspectratio.set (pba, false);
         }
     }
diff -r 879f22ca59c8 -r 6db906e66fe2 libinterp/corefcn/graphics.in.h
--- a/libinterp/corefcn/graphics.in.h	Sun Feb 03 16:35:34 2019 +0100
+++ b/libinterp/corefcn/graphics.in.h	Sun Feb 03 21:33:17 2019 +0100
@@ -4248,10 +4248,10 @@
       // hidden properties for limit computation
       row_vector_property xlim hlr , Matrix ()
       row_vector_property ylim hlr , Matrix ()
-      row_vector_property zlim hlr , Matrix ()
+      row_vector_property zlim hlr , default_line_zlim ()
       bool_property xliminclude hl , "on"
       bool_property yliminclude hl , "on"
-      bool_property zliminclude hl , "off"
+      bool_property zliminclude hl , "on"
     END_PROPERTIES
 
   protected:
@@ -4269,11 +4269,7 @@
 
     void update_ydata (void) { set_ylim (compute_ylim ()); }
 
-    void update_zdata (void)
-    {
-      set_zlim (zdata.get_limits ());
-      set_zliminclude (get_zdata ().numel () > 0);
-    }
+    void update_zdata (void) { set_zlim (zdata.get_limits ()); }
   };
 
 private:
