Mercurial > octave
diff scripts/plot/draw/quiver.m @ 32062:ada96a467a28
quiver: Improve plotting with non-float numeric inputs (bug #59695)
* scripts/plot/draw/private/__quiver__.m: Change firstnonnumeric check to look
for char instead of numeric to allow for logical inputs. Recast all inputs
up to firstnonnumeric as doubles. Check if firstnonnumeric element is 'off'
and if so set scale factor to 0 and increment firstnonnumeric.
* scripts/plot/draw/quiver.m: Update docstring to include scaling factor
option 'off'. Add BIST for int and logical input types.
* scripts/plot/draw/quiver3.m: Update docstring to include scaling factor
option 'off'. Add BISTs for too-few inputs.
* etc/NEWS.9.md: Appended details of changes to quiver note under General
Improvements and noted it also applies to quiver3.
author | Nicholas R. Jankowski <jankowski.nicholas@gmail.com> |
---|---|
date | Wed, 26 Apr 2023 17:18:50 -0400 |
parents | 31f7f5359ba2 |
children | 03fe0b635d2e |
line wrap: on
line diff
--- a/scripts/plot/draw/quiver.m Wed Apr 26 16:29:28 2023 -0700 +++ b/scripts/plot/draw/quiver.m Wed Apr 26 17:18:50 2023 -0400 @@ -46,7 +46,7 @@ ## The optional input @var{s} is a scalar defining a scaling factor to use for ## the arrows of the field relative to the mesh spacing. A value of 1.0 will ## result in the longest vector exactly filling one grid square. A value of 0 -## disables all scaling. The default value is 0.9. +## or "off" disables all scaling. The default value is 0.9. ## ## The style to use for the plot can be defined with a line style @var{style} ## of the same format as the @code{plot} command. If a marker is specified @@ -198,7 +198,52 @@ %! close (hf); %! end_unwind_protect +%!test <*59695> # Check for proper plotting with non-float inputs. +%! hf = figure ("visible", "off"); +%! hax = gca (); +%! unwind_protect +%! h = quiver (int32(1), int32(1), int32(1), int32(1), double(0.5)); +%! childxdata = get (get (h, "children"), "xdata"); +%! childydata = get (get (h, "children"), "ydata"); +%! assert (all (strcmp (cellfun (... +%! 'class', childxdata, 'UniformOutput', false), "double"))); +%! assert (all (strcmp (cellfun (... +%! 'class', childydata, 'UniformOutput', false), "double"))); +%! assert (childxdata{2}(2) , 1.5, eps); +%! assert (childxdata{3}(2) , 1.5, eps); +%! assert (childydata{2}(2) , 1.5, eps); +%! assert (childydata{3}(2) , 1.5, eps); +%! +%! h = quiver (0.5, 0.5, 0.5, 0.5, int32(1)); +%! childxdata = get (get (h, "children"), "xdata"); +%! childydata = get (get (h, "children"), "ydata"); +%! assert (all (strcmp (cellfun (... +%! 'class', childxdata, 'UniformOutput', false), "double"))); +%! assert (all (strcmp (cellfun (... +%! 'class', childydata, 'UniformOutput', false), "double"))); +%! assert (childxdata{2}(2) , 1, eps); +%! assert (childxdata{3}(2) , 1, eps); +%! assert (childydata{2}(2) , 1, eps); +%! assert (childydata{3}(2) , 1, eps); +%! +%! h = quiver (false, true, false, true, true); +%! childxdata = get (get (h, "children"), "xdata"); +%! childydata = get (get (h, "children"), "ydata"); +%! assert (all (strcmp (cellfun (... +%! 'class', childxdata, 'UniformOutput', false), "double"))); +%! assert (all (strcmp (cellfun (... +%! 'class', childydata, 'UniformOutput', false), "double"))); +%! assert (childxdata{2}(2) , 0, eps); +%! assert (childxdata{3}(2) , 0, eps); +%! assert (childydata{2}(2) , 2, eps); +%! assert (childydata{3}(2) , 2, eps); +%! +%! unwind_protect_cleanup +%! close (hf); +%! end_unwind_protect + ## Test input validation %!error <Invalid call> quiver() -%!error <Invalid call> quiver(1) +%!error <Invalid call> quiver(1.1) +