changeset 19645:ed4eeb4314e6

cubehelix: fix for the corner cases when N is 1 or 0.
author Carnë Draug <carandraug@octave.org>
date Fri, 23 Jan 2015 15:28:45 +0000
parents 965384560122
children 68cc16969f78
files scripts/image/cubehelix.m
diffstat 1 files changed, 20 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/image/cubehelix.m	Fri Jan 23 13:17:08 2015 +0000
+++ b/scripts/image/cubehelix.m	Fri Jan 23 15:28:45 2015 +0000
@@ -51,25 +51,30 @@
 
   if (nargin > 5)
     print_usage ()
-  endif
-
-  if (! isscalar (n) || n < 1)
-    error ("cubehelix: N must be a positive scalar");
+  elseif (! isscalar (n))
+    error ("cubehelix: N must be a scalar");
   endif
 
-  coeff = [ -0.14861  -0.29227   1.97294
-             1.78277  -0.90649   0.00000];
+  if (n > 1)
+    coeff = [ -0.14861  -0.29227   1.97294
+               1.78277  -0.90649   0.00000];
 
-  fract = ((0:n-1) / (n-1))';
-  angle = 2 * pi * (start/3 + 1 + rots*fract);
-  fract = fract .^ gamma;
-  amp   = hue * fract .* (1-fract) /2;
-  warning ("off", "Octave:broadcast", "local");
-  map   = fract + amp .* ([cos(angle) sin(angle)] * coeff);
+    fract = ((0:n-1) / (n-1))';
+    angle = 2 * pi * (start/3 + 1 + rots*fract);
+    fract = fract .^ gamma;
+    amp   = hue * fract .* (1-fract) /2;
+    warning ("off", "Octave:broadcast", "local");
+    map   = fract + amp .* ([cos(angle) sin(angle)] * coeff);
 
-  ## Clip values (only in case users have changed values of hue or gamma)
-  map(map < 0) = 0;
-  map(map > 1) = 1;
+    ## Clip values (only in case users have changed values of hue or gamma)
+    map(map < 0) = 0;
+    map(map > 1) = 1;
+
+  elseif (n > 0)
+    map = [0, 0, 0];
+  else
+    map = zeros (0, 3);
+  endif
 
 endfunction