annotate scripts/geometry/delaunay.m @ 31191:bb9d776eafac stable

Fix wrong color in PDF printout of some latex strings (bug #62884) * octave-svgconvert (draw): For "rect" elements only set brush color if necessary and eventually restore to previous color.
author Pantxo Diribarne <pantxo.diribarne@gmail.com>
date Sun, 14 Aug 2022 18:24:07 +0200
parents 796f54d4ddbf
children 597f3ee61a48
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 ##
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
3 ## Copyright (C) 1999-2022 The Octave Project Developers
27918
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26376
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/>.
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
7 ##
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
8 ## This file is part of Octave.
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
9 ##
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24266
diff changeset
10 ## Octave is free software: you can redistribute it and/or modify it
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
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: 24266
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.
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
14 ##
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
15 ## Octave is distributed in the hope that it will be useful, but
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
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.
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
19 ##
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
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: 6846
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: 24266
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 ########################################################################
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
25
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
26 ## -*- texinfo -*-
20852
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 19833
diff changeset
27 ## @deftypefn {} {@var{tri} =} delaunay (@var{x}, @var{y})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 19833
diff changeset
28 ## @deftypefnx {} {@var{tetr} =} delaunay (@var{x}, @var{y}, @var{z})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 19833
diff changeset
29 ## @deftypefnx {} {@var{tri} =} delaunay (@var{x})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 19833
diff changeset
30 ## @deftypefnx {} {@var{tri} =} delaunay (@dots{}, @var{options})
19164
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
31 ## Compute the Delaunay triangulation for a 2-D or 3-D set of points.
13746
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
32 ##
19164
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
33 ## For 2-D sets, the return value @var{tri} is a set of triangles which
24265
4746bd294c54 Fix definition of Delaunay triangulation in docstrings (bug #52416).
Rik <rik@octave.org>
parents: 23219
diff changeset
34 ## satisfies the Delaunay circum-circle criterion, i.e., no data point from
4746bd294c54 Fix definition of Delaunay triangulation in docstrings (bug #52416).
Rik <rik@octave.org>
parents: 23219
diff changeset
35 ## [@var{x}, @var{y}] is within the circum-circle of the defining triangle.
4746bd294c54 Fix definition of Delaunay triangulation in docstrings (bug #52416).
Rik <rik@octave.org>
parents: 23219
diff changeset
36 ## The set of triangles @var{tri} is a matrix of size [n, 3]. Each row defines
4746bd294c54 Fix definition of Delaunay triangulation in docstrings (bug #52416).
Rik <rik@octave.org>
parents: 23219
diff changeset
37 ## a triangle and the three columns are the three vertices of the triangle.
4746bd294c54 Fix definition of Delaunay triangulation in docstrings (bug #52416).
Rik <rik@octave.org>
parents: 23219
diff changeset
38 ## The value of @code{@var{tri}(i,j)} is an index into @var{x} and @var{y} for
4746bd294c54 Fix definition of Delaunay triangulation in docstrings (bug #52416).
Rik <rik@octave.org>
parents: 23219
diff changeset
39 ## the location of the j-th vertex of the i-th triangle.
19164
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
40 ##
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
41 ## For 3-D sets, the return value @var{tetr} is a set of tetrahedrons which
24265
4746bd294c54 Fix definition of Delaunay triangulation in docstrings (bug #52416).
Rik <rik@octave.org>
parents: 23219
diff changeset
42 ## satisfies the Delaunay circum-circle criterion, i.e., no data point from
4746bd294c54 Fix definition of Delaunay triangulation in docstrings (bug #52416).
Rik <rik@octave.org>
parents: 23219
diff changeset
43 ## [@var{x}, @var{y}, @var{z}] is within the circum-circle of the defining
4746bd294c54 Fix definition of Delaunay triangulation in docstrings (bug #52416).
Rik <rik@octave.org>
parents: 23219
diff changeset
44 ## tetrahedron. The set of tetrahedrons is a matrix of size [n, 4]. Each row
4746bd294c54 Fix definition of Delaunay triangulation in docstrings (bug #52416).
Rik <rik@octave.org>
parents: 23219
diff changeset
45 ## defines a tetrahedron and the four columns are the four vertices of the
4746bd294c54 Fix definition of Delaunay triangulation in docstrings (bug #52416).
Rik <rik@octave.org>
parents: 23219
diff changeset
46 ## tetrahedron. The value of @code{@var{tetr}(i,j)} is an index into @var{x},
4746bd294c54 Fix definition of Delaunay triangulation in docstrings (bug #52416).
Rik <rik@octave.org>
parents: 23219
diff changeset
47 ## @var{y}, @var{z} for the location of the j-th vertex of the i-th
19164
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
48 ## tetrahedron.
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
49 ##
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
50 ## The input @var{x} may also be a matrix with two or three columns where the
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
51 ## first column contains x-data, the second y-data, and the optional third
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
52 ## column contains z-data.
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
53 ##
26098
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
54 ## An optional final argument, which must be a string or cell array of strings,
13746
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
55 ## contains options passed to the underlying qhull command.
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
56 ## See the documentation for the Qhull library for details
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
57 ## @url{http://www.qhull.org/html/qh-quick.htm#options}.
28027
2e6dc7e2b191 Use appropriate Qhull options as necessary to obtain triangulation (bug #50494).
Rik <rik@octave.org>
parents: 27923
diff changeset
58 ## The default options are @code{@{"Qt", "Qbb", "Qc"@}}.
28714
d8dcb36bb904 maint: spellcheck documentation ahead of 6.1 release.
Rik <rik@octave.org>
parents: 28027
diff changeset
59 ## If Qhull fails for 2-D input the triangulation is attempted again with
28027
2e6dc7e2b191 Use appropriate Qhull options as necessary to obtain triangulation (bug #50494).
Rik <rik@octave.org>
parents: 27923
diff changeset
60 ## the options @code{@{"Qt", "Qbb", "Qc", "Qz"@}} which may result in
2e6dc7e2b191 Use appropriate Qhull options as necessary to obtain triangulation (bug #50494).
Rik <rik@octave.org>
parents: 27923
diff changeset
61 ## reduced accuracy.
13746
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
62 ##
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
63 ## If @var{options} is not present or @code{[]} then the default arguments are
19593
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
64 ## used. Otherwise, @var{options} replaces the default argument list.
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
65 ## To append user options to the defaults it is necessary to repeat the
13746
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
66 ## default arguments in @var{options}. Use a null string to pass no arguments.
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
67 ##
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
68 ## @example
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
69 ## @group
6826
8618f29520c6 [project @ 2007-08-24 16:02:07 by jwe]
jwe
parents: 6823
diff changeset
70 ## x = rand (1, 10);
13746
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
71 ## y = rand (1, 10);
19164
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
72 ## tri = delaunay (x, y);
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
73 ## triplot (tri, x, y);
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
74 ## hold on;
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
75 ## plot (x, y, "r*");
6826
8618f29520c6 [project @ 2007-08-24 16:02:07 by jwe]
jwe
parents: 6823
diff changeset
76 ## axis ([0,1,0,1]);
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
77 ## @end group
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
78 ## @end example
19164
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
79 ## @seealso{delaunayn, convhull, voronoi, triplot, trimesh, tetramesh, trisurf}
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
80 ## @end deftypefn
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
81
16928
7c4a6197e020 delaunay.m: Accept a single matrix as input.
Rik <rik@octave.org>
parents: 14541
diff changeset
82 function tri = delaunay (varargin)
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
83
19164
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
84 if (nargin < 1 || nargin > 4)
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
85 print_usage ();
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
86 endif
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
87
19164
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
88 z = [];
16928
7c4a6197e020 delaunay.m: Accept a single matrix as input.
Rik <rik@octave.org>
parents: 14541
diff changeset
89 options = [];
7c4a6197e020 delaunay.m: Accept a single matrix as input.
Rik <rik@octave.org>
parents: 14541
diff changeset
90
7c4a6197e020 delaunay.m: Accept a single matrix as input.
Rik <rik@octave.org>
parents: 14541
diff changeset
91 switch (nargin)
7c4a6197e020 delaunay.m: Accept a single matrix as input.
Rik <rik@octave.org>
parents: 14541
diff changeset
92
17174
c3c1ebfaa7dc maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents: 17132
diff changeset
93 case 1
19164
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
94 if (! ismatrix (varargin{1})
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
95 || (columns (varargin{1}) != 2 && columns (varargin{1}) != 3))
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
96 error ("delaunay: X must be a matrix with 2 or 3 columns");
16928
7c4a6197e020 delaunay.m: Accept a single matrix as input.
Rik <rik@octave.org>
parents: 14541
diff changeset
97 else
7c4a6197e020 delaunay.m: Accept a single matrix as input.
Rik <rik@octave.org>
parents: 14541
diff changeset
98 x = varargin{1}(:,1);
7c4a6197e020 delaunay.m: Accept a single matrix as input.
Rik <rik@octave.org>
parents: 14541
diff changeset
99 y = varargin{1}(:,2);
19164
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
100 if (columns (varargin{1}) == 3)
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
101 z = varargin{1}(:,3);
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
102 endif
16928
7c4a6197e020 delaunay.m: Accept a single matrix as input.
Rik <rik@octave.org>
parents: 14541
diff changeset
103 endif
19593
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
104
17174
c3c1ebfaa7dc maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents: 17132
diff changeset
105 case 2
c3c1ebfaa7dc maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents: 17132
diff changeset
106 if (isnumeric (varargin{2}))
c3c1ebfaa7dc maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents: 17132
diff changeset
107 x = varargin{1};
c3c1ebfaa7dc maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents: 17132
diff changeset
108 y = varargin{2};
19164
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
109 elseif (! (ischar (varargin{2}) || iscellstr (varargin{2})))
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
110 error ("delaunay: OPTIONS must be a string or cell array of strings");
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
111 else
17174
c3c1ebfaa7dc maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents: 17132
diff changeset
112 options = varargin{2};
19164
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
113 ncols = columns (varargin{1});
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
114
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
115 if (! ismatrix (varargin{1}) || (ncols != 2 && ncols != 3))
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
116 error ("delaunay: X must be a matrix with 2 or 3 columns");
17174
c3c1ebfaa7dc maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents: 17132
diff changeset
117 else
c3c1ebfaa7dc maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents: 17132
diff changeset
118 x = varargin{1}(:,1);
c3c1ebfaa7dc maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents: 17132
diff changeset
119 y = varargin{1}(:,2);
19164
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
120 if (ncols == 3)
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
121 z = varargin{1}(:,3);
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
122 endif
17174
c3c1ebfaa7dc maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents: 17132
diff changeset
123 endif
c3c1ebfaa7dc maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents: 17132
diff changeset
124 endif
16928
7c4a6197e020 delaunay.m: Accept a single matrix as input.
Rik <rik@octave.org>
parents: 14541
diff changeset
125
17174
c3c1ebfaa7dc maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents: 17132
diff changeset
126 case 3
19164
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
127 if (isnumeric (varargin{3}))
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
128 x = varargin{1};
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
129 y = varargin{2};
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
130 z = varargin{3};
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
131 elseif (! (ischar (varargin{3}) || iscellstr (varargin{3})))
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
132 error ("delaunay: OPTIONS must be a string or cell array of strings");
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
133 else
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
134 x = varargin{1};
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
135 y = varargin{2};
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
136 options = varargin{3};
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
137 endif
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
138
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
139 case 4
17174
c3c1ebfaa7dc maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents: 17132
diff changeset
140 x = varargin{1};
c3c1ebfaa7dc maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents: 17132
diff changeset
141 y = varargin{2};
19164
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
142 z = varargin{3};
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
143 options = varargin{4};
16928
7c4a6197e020 delaunay.m: Accept a single matrix as input.
Rik <rik@octave.org>
parents: 14541
diff changeset
144
17174
c3c1ebfaa7dc maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents: 17132
diff changeset
145 if (! (ischar (options) || iscellstr (options)))
c3c1ebfaa7dc maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents: 17132
diff changeset
146 error ("delaunay: OPTIONS must be a string or cell array of strings");
c3c1ebfaa7dc maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents: 17132
diff changeset
147 endif
16928
7c4a6197e020 delaunay.m: Accept a single matrix as input.
Rik <rik@octave.org>
parents: 14541
diff changeset
148
7c4a6197e020 delaunay.m: Accept a single matrix as input.
Rik <rik@octave.org>
parents: 14541
diff changeset
149 endswitch
7c4a6197e020 delaunay.m: Accept a single matrix as input.
Rik <rik@octave.org>
parents: 14541
diff changeset
150
19164
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
151 if (isempty (z))
26098
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
152 x = x(:); y = y(:);
19164
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
153 if (! size_equal (x, y))
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
154 error ("delaunay: X and Y must be the same size");
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
155 endif
26098
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
156 tri = delaunayn ([x, y], options);
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
157 else
26098
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
158 x = x(:); y = y(:); z = z(:);
19164
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
159 if (! size_equal (x, y, z))
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
160 error ("delaunay: X, Y, and Z must be the same size");
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
161 endif
26098
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
162 tri = delaunayn ([x, y, z], options);
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
163 endif
13746
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
164
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
165 endfunction
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
166
13746
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
167
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
168 %!demo
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
169 %! old_state = rand ("state");
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
170 %! restore_state = onCleanup (@() rand ("state", old_state));
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
171 %! rand ("state", 1);
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
172 %! x = rand (1,10);
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
173 %! y = rand (1,10);
19164
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
174 %! tri = delaunay (x,y);
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
175 %! clf;
19164
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
176 %! triplot (tri, x, y);
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
177 %! hold on;
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
178 %! plot (x, y, "r*");
13746
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
179 %! axis ([0,1,0,1]);
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
180
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
181 %!testif HAVE_QHULL
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
182 %! x = [-1, 0, 1, 0];
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
183 %! y = [0, 1, 0, -1];
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
184 %! assert (sortrows (sort (delaunay (x, y), 2)), [1,2,4;2,3,4]);
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
185
8153
ec0a13863eb7 Only run tests that depend on HDF5 and QHull if Octave was actually
Soren Hauberg <hauberg@gmail.com>
parents: 7017
diff changeset
186 %!testif HAVE_QHULL
16928
7c4a6197e020 delaunay.m: Accept a single matrix as input.
Rik <rik@octave.org>
parents: 14541
diff changeset
187 %! x = [-1, 0, 1, 0];
7c4a6197e020 delaunay.m: Accept a single matrix as input.
Rik <rik@octave.org>
parents: 14541
diff changeset
188 %! y = [0, 1, 0, -1];
26098
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
189 %! mat = [x(:), y(:)];
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
190 %! assert (sortrows (sort (delaunay (mat), 2)), [1,2,4;2,3,4]);
16928
7c4a6197e020 delaunay.m: Accept a single matrix as input.
Rik <rik@octave.org>
parents: 14541
diff changeset
191
7c4a6197e020 delaunay.m: Accept a single matrix as input.
Rik <rik@octave.org>
parents: 14541
diff changeset
192 %!testif HAVE_QHULL
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
193 %! x = [-1, 0, 1, 0, 0];
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
194 %! y = [0, 1, 0, -1, 0];
13746
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
195 %! assert (sortrows (sort (delaunay (x, y), 2)), [1,2,5;1,4,5;2,3,5;3,4,5]);
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
196
17132
f72ffae1fcc3 delaunay.m: Fixed matlab compatibility and input check for single matrix (bug #39644)
Andreas Weber <andreas.weber@hs-offenburg.de>
parents: 16932
diff changeset
197 %!testif HAVE_QHULL
f72ffae1fcc3 delaunay.m: Fixed matlab compatibility and input check for single matrix (bug #39644)
Andreas Weber <andreas.weber@hs-offenburg.de>
parents: 16932
diff changeset
198 %! x = [-1, 0; 0, 1; 1, 0; 0, -1; 0, 0];
f72ffae1fcc3 delaunay.m: Fixed matlab compatibility and input check for single matrix (bug #39644)
Andreas Weber <andreas.weber@hs-offenburg.de>
parents: 16932
diff changeset
199 %! assert (sortrows (sort (delaunay (x), 2)), [1,2,5;1,4,5;2,3,5;3,4,5]);
f72ffae1fcc3 delaunay.m: Fixed matlab compatibility and input check for single matrix (bug #39644)
Andreas Weber <andreas.weber@hs-offenburg.de>
parents: 16932
diff changeset
200
f72ffae1fcc3 delaunay.m: Fixed matlab compatibility and input check for single matrix (bug #39644)
Andreas Weber <andreas.weber@hs-offenburg.de>
parents: 16932
diff changeset
201 %!testif HAVE_QHULL
f72ffae1fcc3 delaunay.m: Fixed matlab compatibility and input check for single matrix (bug #39644)
Andreas Weber <andreas.weber@hs-offenburg.de>
parents: 16932
diff changeset
202 %! x = [1 5 2; 5 6 7];
f72ffae1fcc3 delaunay.m: Fixed matlab compatibility and input check for single matrix (bug #39644)
Andreas Weber <andreas.weber@hs-offenburg.de>
parents: 16932
diff changeset
203 %! y = [5 7 8; 1 2 3];
f72ffae1fcc3 delaunay.m: Fixed matlab compatibility and input check for single matrix (bug #39644)
Andreas Weber <andreas.weber@hs-offenburg.de>
parents: 16932
diff changeset
204 %! assert (sortrows (sort (delaunay (x, y), 2)), [1,2,4;1,3,4;1,3,5;3,4,6]);
f72ffae1fcc3 delaunay.m: Fixed matlab compatibility and input check for single matrix (bug #39644)
Andreas Weber <andreas.weber@hs-offenburg.de>
parents: 16932
diff changeset
205
19164
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
206 ## Test 3-D input
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
207 %!testif HAVE_QHULL
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
208 %! x = [-1, -1, 1, 0, -1]; y = [-1, 1, 1, 0, -1]; z = [0, 0, 0, 1, 1];
21580
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 20852
diff changeset
209 %! assert (sortrows (sort (delaunay (x, y, z), 2)), [1,2,3,4;1,2,4,5]);
17338
1c89599167a6 maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents: 17174
diff changeset
210
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
211 ## Input validation tests
28896
90fea9cc9caa test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents: 28714
diff changeset
212 %!error <Invalid call> delaunay ()
90fea9cc9caa test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents: 28714
diff changeset
213 %!error <Invalid call> delaunay (1,2,3,4,5)
19164
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
214 %!error <X must be a matrix with 2 or 3 columns> delaunay (ones (2,4))
28912
0de38a6ef693 maint: Use Octave convention of space after function name in scripts dir.
Rik <rik@octave.org>
parents: 28896
diff changeset
215 %!error <OPTIONS must be a string or cell array> delaunay (ones (2,2), struct ())
19164
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
216 %!error <X must be a matrix with 2 or 3 columns> delaunay (ones (2,4), "")
28912
0de38a6ef693 maint: Use Octave convention of space after function name in scripts dir.
Rik <rik@octave.org>
parents: 28896
diff changeset
217 %!error <OPTIONS must be a string or cell array> delaunay (ones (2,2), ones (2,2), struct ())
0de38a6ef693 maint: Use Octave convention of space after function name in scripts dir.
Rik <rik@octave.org>
parents: 28896
diff changeset
218 %!error <OPTIONS must be a string or cell array> delaunay (ones (2,2), ones (2,2), ones (2,2), struct ())
19164
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
219 %!error <X and Y must be the same size> delaunay (1, [1 2])
ba167badef9f Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents: 17744
diff changeset
220 %!error <X, Y, and Z must be the same size> delaunay (1, [1 2], [1 2])