Mercurial > octave
comparison scripts/geometry/inpolygon.m @ 21222:732ec49d1ec5 stable
Fix regressions caused by ismatrix definition change (partial fix bug #47036).
* gray2ind.m: Simplify input checks. Add BIST test.
* inpolygon.m: Replace ismatrix with isnumeric in input validation.
Add BIST tests. Update copyright date.
* __stem__.m: Validate single input is a not an N-D array.
* stem.m: Add BIST test for an N-D array input.
author | Colin Macdonald <cbm@m.fsf.org> |
---|---|
date | Mon, 08 Feb 2016 20:35:29 -0800 |
parents | aa36fb998a4d |
children | f6aab24ed82e |
comparison
equal
deleted
inserted
replaced
21204:5cff92d32ee7 | 21222:732ec49d1ec5 |
---|---|
1 ## Copyright (C) 2006-2015 Frederick (Rick) A Niles | 1 ## Copyright (C) 2006-2016 Frederick (Rick) A Niles |
2 ## and Søren Hauberg | 2 ## and Søren Hauberg |
3 ## | 3 ## |
4 ## This file is part of Octave. | 4 ## This file is part of Octave. |
5 ## | 5 ## |
6 ## Octave is free software; you can redistribute it and/or modify it | 6 ## Octave is free software; you can redistribute it and/or modify it |
46 | 46 |
47 if (nargin != 4) | 47 if (nargin != 4) |
48 print_usage (); | 48 print_usage (); |
49 endif | 49 endif |
50 | 50 |
51 if (! (isreal (x) && isreal (y) && ismatrix (y) && ismatrix (y) | 51 if (! (isreal (x) && isreal (y) && isnumeric (x) && isnumeric (y) |
52 && size_equal (x, y))) | 52 && size_equal (x, y))) |
53 error ("inpolygon: X and Y must be real matrices of the same size"); | 53 error ("inpolygon: X and Y must be real arrays of the same size"); |
54 elseif (! (isreal (xv) && isreal (yv) && isvector (xv) && isvector (yv) | 54 elseif (! (isreal (xv) && isreal (yv) && isvector (xv) && isvector (yv) |
55 && size_equal (xv, yv))) | 55 && size_equal (xv, yv))) |
56 error ("inpolygon: XV and YV must be real vectors of the same size"); | 56 error ("inpolygon: XV and YV must be real vectors of the same size"); |
57 endif | 57 endif |
58 | 58 |
138 %!test | 138 %!test |
139 %! [in, on] = inpolygon ([1, 0, 2], [1, 0, 0], [-1, -1, 1, 1], [-1, 1, 1, -1]); | 139 %! [in, on] = inpolygon ([1, 0, 2], [1, 0, 0], [-1, -1, 1, 1], [-1, 1, 1, -1]); |
140 %! assert (in, [true, true, false]); | 140 %! assert (in, [true, true, false]); |
141 %! assert (on, [true, false, false]); | 141 %! assert (on, [true, false, false]); |
142 | 142 |
143 ## 3D array input | |
144 %!test | |
145 %! x = zeros (2, 2, 2); | |
146 %! x(1, 1, 1) = 1; | |
147 %! x(2, 2, 2) = 2; | |
148 %! y = zeros (2, 2, 2); | |
149 %! y(1, 1, 1) = 1; | |
150 %! y(2, 2, 2) = -1; | |
151 %! [in, on] = inpolygon (x, y, [-1, -1, 1, 1], [-1, 1, 1, -1]); | |
152 %! IN = true (2, 2, 2); | |
153 %! IN(2, 2, 2) = false; | |
154 %! ON = false (2, 2, 2); | |
155 %! ON(1, 1, 1) = true; | |
156 %! assert (in, IN); | |
157 %! assert (on, ON); | |
158 | |
143 ## Test input validation | 159 ## Test input validation |
144 %!error inpolygon () | 160 %!error inpolygon () |
145 %!error inpolygon (1, 2) | 161 %!error inpolygon (1, 2) |
146 %!error inpolygon (1, 2, 3) | 162 %!error inpolygon (1, 2, 3) |
147 %!error inpolygon (1, 2, 3, 4, 5) | 163 %!error inpolygon (1, 2, 3, 4, 5) |
148 %!error <X and Y must be real matrices> inpolygon (1i, 1, [3, 4], [5, 6]) | 164 %!error <X and Y must be real> inpolygon (1i, 1, [3, 4], [5, 6]) |
149 %!error <X and Y must be real matrices> inpolygon (1, {1}, [3, 4], [5, 6]) | 165 %!error <X and Y must be real> inpolygon (1, {1}, [3, 4], [5, 6]) |
150 %!error <X and Y must be .* the same size> inpolygon (1, [1,2], [3, 4], [5, 6]) | 166 %!error <X and Y must be .* the same size> inpolygon (1, [1,2], [3, 4], [5, 6]) |
167 %!error <X and Y must be .* the same size> inpolygon (1, ones (1,1,2), [3, 4], [5, 6]) | |
151 %!error <XV and YV must be real vectors> inpolygon (1, 1, [3i, 4], [5, 6]) | 168 %!error <XV and YV must be real vectors> inpolygon (1, 1, [3i, 4], [5, 6]) |
152 %!error <XV and YV must be real vectors> inpolygon (1, 1, [3, 4], {5, 6}) | 169 %!error <XV and YV must be real vectors> inpolygon (1, 1, [3, 4], {5, 6}) |
153 %!error <XV and YV must .* the same size> inpolygon ([1,2], [3, 4], [5, 6], 1) | 170 %!error <XV and YV must .* the same size> inpolygon ([1,2], [3, 4], [5, 6], 1) |
154 | 171 |