Mercurial > octave
annotate scripts/geometry/voronoi.m @ 28896:90fea9cc9caa
test: Add expected error message <Invalid call> to BIST tests for nargin.
* acosd.m, acot.m, acotd.m, acoth.m, acsc.m, acscd.m, acsch.m, asec.m,
asecd.m, asech.m, asind.m, atand.m, cosd.m, cot.m, cotd.m, coth.m, csc.m,
cscd.m, csch.m, sec.m, secd.m, sech.m, sind.m, tand.m, cart2pol.m, cart2sph.m,
celldisp.m, common_size.m, deal.m, del2.m, fliplr.m, integral2.m, interp1.m,
isequal.m, isequaln.m, nextpow2.m, pol2cart.m, quad2d.m, quadl.m, quadv.m,
randi.m, rat.m, repelem.m, rescale.m, shiftdim.m, sortrows.m, sph2cart.m,
xor.m, convhull.m, delaunay.m, delaunayn.m, griddata.m, griddatan.m,
inpolygon.m, voronoi.m, voronoin.m, listdlg.m, msgbox.m, questdlg.m,
rmappdata.m, setappdata.m, __gripe_missing_component__.m,
get_first_help_sentence.m, type.m, which.m, cmpermute.m, cmunique.m,
gray2ind.m, imfinfo.m, imshow.m, imwrite.m, ind2rgb.m, movie.m, rgb2ind.m,
importdata.m, bandwidth.m, condeig.m, gls.m, housh.m, linsolve.m, logm.m,
lscov.m, normest.m, normest1.m, ols.m, ordeig.m, planerot.m, qzhess.m, rref.m,
copyfile.m, delete.m, dos.m, fileparts.m, getfield.m, menu.m, mkdir.m,
movefile.m, orderfields.m, publish.m, setfield.m, substruct.m, unix.m,
unpack.m, decic.m, ode23.m, ode23s.m, ode45.m, fminsearch.m, lsqnonneg.m,
pqpnonneg.m, sqp.m, annotation.m, lighting.m, shading.m, area.m, compass.m,
contourc.m, feather.m, fplot.m, hist.m, isocaps.m, isocolors.m, isonormals.m,
isosurface.m, ostreamtube.m, pie.m, pie3.m, reducepatch.m, reducevolume.m,
rose.m, smooth3.m, stairs.m, stem.m, stem3.m, stream2.m, stream3.m,
streamline.m, streamribbon.m, streamtube.m, surfnorm.m, trimesh.m, trisurf.m,
colstyle.m, hgload.m, linkprop.m, meshgrid.m, ndgrid.m, padecoef.m, polyfit.m,
polyval.m, unmkpp.m, profexport.m, ismember.m, unique.m, movfun.m, movslice.m,
periodogram.m, sinc.m, spdiags.m, sprandsym.m, betaincinv.m, ellipke.m,
factor.m, gammainc.m, gammaincinv.m, isprime.m, lcm.m, gallery.m, hadamard.m,
bounds.m, corrcoef.m, discrete_rnd.m, empirical_rnd.m, histc.m, mode.m,
movmad.m, movmax.m, movmean.m, movmedian.m, movmin.m, movprod.m, movstd.m,
movsum.m, movvar.m, ranks.m, runlength.m, zscore.m, str2num.m, strchr.m,
strsplit.m, strtok.m, untabify.m, assert.m, demo.m, example.m, speed.m, test.m,
datenum.m, datevec.m, webread.m, webwrite.m:
Add expected error message <Invalid call> to BIST tests for nargin.
Remove redundant tests for nargin greater than the number of declared inputs
which are now handled by interpreter.
author | Rik <rik@octave.org> |
---|---|
date | Sun, 11 Oct 2020 21:59:35 -0700 |
parents | a4268efb7334 |
children | 7854d5752dd2 |
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 ## |
27919
1891570abac8
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
27918
diff
changeset
|
3 ## Copyright (C) 2000-2020 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 | 7 ## |
8 ## This file is part of Octave. | |
9 ## | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
10 ## Octave is free software: you can redistribute it and/or modify it |
6823 | 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:
24432
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:
22707
diff
changeset
|
13 ## (at your option) any later version. |
6823 | 14 ## |
15 ## Octave is distributed in the hope that it will be useful, but | |
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22707
diff
changeset
|
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22707
diff
changeset
|
18 ## GNU General Public License for more details. |
6823 | 19 ## |
20 ## You should have received a copy of the GNU General Public License | |
7016 | 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:
24432
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 | 25 |
26 ## -*- texinfo -*- | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20835
diff
changeset
|
27 ## @deftypefn {} {} voronoi (@var{x}, @var{y}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20835
diff
changeset
|
28 ## @deftypefnx {} {} voronoi (@var{x}, @var{y}, @var{options}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20835
diff
changeset
|
29 ## @deftypefnx {} {} voronoi (@dots{}, "linespec") |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20835
diff
changeset
|
30 ## @deftypefnx {} {} voronoi (@var{hax}, @dots{}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20835
diff
changeset
|
31 ## @deftypefnx {} {@var{h} =} voronoi (@dots{}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20835
diff
changeset
|
32 ## @deftypefnx {} {[@var{vx}, @var{vy}] =} voronoi (@dots{}) |
13746
7ff0bdc3dc4c
Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents:
12931
diff
changeset
|
33 ## Plot the Voronoi diagram of points @code{(@var{x}, @var{y})}. |
20158
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
34 ## |
10791
3140cb7a05a1
Add spellchecker scripts for Octave and run spellcheck of documentation
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
35 ## The Voronoi facets with points at infinity are not drawn. |
19593
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
36 ## |
13746
7ff0bdc3dc4c
Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents:
12931
diff
changeset
|
37 ## The @var{options} argument, which must be a string or cell array of strings, |
7ff0bdc3dc4c
Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents:
12931
diff
changeset
|
38 ## 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:
12931
diff
changeset
|
39 ## 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:
12931
diff
changeset
|
40 ## @url{http://www.qhull.org/html/qh-quick.htm#options}. |
7ff0bdc3dc4c
Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents:
12931
diff
changeset
|
41 ## |
20158
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
42 ## If @qcode{"linespec"} is given it is used to set the color and line style of |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
43 ## the plot. |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
44 ## |
24431
0c6cedafc71e
doc: Use 'axes' rather than 'axis' appropriately in docstrings.
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
45 ## If an axes graphics handle @var{hax} is supplied then the Voronoi diagram is |
0c6cedafc71e
doc: Use 'axes' rather than 'axis' appropriately in docstrings.
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
46 ## drawn on the specified axes rather than in a new figure. |
20158
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
47 ## |
13746
7ff0bdc3dc4c
Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents:
12931
diff
changeset
|
48 ## If a single output argument is requested then the Voronoi diagram will be |
14001
5f0bb45e615c
doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents:
13879
diff
changeset
|
49 ## plotted and a graphics handle @var{h} to the plot is returned. |
20158
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
50 ## |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14335
diff
changeset
|
51 ## [@var{vx}, @var{vy}] = voronoi (@dots{}) returns the Voronoi vertices |
13746
7ff0bdc3dc4c
Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents:
12931
diff
changeset
|
52 ## instead of plotting the diagram. |
6823 | 53 ## |
54 ## @example | |
55 ## @group | |
14327
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
56 ## x = rand (10, 1); |
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
57 ## y = rand (size (x)); |
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
58 ## h = convhull (x, y); |
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
59 ## [vx, vy] = voronoi (x, y); |
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
60 ## plot (vx, vy, "-b", x, y, "o", x(h), y(h), "-g"); |
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
61 ## legend ("", "points", "hull"); |
6823 | 62 ## @end group |
63 ## @end example | |
64 ## | |
65 ## @seealso{voronoin, delaunay, convhull} | |
66 ## @end deftypefn | |
67 | |
13746
7ff0bdc3dc4c
Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents:
12931
diff
changeset
|
68 function [vx, vy] = voronoi (varargin) |
6823 | 69 |
70 if (nargin < 1) | |
71 print_usage (); | |
72 endif | |
73 | |
74 narg = 1; | |
18201
0ecd4618b1fc
voronoi.m: Fix input validation so it doesn't open blank figure window.
Rik <rik@octave.org>
parents:
18193
diff
changeset
|
75 hax = NaN; |
24423
1d52db450db4
Change ishandle to return true for Java objects for Matlab compatibility.
Rik <rik@octave.org>
parents:
23573
diff
changeset
|
76 if (isscalar (varargin{1}) && ishghandle (varargin{1})) |
17125
b5d6314314fc
Change various plot functions to take advantage of new isaxes() function.
Rik <rik@octave.org>
parents:
15393
diff
changeset
|
77 hax = varargin{1}; |
18193
31d8e19a745d
voronoi.m: Add input validation test for 2 points (bug #40996)
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
78 if (! isaxes (hax)) |
31d8e19a745d
voronoi.m: Add input validation test for 2 points (bug #40996)
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
79 error ("voronoi: HAX argument must be an axes object"); |
6823 | 80 endif |
20735
418ae0cb752f
Replace ++,-- with in-place operators for performance.
Rik <rik@octave.org>
parents:
20158
diff
changeset
|
81 narg += 1; |
6823 | 82 endif |
83 | |
84 if (nargin < 1 + narg || nargin > 3 + narg) | |
85 print_usage (); | |
86 endif | |
87 | |
88 x = varargin{narg++}; | |
89 y = varargin{narg++}; | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
90 |
6823 | 91 opts = {}; |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
92 if (narg <= nargin) |
6823 | 93 if (iscell (varargin{narg})) |
94 opts = varargin(narg++); | |
13746
7ff0bdc3dc4c
Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents:
12931
diff
changeset
|
95 elseif (isnumeric (varargin{narg})) |
7ff0bdc3dc4c
Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents:
12931
diff
changeset
|
96 ## Accept, but ignore, the triangulation |
20735
418ae0cb752f
Replace ++,-- with in-place operators for performance.
Rik <rik@octave.org>
parents:
20158
diff
changeset
|
97 narg += 1; |
6823 | 98 endif |
99 endif | |
100 | |
101 linespec = {"b"}; | |
13746
7ff0bdc3dc4c
Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents:
12931
diff
changeset
|
102 if (narg <= nargin && ischar (varargin{narg})) |
7ff0bdc3dc4c
Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents:
12931
diff
changeset
|
103 linespec = varargin(narg); |
6823 | 104 endif |
105 | |
22697
8acad59ecec0
voronoi.m: Overhaul function to produce correct number of edges (bug #38295).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
106 if (! isvector (x) || ! isvector (y) || numel (x) != numel (y)) |
13746
7ff0bdc3dc4c
Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents:
12931
diff
changeset
|
107 error ("voronoi: X and Y must be vectors of the same length"); |
22697
8acad59ecec0
voronoi.m: Overhaul function to produce correct number of edges (bug #38295).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
108 elseif (numel (x) < 2) |
8acad59ecec0
voronoi.m: Overhaul function to produce correct number of edges (bug #38295).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
109 error ("voronoi: minimum of 2 points required"); |
6823 | 110 endif |
22697
8acad59ecec0
voronoi.m: Overhaul function to produce correct number of edges (bug #38295).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
111 x = x(:); |
8acad59ecec0
voronoi.m: Overhaul function to produce correct number of edges (bug #38295).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
112 y = y(:); |
6823 | 113 |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
114 ## Add box to approximate rays to infinity. For Voronoi diagrams the |
22697
8acad59ecec0
voronoi.m: Overhaul function to produce correct number of edges (bug #38295).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
115 ## box should be close to the points themselves. To make the job of |
8acad59ecec0
voronoi.m: Overhaul function to produce correct number of edges (bug #38295).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
116 ## finding the exterior edges easier it should be bigger than the area |
8acad59ecec0
voronoi.m: Overhaul function to produce correct number of edges (bug #38295).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
117 ## enclosed by the points themselves. |
8acad59ecec0
voronoi.m: Overhaul function to produce correct number of edges (bug #38295).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
118 ## NOTE: Octave uses a factor of 2 although we don't have an mathematical |
8acad59ecec0
voronoi.m: Overhaul function to produce correct number of edges (bug #38295).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
119 ## justification for that. |
8acad59ecec0
voronoi.m: Overhaul function to produce correct number of edges (bug #38295).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
120 |
8acad59ecec0
voronoi.m: Overhaul function to produce correct number of edges (bug #38295).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
121 xmin = min (x); |
8acad59ecec0
voronoi.m: Overhaul function to produce correct number of edges (bug #38295).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
122 xmax = max (x); |
8acad59ecec0
voronoi.m: Overhaul function to produce correct number of edges (bug #38295).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
123 ymin = min (y); |
8acad59ecec0
voronoi.m: Overhaul function to produce correct number of edges (bug #38295).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
124 ymax = max (y); |
8acad59ecec0
voronoi.m: Overhaul function to produce correct number of edges (bug #38295).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
125 ## Factor for size of bounding box |
8acad59ecec0
voronoi.m: Overhaul function to produce correct number of edges (bug #38295).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
126 scale = 2; |
6852 | 127 xdelta = xmax - xmin; |
128 ydelta = ymax - ymin; | |
22697
8acad59ecec0
voronoi.m: Overhaul function to produce correct number of edges (bug #38295).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
129 xbox = [xmin - scale * xdelta; xmin - scale * xdelta; |
10549 | 130 xmax + scale * xdelta; xmax + scale * xdelta]; |
22697
8acad59ecec0
voronoi.m: Overhaul function to produce correct number of edges (bug #38295).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
131 ybox = [ymin - scale * ydelta; ymax + scale * ydelta; |
14865
70f86a64c412
* voronoi.m: Fix cut and paste error.
Nicholas Musolino <musolino@mit.edu>
parents:
14327
diff
changeset
|
132 ymax + scale * ydelta; ymin - scale * ydelta]; |
6852 | 133 |
22697
8acad59ecec0
voronoi.m: Overhaul function to produce correct number of edges (bug #38295).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
134 [p, c, infi] = __voronoi__ ("voronoi", [[x; xbox], [y; ybox]], opts{:}); |
6823 | 135 |
22697
8acad59ecec0
voronoi.m: Overhaul function to produce correct number of edges (bug #38295).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
136 ## Build list of edges from points in facet. |
15393
b99c52303d0b
voronoi.m: Fix bug when there are multiple identical input points (bug #37270)
Rik <rik@octave.org>
parents:
14881
diff
changeset
|
137 c = c(! infi).'; |
22697
8acad59ecec0
voronoi.m: Overhaul function to produce correct number of edges (bug #38295).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
138 edges = zeros (2, 0); |
8acad59ecec0
voronoi.m: Overhaul function to produce correct number of edges (bug #38295).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
139 for i = 1:numel (c) |
8acad59ecec0
voronoi.m: Overhaul function to produce correct number of edges (bug #38295).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
140 facet = c{i}; |
22707
413a19bca7f3
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22697
diff
changeset
|
141 if (isempty (facet)) |
22697
8acad59ecec0
voronoi.m: Overhaul function to produce correct number of edges (bug #38295).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
142 continue; |
8acad59ecec0
voronoi.m: Overhaul function to produce correct number of edges (bug #38295).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
143 endif |
8acad59ecec0
voronoi.m: Overhaul function to produce correct number of edges (bug #38295).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
144 edges = [edges, [facet; [facet(end), facet(1:end-1)]]]; |
8acad59ecec0
voronoi.m: Overhaul function to produce correct number of edges (bug #38295).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
145 endfor |
6823 | 146 |
22697
8acad59ecec0
voronoi.m: Overhaul function to produce correct number of edges (bug #38295).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
147 ## Keep only the unique edges of the Voronoi diagram |
6823 | 148 edges = sortrows (sort (edges).').'; |
22697
8acad59ecec0
voronoi.m: Overhaul function to produce correct number of edges (bug #38295).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
149 edges = edges(:, [any(diff(edges, 1, 2)), true]); |
6852 | 150 |
18203
5646f999245d
voronoi.m: Add special handling for 2-point input (bug #40996).
Rik <rik@octave.org>
parents:
18201
diff
changeset
|
151 if (numel (x) > 2) |
22697
8acad59ecec0
voronoi.m: Overhaul function to produce correct number of edges (bug #38295).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
152 ## Eliminate the edges of the diagram representing the box. |
8acad59ecec0
voronoi.m: Overhaul function to produce correct number of edges (bug #38295).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
153 ## Exclude points outside a certain radius from the center of distribution. |
8acad59ecec0
voronoi.m: Overhaul function to produce correct number of edges (bug #38295).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
154 ## FIXME: Factor should be at least 1.0. Octave uses 1.1 for margin. |
8acad59ecec0
voronoi.m: Overhaul function to produce correct number of edges (bug #38295).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
155 ## There is no theoretical justification for this choice. |
8acad59ecec0
voronoi.m: Overhaul function to produce correct number of edges (bug #38295).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
156 ctr = [(xmax + xmin)/2 , (ymax + ymin)/2]; |
8acad59ecec0
voronoi.m: Overhaul function to produce correct number of edges (bug #38295).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
157 radius = 1.1 * sumsq ([xmin, ymin] - ctr); |
8acad59ecec0
voronoi.m: Overhaul function to produce correct number of edges (bug #38295).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
158 dist = sumsq (p - ctr, 2); |
8acad59ecec0
voronoi.m: Overhaul function to produce correct number of edges (bug #38295).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
159 |
22707
413a19bca7f3
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22697
diff
changeset
|
160 p_inside = (1:rows (p))(dist < radius); |
22697
8acad59ecec0
voronoi.m: Overhaul function to produce correct number of edges (bug #38295).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
161 edge_inside = any (ismember (edges, p_inside)); |
8acad59ecec0
voronoi.m: Overhaul function to produce correct number of edges (bug #38295).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
162 edges = edges(:, edge_inside); |
18203
5646f999245d
voronoi.m: Add special handling for 2-point input (bug #40996).
Rik <rik@octave.org>
parents:
18201
diff
changeset
|
163 else |
5646f999245d
voronoi.m: Add special handling for 2-point input (bug #40996).
Rik <rik@octave.org>
parents:
18201
diff
changeset
|
164 ## look for the edge between the two given points |
22697
8acad59ecec0
voronoi.m: Overhaul function to produce correct number of edges (bug #38295).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
165 for edge = edges |
18203
5646f999245d
voronoi.m: Add special handling for 2-point input (bug #40996).
Rik <rik@octave.org>
parents:
18201
diff
changeset
|
166 if (det ([[[1;1],p(edge,1:2)];1,x(1),y(1)]) |
5646f999245d
voronoi.m: Add special handling for 2-point input (bug #40996).
Rik <rik@octave.org>
parents:
18201
diff
changeset
|
167 * det ([[[1;1],p(edge,1:2)];1,x(2),y(2)]) < 0) |
5646f999245d
voronoi.m: Add special handling for 2-point input (bug #40996).
Rik <rik@octave.org>
parents:
18201
diff
changeset
|
168 edges = edge; |
5646f999245d
voronoi.m: Add special handling for 2-point input (bug #40996).
Rik <rik@octave.org>
parents:
18201
diff
changeset
|
169 break; |
5646f999245d
voronoi.m: Add special handling for 2-point input (bug #40996).
Rik <rik@octave.org>
parents:
18201
diff
changeset
|
170 endif |
5646f999245d
voronoi.m: Add special handling for 2-point input (bug #40996).
Rik <rik@octave.org>
parents:
18201
diff
changeset
|
171 endfor |
5646f999245d
voronoi.m: Add special handling for 2-point input (bug #40996).
Rik <rik@octave.org>
parents:
18201
diff
changeset
|
172 ## Use larger plot limits to make it more likely single bisector is shown. |
5646f999245d
voronoi.m: Add special handling for 2-point input (bug #40996).
Rik <rik@octave.org>
parents:
18201
diff
changeset
|
173 xdelta = ydelta = max (xdelta, ydelta); |
5646f999245d
voronoi.m: Add special handling for 2-point input (bug #40996).
Rik <rik@octave.org>
parents:
18201
diff
changeset
|
174 endif |
6823 | 175 |
176 ## Get points of the diagram | |
13746
7ff0bdc3dc4c
Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents:
12931
diff
changeset
|
177 Vvx = reshape (p(edges, 1), size (edges)); |
7ff0bdc3dc4c
Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents:
12931
diff
changeset
|
178 Vvy = reshape (p(edges, 2), size (edges)); |
6823 | 179 |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
180 if (nargout < 2) |
18201
0ecd4618b1fc
voronoi.m: Fix input validation so it doesn't open blank figure window.
Rik <rik@octave.org>
parents:
18193
diff
changeset
|
181 if (isnan (hax)) |
0ecd4618b1fc
voronoi.m: Fix input validation so it doesn't open blank figure window.
Rik <rik@octave.org>
parents:
18193
diff
changeset
|
182 hax = gca (); |
0ecd4618b1fc
voronoi.m: Fix input validation so it doesn't open blank figure window.
Rik <rik@octave.org>
parents:
18193
diff
changeset
|
183 endif |
17125
b5d6314314fc
Change various plot functions to take advantage of new isaxes() function.
Rik <rik@octave.org>
parents:
15393
diff
changeset
|
184 h = plot (hax, Vvx, Vvy, linespec{:}, x, y, '+'); |
6852 | 185 lim = [xmin, xmax, ymin, ymax]; |
15393
b99c52303d0b
voronoi.m: Fix bug when there are multiple identical input points (bug #37270)
Rik <rik@octave.org>
parents:
14881
diff
changeset
|
186 axis (lim + 0.1 * [[-1, 1] * xdelta, [-1, 1] * ydelta]); |
6823 | 187 if (nargout == 1) |
13746
7ff0bdc3dc4c
Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents:
12931
diff
changeset
|
188 vx = h; |
6823 | 189 endif |
190 else | |
13746
7ff0bdc3dc4c
Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents:
12931
diff
changeset
|
191 vx = Vvx; |
7ff0bdc3dc4c
Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents:
12931
diff
changeset
|
192 vy = Vvy; |
6823 | 193 endif |
194 | |
195 endfunction | |
12824
819a60a05a65
codesprint: add test and demo for voronoi.m
Kai Habel <kai.habel@gmx.de>
parents:
12575
diff
changeset
|
196 |
819a60a05a65
codesprint: add test and demo for voronoi.m
Kai Habel <kai.habel@gmx.de>
parents:
12575
diff
changeset
|
197 |
819a60a05a65
codesprint: add test and demo for voronoi.m
Kai Habel <kai.habel@gmx.de>
parents:
12575
diff
changeset
|
198 %!demo |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
199 %! voronoi (rand (10,1), rand (10,1)); |
13746
7ff0bdc3dc4c
Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents:
12931
diff
changeset
|
200 |
7ff0bdc3dc4c
Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents:
12931
diff
changeset
|
201 %!testif HAVE_QHULL |
7ff0bdc3dc4c
Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents:
12931
diff
changeset
|
202 %! phi = linspace (-pi, 3/4*pi, 8); |
7ff0bdc3dc4c
Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents:
12931
diff
changeset
|
203 %! [x,y] = pol2cart (phi, 1); |
7ff0bdc3dc4c
Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents:
12931
diff
changeset
|
204 %! [vx,vy] = voronoi (x,y); |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14335
diff
changeset
|
205 %! assert (vx(2,:), zeros (1, columns (vx)), eps); |
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14335
diff
changeset
|
206 %! assert (vy(2,:), zeros (1, columns (vy)), eps); |
13746
7ff0bdc3dc4c
Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents:
12931
diff
changeset
|
207 |
23573
1b4f4ec53b4a
use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents:
23572
diff
changeset
|
208 %!testif HAVE_QHULL <*40996> |
18203
5646f999245d
voronoi.m: Add special handling for 2-point input (bug #40996).
Rik <rik@octave.org>
parents:
18201
diff
changeset
|
209 %! ## Special case of just 2 points |
5646f999245d
voronoi.m: Add special handling for 2-point input (bug #40996).
Rik <rik@octave.org>
parents:
18201
diff
changeset
|
210 %! x = [0 1]; y = [1 0]; |
5646f999245d
voronoi.m: Add special handling for 2-point input (bug #40996).
Rik <rik@octave.org>
parents:
18201
diff
changeset
|
211 %! [vx, vy] = voronoi (x,y); |
5646f999245d
voronoi.m: Add special handling for 2-point input (bug #40996).
Rik <rik@octave.org>
parents:
18201
diff
changeset
|
212 %! assert (vx, [-0.7; 1.7], eps); |
5646f999245d
voronoi.m: Add special handling for 2-point input (bug #40996).
Rik <rik@octave.org>
parents:
18201
diff
changeset
|
213 %! assert (vy, [-0.7; 1.7], eps); |
13746
7ff0bdc3dc4c
Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents:
12931
diff
changeset
|
214 |
23573
1b4f4ec53b4a
use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents:
23572
diff
changeset
|
215 %!testif HAVE_QHULL <*38295> |
22697
8acad59ecec0
voronoi.m: Overhaul function to produce correct number of edges (bug #38295).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
216 %! x = [1,2,3]; y = [2,3,1]; |
8acad59ecec0
voronoi.m: Overhaul function to produce correct number of edges (bug #38295).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
217 %! [vx, vy] = voronoi (x,y); |
8acad59ecec0
voronoi.m: Overhaul function to produce correct number of edges (bug #38295).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
218 %! assert (columns (vx), 3); |
8acad59ecec0
voronoi.m: Overhaul function to produce correct number of edges (bug #38295).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
219 |
23573
1b4f4ec53b4a
use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents:
23572
diff
changeset
|
220 %!testif HAVE_QHULL <*37270> |
22697
8acad59ecec0
voronoi.m: Overhaul function to produce correct number of edges (bug #38295).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
221 %! ## Duplicate points can cause an internal error |
8acad59ecec0
voronoi.m: Overhaul function to produce correct number of edges (bug #38295).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
222 %! x = [1,2,3, 3]; y = [2,3,1, 1]; |
8acad59ecec0
voronoi.m: Overhaul function to produce correct number of edges (bug #38295).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
223 %! [vx, vy] = voronoi (x,y); |
8acad59ecec0
voronoi.m: Overhaul function to produce correct number of edges (bug #38295).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
224 |
8acad59ecec0
voronoi.m: Overhaul function to produce correct number of edges (bug #38295).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
225 |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
226 ## Input validation tests |
28896
90fea9cc9caa
test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents:
27978
diff
changeset
|
227 %!error <Invalid call> voronoi () |
18193
31d8e19a745d
voronoi.m: Add input validation test for 2 points (bug #40996)
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
228 %!error voronoi (ones (3,1)) |
20835
14cd86258b3d
use 'invalid' instead of 'bogus' in source files
John W. Eaton <jwe@octave.org>
parents:
20735
diff
changeset
|
229 %!error voronoi (ones (3,1), ones (3,1), "invalid1", "invalid2", "invalid3") |
18193
31d8e19a745d
voronoi.m: Add input validation test for 2 points (bug #40996)
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
230 %!error <HAX argument must be an axes object> voronoi (0, ones (3,1), ones (3,1)) |
31d8e19a745d
voronoi.m: Add input validation test for 2 points (bug #40996)
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
231 %!error <X and Y must be vectors of the same length> voronoi (ones (3,1), ones (4,1)) |
22697
8acad59ecec0
voronoi.m: Overhaul function to produce correct number of edges (bug #38295).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
232 %!error <minimum of 2 points required> voronoi (2.5, 3.5) |