# HG changeset patch
# User Colin Macdonald <cbm@m.fsf.org>
# Date 1454303108 28800
#      Sun Jan 31 21:05:08 2016 -0800
# Node ID a48471a3d649eacf4a83772144a395aa8afe8f85
# Parent  446bab5da2f755b5697d6334563b6c802378acfd
fix regression for coordinate transforms on 3D arrays

The ismatrix changes from 4.0 caused a regression here.  I
replaced these calls with isnumeric.  The meaning is not quite
the as ismatrix was previously true for logical and char: but
there is little reason to support those here (anyone calling
cart2sph on a char almost certainly has a bug!).

diff -r 446bab5da2f7 -r a48471a3d649 scripts/general/cart2pol.m
--- a/scripts/general/cart2pol.m	Sun Jan 31 21:23:12 2016 +0100
+++ b/scripts/general/cart2pol.m	Sun Jan 31 21:05:08 2016 -0800
@@ -1,4 +1,4 @@
-## Copyright (C) 2000-2015 Kai Habel
+## Copyright (C) 2000-2016 Kai Habel
 ##
 ## This file is part of Octave.
 ##
@@ -59,16 +59,16 @@
       error ("cart2pol: matrix input must have 2 or 3 columns [X, Y (, Z)]");
     endif
   elseif (nargin == 2)
