diff scripts/image/image.m @ 18899:3d9e503aea2c

Update image "x/ydata" when "cdata" is changed (bug #42121) * graphics.in.h (image::properties): add two hidden properties "xdatamode" and "ydatamode" * graphics.in.h (image::properties): modify properties "xdata" and "ydata" so that their respective *mode is updated * graphics.in.h (image::properties::update_cdata): setting "cdata" updates "x/ydata" when "x/ydatamode" is "auto" * graphics.in.h (image::properties::update_x/ydata): setting "x/ydata" to empty matrix updates "x/ydata" to [1 npix] and changes "x/ydatamode" to "auto" * graphics.in.h (image::properties::auto_xdata (void), image::properties::auto_ydata (void)): new functions to compute auto x/ydata * image.m (__img__): don't replace empty "x/ydata" in order to use new behavior * image.m: add test for bug #42121
author Pantxo Diribarne <pantxo.diribarne@gmail.com>
date Mon, 14 Apr 2014 22:53:44 +0200
parents 87c3848cf3c0
children 68db8396c378
line wrap: on
line diff
--- a/scripts/image/image.m	Fri Jul 04 21:40:50 2014 -0700
+++ b/scripts/image/image.m	Mon Apr 14 22:53:44 2014 +0200
@@ -144,16 +144,17 @@
   if (! isempty (img))
 
     if (isempty (x))
-      x = [1, columns(img)];
+      xdata = [];
+    else
+      xdata = x([1, end])(:).';  # (:).' is a hack to guarantee row vector
     endif
 
     if (isempty (y))
-      y = [1, rows(img)];
+      ydata = [];
+    else
+      ydata = y([1, end])(:).';
     endif
 
-    xdata = x([1, end])(:).';  # (:).' is a hack to guarantee row vector
-    ydata = y([1, end])(:).';
-
     if (numel (x) > 2 && numel (y) > 2)
       ## Test data for non-linear spacing which is unsupported
       tol = .01;  # 1% tolerance.  FIXME: this value was chosen without thought.
@@ -220,4 +221,31 @@
 %!  h = image (-x, -y, img);
 %!  title ("image (-x, -y, img)");
 
+%!test
+%! ## test hidden properties x/ydatamode (bug #42121)
+%! hf = figure ("visible", "off");
+%! unwind_protect
+%!   nx = 64; ny = 64;
+%!   cdata = rand (ny, nx)*127;
+%!   hi = image (cdata);             # x/ydatamode is auto
+%!   assert (get (hi, "xdata"), [1 nx])
+%!   assert (get (hi, "ydata"), [1 ny])
+%!   set (hi, "cdata", cdata(1:2:end, 1:2:end))
+%!   assert (get (hi, "xdata"), [1 nx/2])
+%!   assert (get (hi, "ydata"), [1 ny/2])
+%! 
+%!   set (hi, "xdata", [10 100])     # xdatamode is now manual
+%!   set (hi, "ydata", [10 1000])    # ydatamode is now manual
+%!   set (hi, "cdata", cdata)
+%!   assert (get (hi, "xdata"), [10 100])
+%!   assert (get (hi, "ydata"), [10 1000])
+%! 
+%!   set (hi, "ydata", [])           # ydatamode is now auto
+%!   set (hi, "cdata", cdata(1:2:end, 1:2:end))
+%!   assert (get (hi, "xdata"), [10 100])
+%!   assert (get (hi, "ydata"), [1 ny/2])
+%! unwind_protect_cleanup
+%!   close (hf)
+%! end_unwind_protect
+
 ## FIXME: Need %!tests for linear