Mercurial > octave
comparison scripts/plot/draw/quiver.m @ 32074:03fe0b635d2e
quiver/quiver3: Overhaul input processing, validation, and add BISTs.
* scripts/plot/draw/private/__quiver__.m: Overhaul numeric input validation.
Simplify input classification using numeric input count switch statements
and avoid quiver3 miscount due to scale factor. Add error messages for all
valid numeric input combinations including vector x,y,z and scale factor.
Move newplot command from quiver/quiver3 into __quiver__ after numeric input
validation. Add hax as an output argument to return any changes back to
calling function.
* scripts/plot/draw/quiver.m: Remove newplot call. Update __quiver__ call
to include hax as a return variable. Update docstring with note that line
style and name-value pairs can both be provided but linstyle must appear
first. Add BISTs to check standard inputs with single and multiple arrows,
arrowhead shape, vector and array inputs, proper treatment of scaling factor
"off", some simple input styles, and input validation BISTs to cover all
numeric input errors. Added known failing BIST for linestyle+pair
arrowhead showing when it should stay off (bug #64143).
* scripts/plot/draw/quiver3.m: Remove newplot call. Update __quiver__ call
to include hax as a return variable. Update docstring with note that line
style and name-value pairs can both be provided but linstyle must appear
first. Add BISTs to check standard inputs with single and multiple arrows,
vector and array inputs, and input validation BISTs to cover all numeric
input errors.
* etc/NEWS.9.md: Update quiver/quiver3 improvement description under General
Improvements.
author | Nicholas R. Jankowski <jankowski.nicholas@gmail.com> |
---|---|
date | Wed, 03 May 2023 22:52:33 -0400 |
parents | ada96a467a28 |
children | 7dcb6b4a4218 |
comparison
equal
deleted
inserted
replaced
32073:24752aa8be11 | 32074:03fe0b635d2e |
---|---|
34 ## | 34 ## |
35 ## Plot a 2-D vector field with arrows. | 35 ## Plot a 2-D vector field with arrows. |
36 ## | 36 ## |
37 ## Plot the (@var{u}, @var{v}) components of a vector field at the grid points | 37 ## Plot the (@var{u}, @var{v}) components of a vector field at the grid points |
38 ## defined by (@var{x}, @var{y}). If the grid is uniform then @var{x} and | 38 ## defined by (@var{x}, @var{y}). If the grid is uniform then @var{x} and |
39 ## @var{y} can be specified as vectors and @code{meshgrid} is used to create | 39 ## @var{y} can be specified as grid vectors and @code{meshgrid} is used to |
40 ## the 2-D grid. | 40 ## create the 2-D grid. |
41 ## | 41 ## |
42 ## If @var{x} and @var{y} are not given they are assumed to be | 42 ## If @var{x} and @var{y} are not given they are assumed to be |
43 ## @code{(1:@var{m}, 1:@var{n})} where | 43 ## @code{(1:@var{m}, 1:@var{n})} where |
44 ## @code{[@var{m}, @var{n}] = size (@var{u})}. | 44 ## @code{[@var{m}, @var{n}] = size (@var{u})}. |
45 ## | 45 ## |
46 ## The optional input @var{s} is a scalar defining a scaling factor to use for | 46 ## The optional input @var{s} is a scalar defining a scaling factor to use for |
47 ## the arrows of the field relative to the mesh spacing. A value of 1.0 will | 47 ## the arrows of the field relative to the mesh spacing. A value of 1.0 will |
48 ## result in the longest vector exactly filling one grid square. A value of 0 | 48 ## result in the longest vector exactly filling one grid square. A value of 0 |
49 ## or "off" disables all scaling. The default value is 0.9. | 49 ## or "off" disables all scaling. The default value is 0.9. |
50 ## | 50 ## |
51 ## The style to use for the plot can be defined with a line style @var{style} | 51 ## The style to use for the plot can be defined with a line style, @var{style}, |
52 ## of the same format as the @code{plot} command. If a marker is specified | 52 ## of the same format as the @code{plot} command. If a marker is specified |
53 ## then the markers are drawn at the origin of the vectors (which are the grid | 53 ## then the markers are drawn at the origin of the vectors (which are the grid |
54 ## points defined by @var{x} and @var{y}). When a marker is specified, the | 54 ## points defined by @var{x} and @var{y}). When a marker is specified, the |
55 ## arrowhead is not drawn. If the argument @qcode{"filled"} is given then the | 55 ## arrowhead is not drawn. If the argument @qcode{"filled"} is given then the |
56 ## markers are filled. | 56 ## markers are filled. If name-value plot style properties are used, they must |
57 ## appear in pairs and follow any other plot style arguments. | |
57 ## | 58 ## |
58 ## If the first argument @var{hax} is an axes handle, then plot into this axes, | 59 ## If the first argument @var{hax} is an axes handle, then plot into this axes, |
59 ## rather than the current axes returned by @code{gca}. | 60 ## rather than the current axes returned by @code{gca}. |
60 ## | 61 ## |
61 ## The optional return value @var{h} is a graphics handle to a quiver object. | 62 ## The optional return value @var{h} is a graphics handle to a quiver object. |
86 oldfig = []; | 87 oldfig = []; |
87 if (! isempty (hax)) | 88 if (! isempty (hax)) |
88 oldfig = get (0, "currentfigure"); | 89 oldfig = get (0, "currentfigure"); |
89 endif | 90 endif |
90 unwind_protect | 91 unwind_protect |
91 hax = newplot (hax); | 92 [hax, htmp] = __quiver__ (hax, false, varargin{:}); |
92 htmp = __quiver__ (hax, false, varargin{:}); | |
93 | 93 |
94 ## FIXME: This should be moved into __quiver__ when problem with | 94 ## FIXME: This should be moved into __quiver__ when problem with |
95 ## re-initialization of title object is fixed. | 95 ## re-initialization of title object is fixed. |
96 if (! ishold ()) | 96 if (! ishold ()) |
97 set (hax, "box", "on"); | 97 set (hax, "box", "on"); |
137 %! quiver (x, y, sin (theta)/10, cos (theta)/10, 0.4); | 137 %! quiver (x, y, sin (theta)/10, cos (theta)/10, 0.4); |
138 %! axis equal tight; | 138 %! axis equal tight; |
139 %! hold on; plot (x,y,"r"); hold off; | 139 %! hold on; plot (x,y,"r"); hold off; |
140 %! title ("quiver() with scaled arrows"); | 140 %! title ("quiver() with scaled arrows"); |
141 | 141 |
142 | 142 ## Check standard inputs, single arrow. |
143 %!test <*39552> # Check arrow length, scale factor adjustment, one arrow. | 143 %!test |
144 %! hf = figure ("visible", "off"); | |
145 %! hax = gca(); | |
146 %! unwind_protect | |
147 %! h = quiver (hax, 1, 2); | |
148 %! childxdata = get (get (h, "children"), "xdata"); | |
149 %! stemchild = find (cellfun (@numel, childxdata) == 3); | |
150 %! arrowheadchild = find (cellfun (@numel, childxdata) == 4); | |
151 %! assert (childxdata{stemchild}(1), 1, eps); | |
152 %! assert (childxdata{stemchild}(2), 1 + 1*0.9, eps); | |
153 %! assert (isnan (childxdata{stemchild}(3))); | |
154 %! assert (childxdata{arrowheadchild}(2), 1 + 1*0.9, eps); | |
155 %! assert (isnan (childxdata{arrowheadchild}(4))); | |
156 %! | |
157 %! h = quiver (hax, 1, 2, 0.5); | |
158 %! childxdata = get (get (h, "children"), "xdata"); | |
159 %! stemchild = find (cellfun (@numel, childxdata) == 3); | |
160 %! arrowheadchild = find (cellfun (@numel, childxdata) == 4); | |
161 %! assert (childxdata{stemchild}(1), 1, eps); | |
162 %! assert (childxdata{stemchild}(2), 1 + 1*0.5, eps); | |
163 %! assert (isnan (childxdata{stemchild}(3))); | |
164 %! assert (childxdata{arrowheadchild}(2), 1 + 1*0.5, eps); | |
165 %! assert (isnan (childxdata{arrowheadchild}(4))); | |
166 %! | |
167 %! h = quiver (hax, 0, 1, 2, 3); | |
168 %! childxdata = get (get (h, "children"), "xdata"); | |
169 %! stemchild = find (cellfun (@numel, childxdata) == 3); | |
170 %! arrowheadchild = find (cellfun (@numel, childxdata) == 4); | |
171 %! assert (childxdata{stemchild}(1), 0, eps); | |
172 %! assert (childxdata{stemchild}(2), 0 + 2*0.9, eps); | |
173 %! assert (isnan (childxdata{stemchild}(3))); | |
174 %! assert (childxdata{arrowheadchild}(2), 0 + 2*0.9, eps); | |
175 %! assert (isnan (childxdata{arrowheadchild}(4))); | |
176 %! | |
177 %! h = quiver (hax, 0, 1, 2, 3, 0.5); | |
178 %! childxdata = get (get (h, "children"), "xdata"); | |
179 %! stemchild = find (cellfun (@numel, childxdata) == 3); | |
180 %! arrowheadchild = find (cellfun (@numel, childxdata) == 4); | |
181 %! assert (childxdata{stemchild}(1), 0, eps); | |
182 %! assert (childxdata{stemchild}(2), 0 + 2*0.5, eps); | |
183 %! assert (isnan (childxdata{stemchild}(3))); | |
184 %! assert (childxdata{arrowheadchild}(2), 0 + 2*0.5, eps); | |
185 %! assert (isnan (childxdata{arrowheadchild}(4))); | |
186 %! | |
187 %! unwind_protect_cleanup | |
188 %! close (hf); | |
189 %! end_unwind_protect | |
190 | |
191 ## Check arrowhead size | |
192 %!test | |
193 %! hf = figure ("visible", "off"); | |
194 %! hax = gca(); | |
195 %! unwind_protect | |
196 %! h = quiver (hax, 0, 0, 0, 1, 1); # up | |
197 %! children = get (h, "children"); | |
198 %! childxdata = get (children, "xdata"); | |
199 %! childydata = get (children, "ydata"); | |
200 %! arrowheadchild = find (cellfun (@numel, childxdata) == 4); | |
201 %! assert (childxdata{arrowheadchild}, [1/9 0 -1/9 NaN], eps); | |
202 %! assert (childydata{arrowheadchild}, [2/3 1 2/3 NaN], eps); | |
203 %! | |
204 %! h = quiver (hax, 0, 0, 0, -1, 1); # down | |
205 %! children = get (h, "children"); | |
206 %! childxdata = get (children, "xdata"); | |
207 %! childydata = get (children, "ydata"); | |
208 %! arrowheadchild = find (cellfun (@numel, childxdata) == 4); | |
209 %! assert (childxdata{arrowheadchild}, [-1/9 0 1/9 NaN], eps); | |
210 %! assert (childydata{arrowheadchild}, [-2/3 -1 -2/3 NaN], eps); | |
211 %! | |
212 %! h = quiver (hax, 0, 0, -1, 0, 1); # left | |
213 %! children = get (h, "children"); | |
214 %! childxdata = get (children, "xdata"); | |
215 %! childydata = get (children, "ydata"); | |
216 %! arrowheadchild = find (cellfun (@numel, childxdata) == 4); | |
217 %! assert (childxdata{arrowheadchild}, [-2/3 -1 -2/3 NaN], eps); | |
218 %! assert (childydata{arrowheadchild}, [1/9 0 -1/9 NaN], eps); | |
219 %! | |
220 %! h = quiver (hax, 0, 0, 1, 0, 1); # right | |
221 %! children = get (h, "children"); | |
222 %! childxdata = get (children, "xdata"); | |
223 %! childydata = get (children, "ydata"); | |
224 %! arrowheadchild = find (cellfun (@numel, childxdata) == 4); | |
225 %! assert (childxdata{arrowheadchild}, [2/3 1 2/3 NaN], eps); | |
226 %! assert (childydata{arrowheadchild}, [-1/9 0 1/9 NaN], eps); | |
227 %! | |
228 %! h = quiver (hax, 0, 0, 1, 1, 1); # 45 deg - symmetric | |
229 %! children = get (h, "children"); | |
230 %! childxdata = get (children, "xdata"); | |
231 %! childydata = get (children, "ydata"); | |
232 %! arrowheadchild = find (cellfun (@numel, childxdata) == 4); | |
233 %! assert (childxdata{arrowheadchild}, [7/9 1 5/9 NaN], eps); | |
234 %! assert (childydata{arrowheadchild}, [5/9 1 7/9 NaN], eps); | |
235 %! | |
236 %! h = quiver (hax, 0, 0, sqrt(3), 1, 1); # 30 deg | |
237 %! children = get (h, "children"); | |
238 %! childxdata = get (children, "xdata"); | |
239 %! childydata = get (children, "ydata"); | |
240 %! arrowheadchild = find (cellfun (@numel, childxdata) == 4); | |
241 %! assert (childxdata{arrowheadchild}, [(6*sqrt(3)+1)/9, sqrt(3), (6*sqrt(3)-1)/9, NaN], eps); | |
242 %! assert (childydata{arrowheadchild}, [(6-sqrt(3))/9, 1, (6+sqrt(3))/9, NaN], eps); | |
243 %! unwind_protect_cleanup | |
244 %! close (hf); | |
245 %! end_unwind_protect | |
246 | |
247 ## Check standard inputs, multiple arrows. | |
248 %!test | |
249 %! hf = figure ("visible", "off"); | |
250 %! hax = gca(); | |
251 %! unwind_protect | |
252 %! [x,y] = meshgrid (0:1); | |
253 %! u = [0 1; 1 -2]; | |
254 %! v = [1 0; 1 -2]; | |
255 %! numpts = 4; | |
256 %! h = quiver (hax, u, v, 1); # assumes [x,y] = meshgrid (1:2) | |
257 %! childxdata = get (get (h, "children"), "xdata"); | |
258 %! basechild = find (cellfun (@numel, childxdata) == 1*numpts); | |
259 %! stemchild = find (cellfun (@numel, childxdata) == 3*numpts); | |
260 %! arrowheadchild = find (cellfun (@numel, childxdata) == 4*numpts); | |
261 %! assert (childxdata{basechild}, [1 1 2 2]); | |
262 %! assert (childxdata{stemchild}, [1,1,NaN,1,1.25,NaN,2,2.25,NaN,2,1.5,NaN], eps); | |
263 %! assert (childxdata{arrowheadchild}([2, 6, 10, 14]), [1, 1.25, 2.25, 1.5], eps); | |
264 %! assert (childxdata{arrowheadchild}([4, 8, 12, 16]), NaN(1,4), eps); | |
265 %! | |
266 %! h = quiver (hax, x, y, u, v, 1); | |
267 %! childxdata = get (get (h, "children"), "xdata"); | |
268 %! basechild = find (cellfun (@numel, childxdata) == 1*numpts); | |
269 %! stemchild = find (cellfun (@numel, childxdata) == 3*numpts); | |
270 %! arrowheadchild = find (cellfun (@numel, childxdata) == 4*numpts); | |
271 %! assert (childxdata{basechild}, [0 0 1 1]); | |
272 %! assert (childxdata{stemchild}, [0,0,NaN,0,0.25,NaN,1,1.25,NaN,1,0.5,NaN], eps); | |
273 %! assert (childxdata{arrowheadchild}([2, 6, 10, 14]), [0, 0.25, 1.25, 0.5], eps); | |
274 %! assert (childxdata{arrowheadchild}([4, 8, 12, 16]), NaN(1,4), eps); | |
275 %! | |
276 %! unwind_protect_cleanup | |
277 %! close (hf); | |
278 %! end_unwind_protect | |
279 | |
280 ## Check multiple arrows, vector inputs identical to array inputs. | |
281 %!test | |
282 %! hf = figure ("visible", "off"); | |
283 %! hax = gca(); | |
284 %! unwind_protect | |
285 %! [x,y] = meshgrid (0:1); | |
286 %! u = [0 1; 1 -2]; | |
287 %! v = [1 0; 1 -2]; | |
288 %! h = quiver (hax, x, y, u, v, 1); # arrayinput | |
289 %! haxarray = get(hax); | |
290 %! haxarray.children = []; | |
291 %! haxarray.xlabel = []; | |
292 %! haxarray.ylabel = []; | |
293 %! haxarray.zlabel = []; | |
294 %! haxarray.title = []; | |
295 %! parentarray = get(h); | |
296 %! parentarray.children = []; | |
297 %! childrenarray = get (get (h, "children")); | |
298 %! [childrenarray.parent] = deal ([]); | |
299 %! h = quiver (hax, [0:1], [0:1], u, v, 1); | |
300 %! haxvect1 = get(hax); | |
301 %! haxvect1.children = []; | |
302 %! haxvect1.xlabel= []; | |
303 %! haxvect1.ylabel= []; | |
304 %! haxvect1.zlabel= []; | |
305 %! haxvect1.title= []; | |
306 %! parentvect1 = get(h); | |
307 %! parentvect1.children = []; | |
308 %! childrenvect1 = get (get (h, "children")); | |
309 %! [childrenvect1.parent] = deal ([]); | |
310 %! assert (isequaln (haxarray, haxvect1)); | |
311 %! assert (isequaln (parentarray, parentvect1)); | |
312 %! assert (isequaln (childrenarray, childrenvect1)); | |
313 %! h = quiver (hax, [0:1], [0:1]', u, v, 1); | |
314 %! haxvect2 = get(hax); | |
315 %! haxvect2.children = []; | |
316 %! haxvect2.xlabel= []; | |
317 %! haxvect2.ylabel= []; | |
318 %! haxvect2.zlabel= []; | |
319 %! haxvect2.title= []; | |
320 %! parentvect2 = get(h); | |
321 %! parentvect2.children = []; | |
322 %! childrenvect2 = get (get (h, "children")); | |
323 %! [childrenvect2.parent] = deal ([]); | |
324 %! assert (isequaln (haxvect1, haxvect2)); | |
325 %! assert (isequaln (parentvect1, parentvect2)); | |
326 %! assert (isequaln (childrenvect1, childrenvect2)); | |
327 %! unwind_protect_cleanup | |
328 %! close (hf); | |
329 %! end_unwind_protect | |
330 | |
331 ## Check scale factor "off" is identical to scale factor = 0. | |
332 %!test | |
333 %! hf = figure ("visible", "off"); | |
334 %! hax = gca(); | |
335 %! unwind_protect | |
336 %! h = quiver (hax, 1, 2, 0); | |
337 %! haxzero = get(hax); | |
338 %! haxzero.children = []; | |
339 %! haxzero.xlabel = []; | |
340 %! haxzero.ylabel = []; | |
341 %! haxzero.zlabel = []; | |
342 %! haxzero.title = []; | |
343 %! parentzero = get(h); | |
344 %! parentzero.children = []; | |
345 %! childrenzero = get (get (h, "children")); | |
346 %! [childrenzero.parent] = deal ([]); | |
347 %! h = quiver (hax, 1, 2, "off"); | |
348 %! haxoff = get(hax); | |
349 %! haxoff.children = []; | |
350 %! haxoff.xlabel= []; | |
351 %! haxoff.ylabel= []; | |
352 %! haxoff.zlabel= []; | |
353 %! haxoff.title= []; | |
354 %! parentoff = get(h); | |
355 %! parentoff.children = []; | |
356 %! childrenoff = get (get (h, "children")); | |
357 %! [childrenoff.parent] = deal ([]); | |
358 %! assert (isequaln (haxzero, haxoff)); | |
359 %! assert (isequaln (parentzero, parentoff)); | |
360 %! assert (isequaln (childrenzero, childrenoff)); | |
361 %! unwind_protect_cleanup | |
362 %! close (hf); | |
363 %! end_unwind_protect | |
364 | |
365 ## Check input styles. | |
366 %!test | |
367 %! hf = figure ("visible", "off"); | |
368 %! hax = gca(); | |
369 %! unwind_protect | |
370 %! h = quiver (hax, 0, 1, 2, 3, "-o"); # Linestyle | |
371 %! parent = get (h); | |
372 %! assert (strcmp (parent.marker, "o")); | |
373 %! assert (strcmp (parent.markerfacecolor, "none")); | |
374 %! childdata = get (parent.children); | |
375 %! basechild = find (cellfun (@numel, {childdata.xdata}) == 1); | |
376 %! arrowheadchild = find (cellfun (@numel, {childdata.xdata}) == 4); | |
377 %! assert (strcmp (childdata(basechild).marker, "o")); | |
378 %! assert (strcmp (childdata(basechild).markerfacecolor, "none")); | |
379 %! assert (strcmp (childdata(basechild).linestyle, "none")); | |
380 %! assert (strcmp (childdata(arrowheadchild).marker, "none")); | |
381 %! assert (strcmp (childdata(arrowheadchild).markerfacecolor, "none")); | |
382 %! assert (strcmp (childdata(arrowheadchild).linestyle, "none")); | |
383 %! | |
384 %! h = quiver (hax, 0, 1, 2, 3, "-o", "filled"); # Linestyle + filled. | |
385 %! parent = get (h); | |
386 %! assert (strcmp (parent.marker, "o")); | |
387 %! assert (numel (parent.markerfacecolor), 3); | |
388 %! childdata = get (parent.children); | |
389 %! basechild = find (cellfun (@numel, {childdata.xdata}) == 1); | |
390 %! arrowheadchild = find (cellfun (@numel, {childdata.xdata}) == 4); | |
391 %! assert (strcmp (childdata(basechild).marker, "o")); | |
392 %! assert (numel (childdata(basechild).markerfacecolor), 3); | |
393 %! assert (strcmp (childdata(basechild).linestyle, "none")); | |
394 %! assert (strcmp (childdata(arrowheadchild).marker, "none")); | |
395 %! assert (strcmp (childdata(arrowheadchild).markerfacecolor, "none")); | |
396 %! assert (strcmp (childdata(arrowheadchild).linestyle, "none")); | |
397 %! | |
398 %! h = quiver (hax, 0, 1, 2, 3, "linewidth", 10); # Name/value pair. | |
399 %! parent = get (h); | |
400 %! assert (strcmp (parent.marker, "none")); | |
401 %! assert (strcmp (parent.markerfacecolor, "none")); | |
402 %! assert (strcmp (parent.linestyle, "-")); | |
403 %! assert (parent.linewidth, 10); | |
404 %! childdata = get (parent.children); | |
405 %! basechild = find (cellfun (@numel, {childdata.xdata}) == 1); | |
406 %! stemchild = find (cellfun (@numel, {childdata.xdata}) == 3); | |
407 %! arrowheadchild = find (cellfun (@numel, {childdata.xdata}) == 4); | |
408 %! assert (strcmp (childdata(basechild).marker, "none")); | |
409 %! assert (strcmp (childdata(basechild).markerfacecolor, "none")); | |
410 %! assert (strcmp (childdata(basechild).linestyle, "none")); | |
411 %! assert (strcmp (childdata(stemchild).marker, "none")); | |
412 %! assert (strcmp (childdata(stemchild).markerfacecolor, "none")); | |
413 %! assert (strcmp (childdata(stemchild).linestyle, "-")); | |
414 %! assert (childdata(stemchild).linewidth, 10); | |
415 %! assert (strcmp (childdata(arrowheadchild).marker, "none")); | |
416 %! assert (strcmp (childdata(arrowheadchild).markerfacecolor, "none")); | |
417 %! assert (strcmp (childdata(arrowheadchild).linestyle, "-")); | |
418 %! assert (childdata(arrowheadchild).linewidth, 10); | |
419 %! | |
420 %! unwind_protect_cleanup | |
421 %! close (hf); | |
422 %! end_unwind_protect | |
423 | |
424 ## Test both Linestyle + name/value pair | |
425 %!test <64143> | |
426 %! hf = figure ("visible", "off"); | |
427 %! hax = gca(); | |
428 %! unwind_protect | |
429 %! h = quiver (hax, 0, 1, 2, 3, "-o", "linewidth", 10); | |
430 %! parent = get (h); | |
431 %! assert (strcmp (parent.marker, "o")); | |
432 %! assert (strcmp (parent.markerfacecolor, "none")); | |
433 %! assert (strcmp (parent.linestyle, "-")); | |
434 %! assert (parent.linewidth, 10); | |
435 %! childdata = get (parent.children); | |
436 %! basechild = find (cellfun (@numel, {childdata.xdata}) == 1); | |
437 %! stemchild = find (cellfun (@numel, {childdata.xdata}) == 3); | |
438 %! arrowheadchild = find (cellfun (@numel, {childdata.xdata}) == 4); | |
439 %! assert (strcmp (childdata(basechild).marker, "o")); | |
440 %! assert (strcmp (childdata(basechild).markerfacecolor, "none")); | |
441 %! assert (strcmp (childdata(basechild).linestyle, "none")); | |
442 %! assert (strcmp (childdata(stemchild).marker, "none")); | |
443 %! assert (strcmp (childdata(stemchild).markerfacecolor, "none")); | |
444 %! assert (strcmp (childdata(stemchild).linestyle, "-")); | |
445 %! assert (childdata(stemchild).linewidth, 10); | |
446 %! assert (strcmp (childdata(arrowheadchild).marker, "none")); | |
447 %! assert (strcmp (childdata(arrowheadchild).markerfacecolor, "none")); | |
448 %! assert (strcmp (childdata(arrowheadchild).linestyle, "none")); | |
449 %! assert (childdata(arrowheadchild).linewidth, 10); | |
450 %! | |
451 %! unwind_protect_cleanup | |
452 %! close (hf); | |
453 %! end_unwind_protect | |
454 | |
455 ## Check arrow length, scale factor adjustment, one arrow. | |
456 %!test <*39552> | |
144 %! hf = figure ("visible", "off"); | 457 %! hf = figure ("visible", "off"); |
145 %! hax = gca (); | 458 %! hax = gca (); |
146 %! unwind_protect | 459 %! unwind_protect |
147 %! [x,y] = meshgrid (1:2); | 460 %! [x,y] = meshgrid (1:2); |
148 %! u = [0 1; 2 3]; | 461 %! u = [0 1; 2 3]; |
165 %! | 478 %! |
166 %! unwind_protect_cleanup | 479 %! unwind_protect_cleanup |
167 %! close (hf); | 480 %! close (hf); |
168 %! end_unwind_protect | 481 %! end_unwind_protect |
169 | 482 |
170 %!test <*39552> # Check arrow length, scale factor adjustment, multiple arrows. | 483 ## Check arrow length, scale factor adjustment, multiple arrows. |
484 %!test <*39552> | |
171 %! hf = figure ("visible", "off"); | 485 %! hf = figure ("visible", "off"); |
172 %! hax = gca (); | 486 %! hax = gca (); |
173 %! unwind_protect | 487 %! unwind_protect |
174 %! [x,y] = meshgrid (1:2); | 488 %! [x,y] = meshgrid (1:2); |
175 %! u = [0 1; 2 3]; | 489 %! u = [0 1; 2 3]; |
196 %! | 510 %! |
197 %! unwind_protect_cleanup | 511 %! unwind_protect_cleanup |
198 %! close (hf); | 512 %! close (hf); |
199 %! end_unwind_protect | 513 %! end_unwind_protect |
200 | 514 |
201 %!test <*59695> # Check for proper plotting with non-float inputs. | 515 ## Check for proper plotting with non-float inputs. |
516 %!test <*59695> | |
202 %! hf = figure ("visible", "off"); | 517 %! hf = figure ("visible", "off"); |
203 %! hax = gca (); | 518 %! hax = gca (); |
204 %! unwind_protect | 519 %! unwind_protect |
205 %! h = quiver (int32(1), int32(1), int32(1), int32(1), double(0.5)); | 520 %! h = quiver (int32(1), int32(1), int32(1), int32(1), double(0.5)); |
206 %! childxdata = get (get (h, "children"), "xdata"); | 521 %! children = get (h, "children"); |
207 %! childydata = get (get (h, "children"), "ydata"); | 522 %! childxdata = get (children, "xdata"); |
523 %! childydata = get (children, "ydata"); | |
208 %! assert (all (strcmp (cellfun (... | 524 %! assert (all (strcmp (cellfun (... |
209 %! 'class', childxdata, 'UniformOutput', false), "double"))); | 525 %! 'class', childxdata, 'UniformOutput', false), "double"))); |
210 %! assert (all (strcmp (cellfun (... | 526 %! assert (all (strcmp (cellfun (... |
211 %! 'class', childydata, 'UniformOutput', false), "double"))); | 527 %! 'class', childydata, 'UniformOutput', false), "double"))); |
212 %! assert (childxdata{2}(2) , 1.5, eps); | 528 %! assert (childxdata{2}(2) , 1.5, eps); |
213 %! assert (childxdata{3}(2) , 1.5, eps); | 529 %! assert (childxdata{3}(2) , 1.5, eps); |
214 %! assert (childydata{2}(2) , 1.5, eps); | 530 %! assert (childydata{2}(2) , 1.5, eps); |
215 %! assert (childydata{3}(2) , 1.5, eps); | 531 %! assert (childydata{3}(2) , 1.5, eps); |
216 %! | 532 %! |
217 %! h = quiver (0.5, 0.5, 0.5, 0.5, int32(1)); | 533 %! h = quiver (0.5, 0.5, 0.5, 0.5, int32(1)); |
218 %! childxdata = get (get (h, "children"), "xdata"); | 534 %! children = get (h, "children"); |
219 %! childydata = get (get (h, "children"), "ydata"); | 535 %! childxdata = get (children, "xdata"); |
536 %! childydata = get (children, "ydata"); | |
220 %! assert (all (strcmp (cellfun (... | 537 %! assert (all (strcmp (cellfun (... |
221 %! 'class', childxdata, 'UniformOutput', false), "double"))); | 538 %! 'class', childxdata, 'UniformOutput', false), "double"))); |
222 %! assert (all (strcmp (cellfun (... | 539 %! assert (all (strcmp (cellfun (... |
223 %! 'class', childydata, 'UniformOutput', false), "double"))); | 540 %! 'class', childydata, 'UniformOutput', false), "double"))); |
224 %! assert (childxdata{2}(2) , 1, eps); | 541 %! assert (childxdata{2}(2) , 1, eps); |
225 %! assert (childxdata{3}(2) , 1, eps); | 542 %! assert (childxdata{3}(2) , 1, eps); |
226 %! assert (childydata{2}(2) , 1, eps); | 543 %! assert (childydata{2}(2) , 1, eps); |
227 %! assert (childydata{3}(2) , 1, eps); | 544 %! assert (childydata{3}(2) , 1, eps); |
228 %! | 545 %! |
229 %! h = quiver (false, true, false, true, true); | 546 %! h = quiver (false, true, false, true, true); |
230 %! childxdata = get (get (h, "children"), "xdata"); | 547 %! children = get (h, "children"); |
231 %! childydata = get (get (h, "children"), "ydata"); | 548 %! childxdata = get (children, "xdata"); |
549 %! childydata = get (children, "ydata"); | |
232 %! assert (all (strcmp (cellfun (... | 550 %! assert (all (strcmp (cellfun (... |
233 %! 'class', childxdata, 'UniformOutput', false), "double"))); | 551 %! 'class', childxdata, 'UniformOutput', false), "double"))); |
234 %! assert (all (strcmp (cellfun (... | 552 %! assert (all (strcmp (cellfun (... |
235 %! 'class', childydata, 'UniformOutput', false), "double"))); | 553 %! 'class', childydata, 'UniformOutput', false), "double"))); |
236 %! assert (childxdata{2}(2) , 0, eps); | 554 %! assert (childxdata{2}(2) , 0, eps); |
243 %! end_unwind_protect | 561 %! end_unwind_protect |
244 | 562 |
245 ## Test input validation | 563 ## Test input validation |
246 %!error <Invalid call> quiver() | 564 %!error <Invalid call> quiver() |
247 %!error <Invalid call> quiver(1.1) | 565 %!error <Invalid call> quiver(1.1) |
248 | 566 %!error <Invalid call> quiver(1.1, "foo") |
249 | 567 %!error <Invalid call> quiver(1.1, 2, 3, 4, 5, 6, "foo") |
568 %!error <U and V must be the same size> quiver ([1, 2], 3) | |
569 %!error <U and V must be the same size> quiver (1.1, [2, 3]) | |
570 %!error <U and V must be the same size> quiver (1.1, 2, eye(2), 4) | |
571 %!error <U and V must be the same size> quiver (1.1, 2, 3, eye(2)) | |
572 %!error <X vector length must equal> quiver (1.1, [2 3], eye(2), eye(2)) | |
573 %!error <Y vector length must equal> quiver ([1, 2], 3, eye(2), eye(2)) | |
574 %!error <X, Y, U, and V must be the same size> quiver (eye(3), eye(2), eye(2), eye(2)) | |
575 %!error <X, Y, U, and V must be the same size> quiver (eye(2), eye(3), eye(2), eye(2)) | |
576 %!error <X, Y, U, and V must be the same size> quiver (eye(2), eye(2), eye(3), eye(2)) | |
577 %!error <X, Y, U, and V must be the same size> quiver (eye(2), eye(2), eye(2), eye(3)) | |
578 %!error <scaling factor must be> quiver (10, 20, -5) | |
579 %!error <scaling factor must be> quiver (10, 20, [1 2]) | |
580 %!error <scaling factor must be> quiver (10, 20, 30, 40, -5) | |
581 %!error <scaling factor must be> quiver (10, 20, 30, 40, [1 2]) | |
582 |