Mercurial > octave-nkf
comparison scripts/geometry/voronoi.m @ 18192:31d8e19a745d
voronoi.m: Add input validation test for 2 points (bug #40996)
* voronoi.m: Add input validation test for 2 points (bug #40996).
Add %!tests for input validation. Correct misnamed variable harg to hax.
author | Rik <rik@octave.org> |
---|---|
date | Thu, 02 Jan 2014 10:55:09 -0800 |
parents | d63878346099 |
children | 0ecd4618b1fc |
comparison
equal
deleted
inserted
replaced
18188:f24d5bd050d9 | 18192:31d8e19a745d |
---|---|
74 endif | 74 endif |
75 | 75 |
76 narg = 1; | 76 narg = 1; |
77 if (isscalar (varargin{1}) && ishandle (varargin{1})) | 77 if (isscalar (varargin{1}) && ishandle (varargin{1})) |
78 hax = varargin{1}; | 78 hax = varargin{1}; |
79 if (! isaxes (harg)) | 79 if (! isaxes (hax)) |
80 error ("imagesc: HAX argument must be an axes object"); | 80 error ("voronoi: HAX argument must be an axes object"); |
81 endif | 81 endif |
82 narg++; | 82 narg++; |
83 elseif (nargout < 2) | 83 elseif (nargout < 2) |
84 hax = gca (); | 84 hax = gca (); |
85 endif | 85 endif |
106 linespec = varargin(narg); | 106 linespec = varargin(narg); |
107 endif | 107 endif |
108 | 108 |
109 if (length (x) != length (y)) | 109 if (length (x) != length (y)) |
110 error ("voronoi: X and Y must be vectors of the same length"); | 110 error ("voronoi: X and Y must be vectors of the same length"); |
111 elseif (length (x) < 3) | |
112 ## See bug #40996. | |
113 ## For 2 points it would be nicer to just calculate the bisection line. | |
114 error ("voronoi: minimum of 3 points needed"); | |
111 endif | 115 endif |
112 | 116 |
113 ## Add box to approximate rays to infinity. For Voronoi diagrams the | 117 ## Add box to approximate rays to infinity. For Voronoi diagrams the |
114 ## box can (and should) be close to the points themselves. To make the | 118 ## box can (and should) be close to the points themselves. To make the |
115 ## job of finding the exterior edges it should be at least two times the | 119 ## job of finding the exterior edges it should be at least two times the |
177 %! [x,y] = pol2cart (phi, 1); | 181 %! [x,y] = pol2cart (phi, 1); |
178 %! [vx,vy] = voronoi (x,y); | 182 %! [vx,vy] = voronoi (x,y); |
179 %! assert (vx(2,:), zeros (1, columns (vx)), eps); | 183 %! assert (vx(2,:), zeros (1, columns (vx)), eps); |
180 %! assert (vy(2,:), zeros (1, columns (vy)), eps); | 184 %! assert (vy(2,:), zeros (1, columns (vy)), eps); |
181 | 185 |
182 %% FIXME: Need input validation tests | 186 %% Input validation tests |
187 %!error voronoi () | |
188 %!error voronoi (ones (3,1)) | |
189 %!error voronoi (ones (3,1), ones (3,1), "bogus1", "bogus2", "bogus3") | |
190 %!error <HAX argument must be an axes object> voronoi (0, ones (3,1), ones (3,1)) | |
191 %!error <X and Y must be vectors of the same length> voronoi (ones (3,1), ones (4,1)) | |
192 %!error <minimum of 3 points needed> voronoi (2.5, 3.5) | |
193 %!error <minimum of 3 points needed> voronoi ([2.5, 3.5], [2.5, 3.5]) | |
183 | 194 |