changeset 26311:3592ad04b0c6 stable

Fix unexpected "xlim" error when re-parenting hggroup (bug #55308). * graphics.cc (axes::update_axis_limits (string, graphics_handle): Declare limits to be a 1x2 Matrix. Re-define FIX_LIMITS macro to work with only two elements since axes object does not maintain a 1x4 vector for axes limits. Remove resize calls on "limits" matrix. * graphics.cc (axes::update_axis_limits (string)): Add FIXME about unneccessary calls to this function degrading graphics performance. * test/bug-55308/bug-55308.tst: Add fixed test for re-parenting. * test/bug-55308/module.mk: Add fixed test to build system.
author Rik <rik@octave.org>
date Thu, 27 Dec 2018 15:38:42 -0800
parents 44670b45ff3b
children dacba8a503d8
files libinterp/corefcn/graphics.cc test/bug-55308/bug-55308.tst test/bug-55308/module.mk
diffstat 3 files changed, 44 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/graphics.cc	Thu Dec 27 11:21:50 2018 +0100
+++ b/libinterp/corefcn/graphics.cc	Thu Dec 27 15:38:42 2018 -0800
@@ -8175,33 +8175,16 @@
 
   char update_type = 0;
 
-  Matrix limits;
+  Matrix limits (1, 2);
   double val;
 
-#define FIX_LIMITS                              \
-  if (limits.numel () == 4)                     \
-    {                                           \
-      val = limits(0);                          \
-      if (octave::math::isfinite (val))         \
-        min_val = val;                          \
-      val = limits(1);                          \
-      if (octave::math::isfinite (val))         \
-        max_val = val;                          \
-      val = limits(2);                          \
-      if (octave::math::isfinite (val))         \
-        min_pos = val;                          \
-      val = limits(3);                          \
-      if (octave::math::isfinite (val))         \
-        max_neg = val;                          \
-    }                                           \
-  else                                          \
-    {                                           \
-      limits.resize (4, 1);                     \
-      limits(0) = min_val;                      \
-      limits(1) = max_val;                      \
-      limits(2) = min_pos;                      \
-      limits(3) = max_neg;                      \
-    }
+#define FIX_LIMITS                          \
+  val = limits(0);                          \
+  if (octave::math::isfinite (val))         \
+    min_val = val;                          \
+  val = limits(1);                          \
+  if (octave::math::isfinite (val))         \
+    max_val = val;
 
   if (axis_type == "xdata" || axis_type == "xscale"
       || axis_type == "xlimmode" || axis_type == "xliminclude"
@@ -8267,7 +8250,7 @@
       else
         {
           // FIXME: get_children_limits is only needed here in order to know
-          // if there are 3D children. Is there a way to avoid this call?
+          // if there are 3D children.  Is there a way to avoid this call?
           get_children_limits (min_val, max_val, min_pos, max_neg, kids, 'z');
 
           xproperties.set_has3Dkids ((max_val - min_val) >
@@ -8300,14 +8283,11 @@
               min_val -= 1;
             }
 
-          limits.resize (1, 2);
-
           limits(0) = min_val;
           limits(1) = max_val;
 
           update_type = 'c';
         }
-
     }
   else if (axis_type == "alphadata" || axis_type == "alimmode"
            || axis_type == "alphadatamapping" || axis_type == "aliminclude"
@@ -8328,14 +8308,11 @@
           else if (min_val == max_val)
             max_val = min_val + 1;
 
-          limits.resize (1, 2);
-
           limits(0) = min_val;
           limits(1) = max_val;
 
           update_type = 'a';
         }
-
     }
 
 #undef FIX_LIMITS
@@ -8389,6 +8366,9 @@
   xproperties.update_transform ();
 }
 
+// FIXME: This function is called repeatedly while the axes are being set up.
+// There is probably some way to make this more efficient.
+
 void
 axes::update_axis_limits (const std::string& axis_type)
 {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/bug-55308/bug-55308.tst	Thu Dec 27 15:38:42 2018 -0800
@@ -0,0 +1,28 @@
+## Copyright (C) 2018 Rik Wehbring
+##
+## This file is part of Octave.
+##
+## Octave is free software: you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation, either version 3 of the License, or
+## (at your option) any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Octave; see the file COPYING.  If not, see
+## <https://www.gnu.org/licenses/>.
+
+%!test
+%! hf = figure ("visible", "off");
+%! unwind_protect
+%!   hg = hggroup ();
+%!   axis ([-2, 2, -2, 2]);
+%!   hl = line ([0;1], [0;0], "color", "r");
+%!   set (hl, "parent", hg);
+%! unwind_protect_cleanup
+%!   close (hf);
+%! end_unwind_protect
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/bug-55308/module.mk	Thu Dec 27 15:38:42 2018 -0800
@@ -0,0 +1,4 @@
+bug_55308_TEST_FILES = \
+  %reldir%/bug-55308.tst
+
+TEST_FILES += $(bug_55308_TEST_FILES)