-    if (! ((ismatrix (x) && ismatrix (y))
+    if (! ((isnumeric (x) && isnumeric (y))
             && (size_equal (x, y) || isscalar (x) || isscalar (y))))
-      error ("cart2pol: arguments must be matrices of same size, or scalar");
+      error ("cart2pol: arguments must be arrays of same size, or scalar");
     endif
   elseif (nargin == 3)
-    if (! ((ismatrix (x) && ismatrix (y) && ismatrix (z))
+    if (! ((isnumeric (x) && isnumeric (y) && isnumeric (z))
             && (size_equal (x, y) || isscalar (x) || isscalar (y))
             && (size_equal (x, z) || isscalar (x) || isscalar (z))
             && (size_equal (y, z) || isscalar (y) || isscalar (z))))
-      error ("cart2pol: arguments must be matrices of same size, or scalar");
+      error ("cart2pol: arguments must be arrays of same size, or scalar");
     endif
   endif
 
@@ -142,3 +142,32 @@
 %! P = [0, 0, 0; pi/4, sqrt(2), 1; pi/4, 2*sqrt(2), 2];
 %! assert (cart2pol (C), P, sqrt (eps));
 
+%!test
+%! x = zeros (1, 1, 1, 2);
+%! x(1, 1, 1, 2) = sqrt (2);
+%! y = x;
+%! [t, r] = cart2pol (x, y);
+%! T = zeros (1, 1, 1, 2);
+%! T(1, 1, 1, 2) = pi/4;
+%! R = zeros (1, 1, 1, 2);
+%! R(1, 1, 1, 2) = 2;
+%! assert (t, T, eps);
+%! assert (r, R, eps);
+
+%!test
+%! [x, y, Z] = meshgrid ([0, 1], [0, 1], [0, 1]);
+%! [t, r, z] = cart2pol (x, y, Z);
+%! T(:, :, 1) = [0, 0; pi/2, pi/4];
+%! T(:, :, 2) = T(:, :, 1);
+%! R = sqrt (x.^2 + y.^2);
+%! assert (t, T, eps);
+%! assert (r, R, eps);
+%! assert (z, Z);
+
+%!error cart2pol (rand (3, 3, 3), 0, rand (3, 2, 3))
+
+%!error cart2pol (rand (3, 3, 3), 0, rand (3, 3))
+
+%!error cart2pol (rand (3, 3, 3), rand (3, 2, 3))
+
+%!error cart2pol (rand (3, 3, 3), rand (3, 3))
diff -r 446bab5da2f7 -r a48471a3d649 scripts/general/cart2sph.m
--- a/scripts/general/cart2sph.m	Sun Jan 31 21:23:12 2016 +0100
+++ b/scripts/general/cart2sph.m	Sun Jan 31 21:05:08 2016 -0800
@@ -1,4 +1,4 @@
-## Copyright (C) 2000-2015 Kai Habel
+## Copyright (C) 2000-2016 Kai Habel
 ##
 ## This file is part of Octave.
 ##
@@ -56,11 +56,11 @@
       error ("cart2sph: matrix input must have 3 columns [X, Y, Z]");
     endif
   elseif (nargin == 3)
-    if (! ((ismatrix (x) && ismatrix (y) && ismatrix (z))
+    if (! ((isnumeric (x) && isnumeric (y) && isnumeric (z))
             && (size_equal (x, y) || isscalar (x) || isscalar (y))
             && (size_equal (x, z) || isscalar (x) || isscalar (z))
             && (size_equal (y, z) || isscalar (y) || isscalar (z))))
-      error ("cart2sph: X, Y, Z must be matrices of the same size, or scalar");
+      error ("cart2sph: X, Y, Z must be arrays of the same size, or scalar");
     endif
   endif
 
@@ -116,3 +116,18 @@
 %! S = [0, 0, 0; 0, pi/4, sqrt(2); 0, pi/4, 2*sqrt(2)];
 %! assert (cart2sph (C), S, eps);
 
+%!test
+%! [x, y, z] = meshgrid ([0, 1], [0, 1], [0, 1]);
+%! [t, p, r] = cart2sph (x, y, z);
+%! T(:, :, 1) = [0, 0; pi/2, pi/4];
+%! T(:, :, 2) = T(:, :, 1);
+%! P(:, :, 1) = zeros (2, 2);
+%! P(:, :, 2) = [pi/2, pi/4; pi/4, acos(sqrt(2/3))];
+%! R = sqrt (x .^ 2 + y .^ 2 + z .^ 2);
+%! assert (t, T, eps);
+%! assert (p, P, eps);
+%! assert (r, R, eps);
+
+%!error cart2sph (rand (3, 3, 3), 0, rand (3, 2, 3))
+
+%!error cart2sph (rand (3, 3, 3), 0, rand (3, 3))
diff -r 446bab5da2f7 -r a48471a3d649 scripts/general/pol2cart.m
--- a/scripts/general/pol2cart.m	Sun Jan 31 21:23:12 2016 +0100
+++ b/scripts/general/pol2cart.m	Sun Jan 31 21:05:08 2016 -0800
@@ -1,4 +1,4 @@
-## Copyright (C) 2000-2015 Kai Habel
+## Copyright (C) 2000-2016 Kai Habel
 ##
 ## This file is part of Octave.
 ##
@@ -59,16 +59,16 @@
       error ("pol2cart: matrix input must have 2 or 3 columns [THETA, R (, Z)]");
     endif
   elseif (nargin == 2)
-    if (! ((ismatrix (theta) && ismatrix (r))
+    if (! ((isnumeric (theta) && isnumeric (r))
             && (size_equal (theta, r) || isscalar (theta) || isscalar (r))))
-      error ("pol2cart: arguments must be matrices of same size, or scalar");
+      error ("pol2cart: arguments must be arrays of same size, or scalar");
     endif
   elseif (nargin == 3)
-    if (! ((ismatrix (theta) && ismatrix (r) && ismatrix (z))
+    if (! ((isnumeric (theta) && isnumeric (r) && isnumeric (z))
             && (size_equal (theta, r) || isscalar (theta) || isscalar (r))
             && (size_equal (theta, z) || isscalar (theta) || isscalar (z))
             && (size_equal (r, z) || isscalar (r) || isscalar (z))))
-      error ("pol2cart: arguments must be matrices of same size, or scalar");
+      error ("pol2cart: arguments must be arrays of same size, or scalar");
     endif
   endif
 
@@ -142,3 +142,35 @@
 %! C = [0, 0, 0; 1, 1, 1; 2, 2, 2];
 %! assert (pol2cart (P), C, sqrt (eps));
 
+%!test
+%! r = ones (1, 1, 1, 2);
+%! r(1, 1, 1, 2) = 2;
+%! t = pi/2 * r;
+%! [x, y] = pol2cart (t, r);
+%! X = zeros (1, 1, 1, 2);
+%! X(1, 1, 1, 2) = -2;
+%! Y = zeros (1, 1, 1, 2);
+%! Y(1, 1, 1, 1) = 1;
+%! assert (x, X, 2*eps);
+%! assert (y, Y, 2*eps);
+
+%!test
+%! [t, r, Z] = meshgrid ([0, pi/2], [1, 2], [0, 1]);
+%! [x, y, z] = pol2cart (t, r, Z);
+%! X = zeros(2, 2, 2);
+%! X(:, 1, 1) = [1; 2];
+%! X(:, 1, 2) = [1; 2];
+%! Y = zeros(2, 2, 2);
+%! Y(:, 2, 1) = [1; 2];
+%! Y(:, 2, 2) = [1; 2];
+%! assert (x, X, eps);
+%! assert (y, Y, eps);
+%! assert (z, Z);
+
+%!error pol2cart (rand (3, 3, 3), 0, rand (3, 2, 3))
+
+%!error pol2cart (rand (3, 3, 3), 0, rand (3, 3))
+
+%!error pol2cart (rand (3, 3, 3), rand (3, 2, 3))
+
+%!error pol2cart (rand (3, 3, 3), rand (3, 3))
diff -r 446bab5da2f7 -r a48471a3d649 scripts/general/sph2cart.m
--- a/scripts/general/sph2cart.m	Sun Jan 31 21:23:12 2016 +0100
+++ b/scripts/general/sph2cart.m	Sun Jan 31 21:05:08 2016 -0800
@@ -1,4 +1,4 @@
-## Copyright (C) 2000-2015 Kai Habel
+## Copyright (C) 2000-2016 Kai Habel
 ##
 ## This file is part of Octave.
 ##
@@ -56,11 +56,11 @@
       error ("sph2cart: matrix input must have 3 columns [THETA, PHI, R]");
     endif
   elseif (nargin == 3)
-    if (! ((ismatrix (theta) && ismatrix (phi) && ismatrix (r))
+    if (! ((isnumeric (theta) && isnumeric (phi) && isnumeric (r))
             && (size_equal (theta, phi) || isscalar (theta) || isscalar (phi))
             && (size_equal (theta, r) || isscalar (theta) || isscalar (r))
             && (size_equal (phi, r) || isscalar (phi) || isscalar (r))))
-      error ("sph2cart: THETA, PHI, and R must be matrices of the same size, or scalar");
+      error ("sph2cart: THETA, PHI, and R must be arrays of the same size, or scalar");
     endif
   endif
 
@@ -116,3 +116,19 @@
 %! C = [ 1, 0, 0; 0, 1, 0; -1, 0, 0];
 %! assert (sph2cart (S), C, eps);
 
+%!test
+%! [t, p, r] = meshgrid ([0, pi/2], [0, pi/2], [0, 1]);
+%! [x, y, z] = sph2cart (t, p, r);
+%! X = zeros(2, 2, 2);
+%! X(1, 1, 2) = 1;
+%! Y = zeros(2, 2, 2);
+%! Y(1, 2, 2) = 1;
+%! Z = zeros(2, 2, 2);
+%! Z(2, :, 2) = [1 1];
+%! assert (x, X, eps);
+%! assert (y, Y, eps);
+%! assert (z, Z);
+
+%!error sph2cart (rand (3, 3, 3), 0, rand (3, 2, 3))
+
+%!error sph2cart (rand (3, 3, 3), 0, rand (3, 3))
