annotate scripts/plot/draw/contourc.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 597f3ee61a48
children 2e484f9f1f18
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ########################################################################
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 ##
31706
597f3ee61a48 update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
3 ## Copyright (C) 2003-2023 The Octave Project Developers
27918
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26600
diff changeset
4 ##
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 ## See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 ## distribution or <https://octave.org/copyright/>.
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
7 ##
6440
98ee80702bca [project @ 2007-03-23 15:13:19 by jwe]
jwe
parents: 6269
diff changeset
8 ## This file is part of Octave.
98ee80702bca [project @ 2007-03-23 15:13:19 by jwe]
jwe
parents: 6269
diff changeset
9 ##
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24321
diff changeset
10 ## Octave is free software: you can redistribute it and/or modify it
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
11 ## under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24321
diff changeset
12 ## the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
13 ## (at your option) any later version.
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
14 ##
6440
98ee80702bca [project @ 2007-03-23 15:13:19 by jwe]
jwe
parents: 6269
diff changeset
15 ## Octave is distributed in the hope that it will be useful, but
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
18 ## GNU General Public License for more details.
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
19 ##
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
20 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6895
diff changeset
21 ## along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24321
diff changeset
22 ## <https://www.gnu.org/licenses/>.
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 ##
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ########################################################################
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
25
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
26 ## -*- texinfo -*-
29278
7bfc454b9e08 contourc.m: Overhaul function.
Rik <rik@octave.org>
parents: 28896
diff changeset
27 ## @deftypefn {} {@var{c} =} contourc (@var{z})
7bfc454b9e08 contourc.m: Overhaul function.
Rik <rik@octave.org>
parents: 28896
diff changeset
28 ## @deftypefnx {} {@var{c} =} contourc (@var{z}, @var{vn})
7bfc454b9e08 contourc.m: Overhaul function.
Rik <rik@octave.org>
parents: 28896
diff changeset
29 ## @deftypefnx {} {@var{c} =} contourc (@var{x}, @var{y}, @var{z})
7bfc454b9e08 contourc.m: Overhaul function.
Rik <rik@octave.org>
parents: 28896
diff changeset
30 ## @deftypefnx {} {@var{c} =} contourc (@var{x}, @var{y}, @var{z}, @var{vn})
7bfc454b9e08 contourc.m: Overhaul function.
Rik <rik@octave.org>
parents: 28896
diff changeset
31 ## @deftypefnx {} {[@var{c}, @var{lev}] =} contourc (@dots{})
17122
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 16814
diff changeset
32 ## Compute contour lines (isolines of constant Z value).
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 16814
diff changeset
33 ##
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 16814
diff changeset
34 ## The matrix @var{z} contains height values above the rectangular grid
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 16814
diff changeset
35 ## determined by @var{x} and @var{y}. If only a single input @var{z} is
24319
3cdd2b6c78cb doc: Correct surface plot explanation of meshgridded results of 1 input (bug #52536)
Rik <rik@octave.org>
parents: 23219
diff changeset
36 ## provided then @var{x} is taken to be @code{1:columns (@var{z})} and @var{y}
26120
80643ff8c8b7 contourc.m: Tighten input validation to avoid segfault in __contourc__ (bug #55071).
Rik <rik@octave.org>
parents: 25054
diff changeset
37 ## is taken to be @code{1:rows (@var{z})}. The minimum data size is 2x2.
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
38 ##
17122
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 16814
diff changeset
39 ## The optional input @var{vn} is either a scalar denoting the number of
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 16814
diff changeset
40 ## contour lines to compute or a vector containing the Z values where lines
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 16814
diff changeset
41 ## will be computed. When @var{vn} is a vector the number of contour lines
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 16814
diff changeset
42 ## is @code{numel (@var{vn})}. However, to compute a single contour line
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 16814
diff changeset
43 ## at a given value use @code{@var{vn} = [val, val]}. If @var{vn} is omitted
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 16814
diff changeset
44 ## it defaults to 10.
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 16814
diff changeset
45 ##
29278
7bfc454b9e08 contourc.m: Overhaul function.
Rik <rik@octave.org>
parents: 28896
diff changeset
46 ## The return value @var{c} is a 2x@var{n} matrix containing the contour lines
7bfc454b9e08 contourc.m: Overhaul function.
Rik <rik@octave.org>
parents: 28896
diff changeset
47 ## in the following format
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
48 ##
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
49 ## @example
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 9040
diff changeset
50 ## @group
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
51 ## @var{c} = [lev1, x1, x2, @dots{}, levn, x1, x2, ...
9040
dbd0c77e575e Cleanup documentation file plot.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
52 ## len1, y1, y2, @dots{}, lenn, y1, y2, @dots{}]
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 9040
diff changeset
53 ## @end group
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
54 ## @end example
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
55 ##
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
56 ## @noindent
29278
7bfc454b9e08 contourc.m: Overhaul function.
Rik <rik@octave.org>
parents: 28896
diff changeset
57 ## in which contour line @var{n} has a level (height) of @var{levn} and length
7bfc454b9e08 contourc.m: Overhaul function.
Rik <rik@octave.org>
parents: 28896
diff changeset
58 ## of @var{lenn}.
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
59 ##
29278
7bfc454b9e08 contourc.m: Overhaul function.
Rik <rik@octave.org>
parents: 28896
diff changeset
60 ## The optional return value @var{lev} is a vector with the Z values of the
7bfc454b9e08 contourc.m: Overhaul function.
Rik <rik@octave.org>
parents: 28896
diff changeset
61 ## contour levels.
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
62 ##
17122
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 16814
diff changeset
63 ## Example:
10846
a4f482e66b65 Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents: 10821
diff changeset
64 ##
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
65 ## @example
6592
8899e24ae362 [project @ 2007-04-27 04:11:48 by jwe]
jwe
parents: 6590
diff changeset
66 ## @group
8899e24ae362 [project @ 2007-04-27 04:11:48 by jwe]
jwe
parents: 6590
diff changeset
67 ## x = 0:2;
8899e24ae362 [project @ 2007-04-27 04:11:48 by jwe]
jwe
parents: 6590
diff changeset
68 ## y = x;
8899e24ae362 [project @ 2007-04-27 04:11:48 by jwe]
jwe
parents: 6590
diff changeset
69 ## z = x' * y;
26600
f6730533820e doc: clean up doc example blocks for accuracy and consistent formatting
Mike Miller <mtmiller@octave.org>
parents: 26376
diff changeset
70 ## c = contourc (x, y, z, 2:3)
f6730533820e doc: clean up doc example blocks for accuracy and consistent formatting
Mike Miller <mtmiller@octave.org>
parents: 26376
diff changeset
71 ## @result{} c =
f6730533820e doc: clean up doc example blocks for accuracy and consistent formatting
Mike Miller <mtmiller@octave.org>
parents: 26376
diff changeset
72 ## 2.0000 1.0000 1.0000 2.0000 2.0000 3.0000 1.5000 2.0000
f6730533820e doc: clean up doc example blocks for accuracy and consistent formatting
Mike Miller <mtmiller@octave.org>
parents: 26376
diff changeset
73 ## 4.0000 2.0000 2.0000 1.0000 1.0000 2.0000 2.0000 1.5000
6592
8899e24ae362 [project @ 2007-04-27 04:11:48 by jwe]
jwe
parents: 6590
diff changeset
74 ## @end group
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
75 ## @end example
17122
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 16814
diff changeset
76 ## @seealso{contour, contourf, contour3, clabel}
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
77 ## @end deftypefn
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
78
17451
56e72e8d1aba contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents: 17122
diff changeset
79 function [c, lev] = contourc (varargin)
56e72e8d1aba contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents: 17122
diff changeset
80
56e72e8d1aba contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents: 17122
diff changeset
81 if (nargin < 1 || nargin > 4)
56e72e8d1aba contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents: 17122
diff changeset
82 print_usage ();
56e72e8d1aba contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents: 17122
diff changeset
83 endif
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
84
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
85 if (nargin == 1)
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
86 z = varargin{1};
17451
56e72e8d1aba contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents: 17122
diff changeset
87 x = 1:columns (z);
56e72e8d1aba contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents: 17122
diff changeset
88 y = 1:rows (z);
56e72e8d1aba contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents: 17122
diff changeset
89 vn = 10;
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
90 elseif (nargin == 2)
17451
56e72e8d1aba contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents: 17122
diff changeset
91 z = varargin{1};
56e72e8d1aba contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents: 17122
diff changeset
92 x = 1:columns (z);
56e72e8d1aba contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents: 17122
diff changeset
93 y = 1:rows (z);
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
94 vn = varargin{2};
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
95 elseif (nargin == 3)
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
96 x = varargin{1};
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
97 y = varargin{2};
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
98 z = varargin{3};
17451
56e72e8d1aba contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents: 17122
diff changeset
99 vn = 10;
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
100 elseif (nargin == 4)
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
101 x = varargin{1};
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
102 y = varargin{2};
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
103 z = varargin{3};
17451
56e72e8d1aba contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents: 17122
diff changeset
104 vn = varargin{4};
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
105 endif
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
106
26120
80643ff8c8b7 contourc.m: Tighten input validation to avoid segfault in __contourc__ (bug #55071).
Rik <rik@octave.org>
parents: 25054
diff changeset
107 if (! (isnumeric (z) && isnumeric (x) && isnumeric (y))
29278
7bfc454b9e08 contourc.m: Overhaul function.
Rik <rik@octave.org>
parents: 28896
diff changeset
108 || ! (ismatrix (z) && ismatrix (x) && ismatrix (y))
7bfc454b9e08 contourc.m: Overhaul function.
Rik <rik@octave.org>
parents: 28896
diff changeset
109 || ! (isreal (z) && isreal (x) && isreal (y)))
7bfc454b9e08 contourc.m: Overhaul function.
Rik <rik@octave.org>
parents: 28896
diff changeset
110 error ("contourc: X, Y, and Z must be real numeric matrices");
26120
80643ff8c8b7 contourc.m: Tighten input validation to avoid segfault in __contourc__ (bug #55071).
Rik <rik@octave.org>
parents: 25054
diff changeset
111 endif
80643ff8c8b7 contourc.m: Tighten input validation to avoid segfault in __contourc__ (bug #55071).
Rik <rik@octave.org>
parents: 25054
diff changeset
112
80643ff8c8b7 contourc.m: Tighten input validation to avoid segfault in __contourc__ (bug #55071).
Rik <rik@octave.org>
parents: 25054
diff changeset
113 if (rows (z) < 2 || columns (z) < 2)
80643ff8c8b7 contourc.m: Tighten input validation to avoid segfault in __contourc__ (bug #55071).
Rik <rik@octave.org>
parents: 25054
diff changeset
114 error ("contourc: Z data must have at least 2 rows and 2 columns");
10634
60542efcfa2c Check input arguments for size and type (bug #29861).
Rik <octave@nomad.inbox5.com>
parents: 9758
diff changeset
115 endif
60542efcfa2c Check input arguments for size and type (bug #29861).
Rik <octave@nomad.inbox5.com>
parents: 9758
diff changeset
116
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
117 if (isscalar (vn))
29278
7bfc454b9e08 contourc.m: Overhaul function.
Rik <rik@octave.org>
parents: 28896
diff changeset
118 lev = linspace (min (z(:)), max (z(:)), vn+2)(2:end-1);
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
119 else
29278
7bfc454b9e08 contourc.m: Overhaul function.
Rik <rik@octave.org>
parents: 28896
diff changeset
120 lev = unique (sort (vn));
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
121 endif
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
122
7327
9af6f0a214ee [project @ 2007-12-19 21:39:02 by jwe]
jwe
parents: 7245
diff changeset
123 if (isvector (x) && isvector (y))
29278
7bfc454b9e08 contourc.m: Overhaul function.
Rik <rik@octave.org>
parents: 28896
diff changeset
124 c = __contourc__ (x(:)', y(:)', z, lev);
17451
56e72e8d1aba contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents: 17122
diff changeset
125 elseif (! any (bsxfun (@minus, x, x(1,:))(:))
56e72e8d1aba contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents: 17122
diff changeset
126 && ! any (bsxfun (@minus, y, y(:,1))(:)))
56e72e8d1aba contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents: 17122
diff changeset
127 ## x,y are uniform grid (such as from meshgrid)
29278
7bfc454b9e08 contourc.m: Overhaul function.
Rik <rik@octave.org>
parents: 28896
diff changeset
128 c = __contourc__ (x(1,:), y(:,1)', z, lev);
7327
9af6f0a214ee [project @ 2007-12-19 21:39:02 by jwe]
jwe
parents: 7245
diff changeset
129 else
17451
56e72e8d1aba contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents: 17122
diff changeset
130 ## Data is sampled over non-uniform mesh.
56e72e8d1aba contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents: 17122
diff changeset
131 ## Algorithm calculates contours for uniform grid
56e72e8d1aba contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents: 17122
diff changeset
132 ## and then interpolates values back to the non-uniform mesh.
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
133
17451
56e72e8d1aba contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents: 17122
diff changeset
134 ## Uniform grid for __contourc__.
56e72e8d1aba contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents: 17122
diff changeset
135 [nr, nc] = size (z);
56e72e8d1aba contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents: 17122
diff changeset
136 ii = 1:nc;
56e72e8d1aba contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents: 17122
diff changeset
137 jj = 1:nr;
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
138
29278
7bfc454b9e08 contourc.m: Overhaul function.
Rik <rik@octave.org>
parents: 28896
diff changeset
139 c = __contourc__ (ii, jj, z, lev);
17451
56e72e8d1aba contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents: 17122
diff changeset
140
56e72e8d1aba contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents: 17122
diff changeset
141 ## Map the contour lines from index space (i,j)
56e72e8d1aba contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents: 17122
diff changeset
142 ## back to the original grid (x,y)
7327
9af6f0a214ee [project @ 2007-12-19 21:39:02 by jwe]
jwe
parents: 7245
diff changeset
143 i = 1;
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
144
29278
7bfc454b9e08 contourc.m: Overhaul function.
Rik <rik@octave.org>
parents: 28896
diff changeset
145 while (i < columns (c))
7bfc454b9e08 contourc.m: Overhaul function.
Rik <rik@octave.org>
parents: 28896
diff changeset
146 clen = c(2, i);
17451
56e72e8d1aba contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents: 17122
diff changeset
147 idx = i + (1:clen);
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
148
29278
7bfc454b9e08 contourc.m: Overhaul function.
Rik <rik@octave.org>
parents: 28896
diff changeset
149 ci = c(1, idx);
7bfc454b9e08 contourc.m: Overhaul function.
Rik <rik@octave.org>
parents: 28896
diff changeset
150 cj = c(2, idx);
7327
9af6f0a214ee [project @ 2007-12-19 21:39:02 by jwe]
jwe
parents: 7245
diff changeset
151
29278
7bfc454b9e08 contourc.m: Overhaul function.
Rik <rik@octave.org>
parents: 28896
diff changeset
152 ## Due to rounding errors, some elements of ci and cj can fall out of the
7bfc454b9e08 contourc.m: Overhaul function.
Rik <rik@octave.org>
parents: 28896
diff changeset
153 ## range of ii and jj and interp2 would return NA for those values.
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
154 ## The permitted range is enforced here:
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
155
17451
56e72e8d1aba contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents: 17122
diff changeset
156 ci = max (ci, 1); ci = min (ci, nc);
56e72e8d1aba contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents: 17122
diff changeset
157 cj = max (cj, 1); cj = min (cj, nr);
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
158
29278
7bfc454b9e08 contourc.m: Overhaul function.
Rik <rik@octave.org>
parents: 28896
diff changeset
159 c(1, idx) = interp2 (ii, jj, x, ci, cj);
7bfc454b9e08 contourc.m: Overhaul function.
Rik <rik@octave.org>
parents: 28896
diff changeset
160 c(2, idx) = interp2 (ii, jj, y, ci, cj);
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
161
29278
7bfc454b9e08 contourc.m: Overhaul function.
Rik <rik@octave.org>
parents: 28896
diff changeset
162 i += (clen + 1);
7327
9af6f0a214ee [project @ 2007-12-19 21:39:02 by jwe]
jwe
parents: 7245
diff changeset
163 endwhile
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
164 endif
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
165
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents:
diff changeset
166 endfunction
7245
d65670971cbc [project @ 2007-12-04 03:03:54 by jwe]
jwe
parents: 7017
diff changeset
167
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14327
diff changeset
168
8790
a013ff655ca4 Trivial changes to demos to produce a more pleasant output for octave+gnuplot+aquaterm.
Ben Abbott <bpabbott@mac.com>
parents: 8325
diff changeset
169 %!test
7245
d65670971cbc [project @ 2007-12-04 03:03:54 by jwe]
jwe
parents: 7017
diff changeset
170 %! x = 0:2;
d65670971cbc [project @ 2007-12-04 03:03:54 by jwe]
jwe
parents: 7017
diff changeset
171 %! y = x;
d65670971cbc [project @ 2007-12-04 03:03:54 by jwe]
jwe
parents: 7017
diff changeset
172 %! z = x' * y;
17451
56e72e8d1aba contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents: 17122
diff changeset
173 %! c_exp = [2, 1, 1, 2, 2, 3, 1.5, 2; 4, 2, 2, 1, 1, 2, 2, 1.5];
56e72e8d1aba contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents: 17122
diff changeset
174 %! lev_exp = [2 3];
56e72e8d1aba contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents: 17122
diff changeset
175 %! [c_obs, lev_obs] = contourc (x, y, z, 2:3);
56e72e8d1aba contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents: 17122
diff changeset
176 %! assert (c_obs, c_exp, eps);
56e72e8d1aba contourc.m: Code special case for meshgrid input (30X performance increase).
Rik <rik@octave.org>
parents: 17122
diff changeset
177 %! assert (lev_obs, lev_exp, eps);
26120
80643ff8c8b7 contourc.m: Tighten input validation to avoid segfault in __contourc__ (bug #55071).
Rik <rik@octave.org>
parents: 25054
diff changeset
178
80643ff8c8b7 contourc.m: Tighten input validation to avoid segfault in __contourc__ (bug #55071).
Rik <rik@octave.org>
parents: 25054
diff changeset
179 ## Test input validation
28896
90fea9cc9caa test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents: 27923
diff changeset
180 %!error <Invalid call> contourc ()
90fea9cc9caa test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents: 27923
diff changeset
181 %!error <Invalid call> contourc (1,2,3,4,5)
29278
7bfc454b9e08 contourc.m: Overhaul function.
Rik <rik@octave.org>
parents: 28896
diff changeset
182 %!error <X, Y, and Z must be .* numeric> contourc ({3})
7bfc454b9e08 contourc.m: Overhaul function.
Rik <rik@octave.org>
parents: 28896
diff changeset
183 %!error <X, Y, and Z must be .* numeric> contourc ({1}, 2, 3)
7bfc454b9e08 contourc.m: Overhaul function.
Rik <rik@octave.org>
parents: 28896
diff changeset
184 %!error <X, Y, and Z must be .* numeric> contourc (1, {2}, 3)
26120
80643ff8c8b7 contourc.m: Tighten input validation to avoid segfault in __contourc__ (bug #55071).
Rik <rik@octave.org>
parents: 25054
diff changeset
185 %!error <X, Y, and Z must be .* matrices> contourc (ones (3,3,3))
80643ff8c8b7 contourc.m: Tighten input validation to avoid segfault in __contourc__ (bug #55071).
Rik <rik@octave.org>
parents: 25054
diff changeset
186 %!error <X, Y, and Z must be .* matrices> contourc (ones (3,3,3), 2, 3)
80643ff8c8b7 contourc.m: Tighten input validation to avoid segfault in __contourc__ (bug #55071).
Rik <rik@octave.org>
parents: 25054
diff changeset
187 %!error <X, Y, and Z must be .* matrices> contourc (1, ones (3,3,3), 3)
29278
7bfc454b9e08 contourc.m: Overhaul function.
Rik <rik@octave.org>
parents: 28896
diff changeset
188 %!error <X, Y, and Z must be real> contourc (3i)
7bfc454b9e08 contourc.m: Overhaul function.
Rik <rik@octave.org>
parents: 28896
diff changeset
189 %!error <X, Y, and Z must be real> contourc (1i, 2, 3)
7bfc454b9e08 contourc.m: Overhaul function.
Rik <rik@octave.org>
parents: 28896
diff changeset
190 %!error <X, Y, and Z must be real> contourc (1, 2i, 3)
26120
80643ff8c8b7 contourc.m: Tighten input validation to avoid segfault in __contourc__ (bug #55071).
Rik <rik@octave.org>
parents: 25054
diff changeset
191 %!error <Z data must have at least 2 rows> contourc ([1, 2])
80643ff8c8b7 contourc.m: Tighten input validation to avoid segfault in __contourc__ (bug #55071).
Rik <rik@octave.org>
parents: 25054
diff changeset
192 %!error <Z data must have at least .* 2 columns> contourc ([1; 2])