changeset 10354:f074aa6b2c80

__contour__: don't fail if zlevel is a vector with all the same values
author John W. Eaton <jwe@octave.org>
date Wed, 24 Feb 2010 23:54:32 -0500
parents 7ed1f2e831ba
children f9347eac65dc
files scripts/ChangeLog scripts/plot/private/__contour__.m
diffstat 2 files changed, 25 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog	Wed Feb 24 16:53:46 2010 -0500
+++ b/scripts/ChangeLog	Wed Feb 24 23:54:32 2010 -0500
@@ -1,3 +1,9 @@
+2010-02-24  John W. Eaton  <jwe@octave.org>
+
+	* plot/private/__contour__.m (get_lvl_eps): New function.
+	Handle case of single level value.  Use sqrt (eps) instead of 1e-6.
+	(update_text, add_patch_children): Use it.
+
 2010-02-19  Rik <octave@nomad.inbox5.com>
 
 	* optimization/fzero.m: Add test for discontinuity at the end.
--- a/scripts/plot/private/__contour__.m	Wed Feb 24 16:53:46 2010 -0500
+++ b/scripts/plot/private/__contour__.m	Wed Feb 24 23:54:32 2010 -0500
@@ -229,11 +229,8 @@
   endif
 
   if (strcmpi (filled, "on"))
-    if (diff (lev) < 10*eps) 
-      lvl_eps = 1e-6;
-    else
-      lvl_eps = min (diff (lev)) / 1000.0;
-    endif
+
+    lvl_eps = get_lvl_eps (lev);
 
     ## Decode contourc output format.
     i1 = 1;
@@ -483,11 +480,7 @@
     elseif (strcmpi (get (h, "textstepmode"), "manual"))
       lev = get (h, "levellist");
 
-      if (diff (lev) < 10*eps) 
-	lvl_eps = 1e-6;
-      else
-	lvl_eps = min (abs (diff (lev))) / 1000.0;
-      endif
+      lvl_eps = get_lvl_eps (lev);
 
       stp = get (h, "textstep");
       t = [0, floor(cumsum(diff (lev)) / (abs(stp) - lvl_eps))];
@@ -515,3 +508,19 @@
 
   recursive = false;
 endfunction
+
+function lvl_eps = get_lvl_eps (lev)
+  ## FIXME -- is this the right thing to do for this tolerance?  Should
+  ## it be an absolute or relative tolerance, or switch from one to the
+  ## other depending on the value of lev?
+  if (isscalar (lev))
+    lvl_eps = abs (lev) * sqrt (eps);
+  else
+    tmp = min (abs (diff (lev)));
+    if (tmp < 10*eps) 
+      lvl_eps = sqrt (eps);
+    else
+      lvl_eps = tmp / 1000.0;
+    endif
+  endif
+endfunction