diff scripts/plot/draw/patch.m @ 30634:36d940c58c2e

Improve input validation for patch function (bug #61782) * patch.m: Avoid call to gca() before executing __patch__ as input validation may stop patch from being created leaving empty figure and axes objects. Add BIST tests for input validation. * __patch__.m: Remove second output of function (failed). Detect 3-input case with bad color specification and issue and emit an error. Add comments to clarify code about which input combination is being processed in long if/elseif tree. Call gca() if patch is validated but no axes has been specified. * fill.m: Re-write call to __patch__ to match new function with only one output.
author Rik <rik@octave.org>
date Tue, 11 Jan 2022 12:17:16 -0800
parents 796f54d4ddbf
children ed7b17c7ddf3
line wrap: on
line diff
--- a/scripts/plot/draw/patch.m	Tue Jan 11 20:43:58 2022 +0100
+++ b/scripts/plot/draw/patch.m	Tue Jan 11 12:17:16 2022 -0800
@@ -28,7 +28,7 @@
 ## @deftypefnx {} {} patch (@var{x}, @var{y}, @var{c})
 ## @deftypefnx {} {} patch (@var{x}, @var{y}, @var{z}, @var{c})
 ## @deftypefnx {} {} patch ("Faces", @var{faces}, "Vertices", @var{verts}, @dots{})
-## @deftypefnx {} {} patch (@dots{}, @var{prop}, @var{val}, @dots{})
+## @deftypefnx {} {} patch (@dots{}, "@var{prop}", @var{val}, @dots{})
 ## @deftypefnx {} {} patch (@dots{}, @var{propstruct}, @dots{})
 ## @deftypefnx {} {} patch (@var{hax}, @dots{})
 ## @deftypefnx {} {@var{h} =} patch (@dots{})
@@ -82,17 +82,11 @@
 
   [hax, varargin] = __plt_get_axis_arg__ ("patch", varargin{:});
 
-  if (isempty (hax))
-    hax = gca ();
-  else
+  if (! isempty (hax))
     hax = hax(1);
-  endif
+  endif 
 
-  [htmp, failed] = __patch__ (hax, varargin{:});
-
-  if (failed)
-    print_usage ();
-  endif
+  htmp = __patch__ (hax, varargin{:});
 
   if (nargout > 0)
     h = htmp;
@@ -308,3 +302,9 @@
 %! unwind_protect_cleanup
 %!   close (hf);
 %! end_unwind_protect
+
+## Test input validation
+%!error <invalid color specification C> patch (1, 1, 'x')
+%!error <invalid TrueColor data C> patch (1, 1, rand (1,2,3))
+%!error <size of X, Y, and C must be equal> patch (1, 1, [1, 2])
+%!error <invalid color specification C> patch (1, 1, {1})