annotate scripts/geometry/inpolygon.m @ 27918:b442ec6dda5c

use centralized file for copyright info for individual contributors * COPYRIGHT.md: New file. * In most other files, use "Copyright (C) YYYY-YYYY The Octave Project Developers" instead of tracking individual names in separate source files. The motivation is to reduce the effort required to update the notices each year. Until now, the Octave source files contained copyright notices that list individual contributors. I adopted these file-scope copyright notices because that is what everyone was doing 30 years ago in the days before distributed version control systems. But now, with many contributors and modern version control systems, having these file-scope copyright notices causes trouble when we update copyright years or refactor code. Over time, the file-scope copyright notices may become outdated as new contributions are made or code is moved from one file to another. Sometimes people contribute significant patches but do not add a line claiming copyright. Other times, people add a copyright notice for their contribution but then a later refactoring moves part or all of their contribution to another file and the notice is not moved with the code. As a practical matter, moving such notices is difficult -- determining what parts are due to a particular contributor requires a time-consuming search through the project history. Even managing the yearly update of copyright years is problematic. We have some contributors who are no longer living. Should we update the copyright dates for their contributions when we release new versions? Probably not, but we do still want to claim copyright for the project as a whole. To minimize the difficulty of maintaining the copyright notices, I would like to change Octave's sources to use what is described here: https://softwarefreedom.org/resources/2012/ManagingCopyrightInformation.html in the section "Maintaining centralized copyright notices": The centralized notice approach consolidates all copyright notices in a single location, usually a top-level file. This file should contain all of the copyright notices provided project contributors, unless the contribution was clearly insignificant. It may also credit -- without a copyright notice -- anyone who helped with the project but did not contribute code or other copyrighted material. This approach captures less information about contributions within individual files, recognizing that the DVCS is better equipped to record those details. As we mentioned before, it does have one disadvantage as compared to the file-scope approach: if a single file is separated from the distribution, the recipient won't see the contributors' copyright notices. But this can be easily remedied by including a single copyright notice in each file's header, pointing to the top-level file: Copyright YYYY-YYYY The Octave Project Developers See the COPYRIGHT file at the top-level directory of this distribution or at https://octave.org/COPYRIGHT.html. followed by the usual GPL copyright statement. For more background, see the discussion here: https://lists.gnu.org/archive/html/octave-maintainers/2020-01/msg00009.html Most files in the following directories have been skipped intentinally in this changeset: doc libgui/qterminal liboctave/external m4
author John W. Eaton <jwe@octave.org>
date Mon, 06 Jan 2020 15:38:17 -0500
parents 00f796120a6d
children 1891570abac8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27918
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1 ## Copyright (C) 2006-2019 The Octave Project Developers
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
2 ##
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
3 ## See the file COPYRIGHT.md in the top-level directory of this distribution
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
4 ## or <https://octave.org/COPYRIGHT.html/>.
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
5 ##
17243
f4c8c66faf34 maint: Update source file encodings to UTF-8 and fix character errors
Mike Miller <mtmiller@ieee.org>
parents: 14868
diff changeset
6 ## and Søren Hauberg
6847
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
7 ##
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
8 ## This file is part of Octave.
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
9 ##
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
10 ## Octave is free software: you can redistribute it and/or modify it
6847
956148c0d388 [project @ 2007-08-30 07:39:32 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: 23220
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: 22173
diff changeset
13 ## (at your option) any later version.
6847
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
14 ##
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
15 ## Octave is distributed in the hope that it will be useful, but
956148c0d388 [project @ 2007-08-30 07:39:32 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: 22173
diff changeset
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22173
diff changeset
18 ## GNU General Public License for more details.
6847
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
19 ##
956148c0d388 [project @ 2007-08-30 07:39:32 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: 6847
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: 23220
diff changeset
22 ## <https://www.gnu.org/licenses/>.
6847
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
23
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
24 ## -*- texinfo -*-
20852
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20181
diff changeset
25 ## @deftypefn {} {@var{in} =} inpolygon (@var{x}, @var{y}, @var{xv}, @var{yv})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20181
diff changeset
26 ## @deftypefnx {} {[@var{in}, @var{on}] =} inpolygon (@var{x}, @var{y}, @var{xv}, @var{yv})
6847
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
27 ##
20133
bef9086a6725 inpolygon.m: Overhaul function and fix bug #40970.
Rik <rik@octave.org>
parents: 19833
diff changeset
28 ## For a polygon defined by vertex points @code{(@var{xv}, @var{yv})}, return
bef9086a6725 inpolygon.m: Overhaul function and fix bug #40970.
Rik <rik@octave.org>
parents: 19833
diff changeset
29 ## true if the points @code{(@var{x}, @var{y})} are inside (or on the boundary)
bef9086a6725 inpolygon.m: Overhaul function and fix bug #40970.
Rik <rik@octave.org>
parents: 19833
diff changeset
30 ## of the polygon; Otherwise, return false.
bef9086a6725 inpolygon.m: Overhaul function and fix bug #40970.
Rik <rik@octave.org>
parents: 19833
diff changeset
31 ##
20158
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20133
diff changeset
32 ## The input variables @var{x} and @var{y}, must have the same dimension.
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20133
diff changeset
33 ##
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20133
diff changeset
34 ## The optional output @var{on} returns true if the points are exactly on the
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20133
diff changeset
35 ## polygon edge, and false otherwise.
20133
bef9086a6725 inpolygon.m: Overhaul function and fix bug #40970.
Rik <rik@octave.org>
parents: 19833
diff changeset
36 ## @seealso{delaunay}
6847
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
37 ## @end deftypefn
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
38
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
39 ## Author: Frederick (Rick) A Niles <niles@rickniles.com>
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
40 ## Created: 14 November 2006
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
41
17243
f4c8c66faf34 maint: Update source file encodings to UTF-8 and fix character errors
Mike Miller <mtmiller@ieee.org>
parents: 14868
diff changeset
42 ## Vectorized by Søren Hauberg <soren@hauberg.org>
6847
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
43
22173
8de49f15e182 doc: Fix "doubled words" typos (\b(\w+)\s+\1\b)
Andreas Weber <andy.weber.aw@gmail.com>
parents: 21580
diff changeset
44 ## The method for determining if a point is in a polygon is based on
6847
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
45 ## the algorithm shown on
20133
bef9086a6725 inpolygon.m: Overhaul function and fix bug #40970.
Rik <rik@octave.org>
parents: 19833
diff changeset
46 ## http://local.wasp.uwa.edu.au/~pbourke/geometry/insidepoly/
bef9086a6725 inpolygon.m: Overhaul function and fix bug #40970.
Rik <rik@octave.org>
parents: 19833
diff changeset
47 ## and is credited to Randolph Franklin.
6847
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
48
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
49 function [in, on] = inpolygon (x, y, xv, yv)
6847
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
50
7125
f084ba47812b [project @ 2007-11-08 02:29:23 by jwe]
jwe
parents: 7017
diff changeset
51 if (nargin != 4)
f084ba47812b [project @ 2007-11-08 02:29:23 by jwe]
jwe
parents: 7017
diff changeset
52 print_usage ();
f084ba47812b [project @ 2007-11-08 02:29:23 by jwe]
jwe
parents: 7017
diff changeset
53 endif
f084ba47812b [project @ 2007-11-08 02:29:23 by jwe]
jwe
parents: 7017
diff changeset
54
21222
732ec49d1ec5 Fix regressions caused by ismatrix definition change (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents: 20181
diff changeset
55 if (! (isreal (x) && isreal (y) && isnumeric (x) && isnumeric (y)
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
56 && size_equal (x, y)))
21222
732ec49d1ec5 Fix regressions caused by ismatrix definition change (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents: 20181
diff changeset
57 error ("inpolygon: X and Y must be real arrays of the same size");
7125
f084ba47812b [project @ 2007-11-08 02:29:23 by jwe]
jwe
parents: 7017
diff changeset
58 elseif (! (isreal (xv) && isreal (yv) && isvector (xv) && isvector (yv)
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
59 && size_equal (xv, yv)))
20133
bef9086a6725 inpolygon.m: Overhaul function and fix bug #40970.
Rik <rik@octave.org>
parents: 19833
diff changeset
60 error ("inpolygon: XV and YV must be real vectors of the same size");
6847
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
61 endif
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
62
7125
f084ba47812b [project @ 2007-11-08 02:29:23 by jwe]
jwe
parents: 7017
diff changeset
63 npol = length (xv);
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
64
20133
bef9086a6725 inpolygon.m: Overhaul function and fix bug #40970.
Rik <rik@octave.org>
parents: 19833
diff changeset
65 in = on = false (size (x));
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
66
6847
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
67 j = npol;
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
68 for i = 1 : npol
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
69 delta_xv = xv(j) - xv(i);
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
70 delta_yv = yv(j) - yv(i);
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
71 ## distance = [distance from (x,y) to edge] * length(edge)
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
72 distance = delta_xv .* (y - yv(i)) - (x - xv(i)) .* delta_yv;
20133
bef9086a6725 inpolygon.m: Overhaul function and fix bug #40970.
Rik <rik@octave.org>
parents: 19833
diff changeset
73
bef9086a6725 inpolygon.m: Overhaul function and fix bug #40970.
Rik <rik@octave.org>
parents: 19833
diff changeset
74 ## is y between the y-values of edge i,j AND (x,y) on the left of the edge?
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
75 idx1 = (((yv(i) <= y & y < yv(j)) | (yv(j) <= y & y < yv(i)))
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
76 & 0 < distance.*delta_yv);
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
77 in(idx1) = ! in(idx1);
6847
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
78
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
79 ## Check if (x,y) are actually on the boundary of the polygon.
20133
bef9086a6725 inpolygon.m: Overhaul function and fix bug #40970.
Rik <rik@octave.org>
parents: 19833
diff changeset
80 idx2 = (((yv(i) <= y & y <= yv(j)) | (yv(j) <= y & y <= yv(i)))
bef9086a6725 inpolygon.m: Overhaul function and fix bug #40970.
Rik <rik@octave.org>
parents: 19833
diff changeset
81 & ((xv(i) <= x & x <= xv(j)) | (xv(j) <= x & x <= xv(i)))
20955
77f5591878bf maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents: 20852
diff changeset
82 & (0 == distance | ! delta_xv));
20133
bef9086a6725 inpolygon.m: Overhaul function and fix bug #40970.
Rik <rik@octave.org>
parents: 19833
diff changeset
83 on(idx2) = true;
bef9086a6725 inpolygon.m: Overhaul function and fix bug #40970.
Rik <rik@octave.org>
parents: 19833
diff changeset
84
6847
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
85 j = i;
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
86 endfor
7125
f084ba47812b [project @ 2007-11-08 02:29:23 by jwe]
jwe
parents: 7017
diff changeset
87
20181
aa36fb998a4d maint: Remove unnecessary whitespace at end of lines.
Rik <rik@octave.org>
parents: 20158
diff changeset
88 ## Matlab definition include both in polygon and on polygon points.
20133
bef9086a6725 inpolygon.m: Overhaul function and fix bug #40970.
Rik <rik@octave.org>
parents: 19833
diff changeset
89 in |= on;
bef9086a6725 inpolygon.m: Overhaul function and fix bug #40970.
Rik <rik@octave.org>
parents: 19833
diff changeset
90
6847
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
91 endfunction
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
92
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
93
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
94 %!demo
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14222
diff changeset
95 %! xv = [ 0.05840, 0.48375, 0.69356, 1.47478, 1.32158, ...
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14222
diff changeset
96 %! 1.94545, 2.16477, 1.87639, 1.18218, 0.27615, ...
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14222
diff changeset
97 %! 0.05840 ];
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14222
diff changeset
98 %! yv = [ 0.60628, 0.04728, 0.50000, 0.50000, 0.02015, ...
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14222
diff changeset
99 %! 0.18161, 0.78850, 1.13589, 1.33781, 1.04650, ...
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14222
diff changeset
100 %! 0.60628 ];
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14222
diff changeset
101 %! xa = [0:0.1:2.3];
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14222
diff changeset
102 %! ya = [0:0.1:1.4];
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14222
diff changeset
103 %! [x,y] = meshgrid (xa, ya);
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14222
diff changeset
104 %! [in,on] = inpolygon (x, y, xv, yv);
20955
77f5591878bf maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents: 20852
diff changeset
105 %! inside = in & ! on;
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
106 %!
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14222
diff changeset
107 %! clf;
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14222
diff changeset
108 %! plot (xv, yv);
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14222
diff changeset
109 %! hold on;
21580
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21223
diff changeset
110 %! plot (x(inside), y(inside), "@g");
20955
77f5591878bf maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents: 20852
diff changeset
111 %! plot (x(! in), y(! in), "@m");
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14222
diff changeset
112 %! plot (x(on), y(on), "@b");
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14222
diff changeset
113 %! hold off;
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14222
diff changeset
114 %! disp ("Green points are inside polygon, magenta are outside,");
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14222
diff changeset
115 %! disp ("and blue are on boundary.");
6847
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
116
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14222
diff changeset
117 %!demo
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14222
diff changeset
118 %! xv = [ 0.05840, 0.48375, 0.69356, 1.47478, 1.32158, ...
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14222
diff changeset
119 %! 1.94545, 2.16477, 1.87639, 1.18218, 0.27615, ...
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14222
diff changeset
120 %! 0.05840, 0.73295, 1.28913, 1.74221, 1.16023, ...
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14222
diff changeset
121 %! 0.73295, 0.05840 ];
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14222
diff changeset
122 %! yv = [ 0.60628, 0.04728, 0.50000, 0.50000, 0.02015, ...
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14222
diff changeset
123 %! 0.18161, 0.78850, 1.13589, 1.33781, 1.04650, ...
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14222
diff changeset
124 %! 0.60628, 0.82096, 0.67155, 0.96114, 1.14833, ...
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14222
diff changeset
125 %! 0.82096, 0.60628];
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14222
diff changeset
126 %! xa = [0:0.1:2.3];
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14222
diff changeset
127 %! ya = [0:0.1:1.4];
20133
bef9086a6725 inpolygon.m: Overhaul function and fix bug #40970.
Rik <rik@octave.org>
parents: 19833
diff changeset
128 %! [x, y] = meshgrid (xa, ya);
bef9086a6725 inpolygon.m: Overhaul function and fix bug #40970.
Rik <rik@octave.org>
parents: 19833
diff changeset
129 %! [in, on] = inpolygon (x, y, xv, yv);
20955
77f5591878bf maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents: 20852
diff changeset
130 %! inside = in & ! on;
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14222
diff changeset
131 %!
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14222
diff changeset
132 %! clf;
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14222
diff changeset
133 %! plot (xv, yv);
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14222
diff changeset
134 %! hold on;
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14222
diff changeset
135 %! plot (x(inside), y(inside), "@g");
20955
77f5591878bf maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents: 20852
diff changeset
136 %! plot (x(! in), y(! in), "@m");
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14222
diff changeset
137 %! plot (x(on), y(on), "@b");
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14222
diff changeset
138 %! hold off;
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14222
diff changeset
139 %! disp ("Green points are inside polygon, magenta are outside,");
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14222
diff changeset
140 %! disp ("and blue are on boundary.");
13057
85c77dd2e85b codesprint: tests for inpolygon
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
141
85c77dd2e85b codesprint: tests for inpolygon
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
142 %!test
20133
bef9086a6725 inpolygon.m: Overhaul function and fix bug #40970.
Rik <rik@octave.org>
parents: 19833
diff changeset
143 %! [in, on] = inpolygon ([1, 0, 2], [1, 0, 0], [-1, -1, 1, 1], [-1, 1, 1, -1]);
bef9086a6725 inpolygon.m: Overhaul function and fix bug #40970.
Rik <rik@octave.org>
parents: 19833
diff changeset
144 %! assert (in, [true, true, false]);
bef9086a6725 inpolygon.m: Overhaul function and fix bug #40970.
Rik <rik@octave.org>
parents: 19833
diff changeset
145 %! assert (on, [true, false, false]);
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14222
diff changeset
146
21222
732ec49d1ec5 Fix regressions caused by ismatrix definition change (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents: 20181
diff changeset
147 ## 3D array input
732ec49d1ec5 Fix regressions caused by ismatrix definition change (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents: 20181
diff changeset
148 %!test
732ec49d1ec5 Fix regressions caused by ismatrix definition change (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents: 20181
diff changeset
149 %! x = zeros (2, 2, 2);
732ec49d1ec5 Fix regressions caused by ismatrix definition change (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents: 20181
diff changeset
150 %! x(1, 1, 1) = 1;
732ec49d1ec5 Fix regressions caused by ismatrix definition change (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents: 20181
diff changeset
151 %! x(2, 2, 2) = 2;
732ec49d1ec5 Fix regressions caused by ismatrix definition change (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents: 20181
diff changeset
152 %! y = zeros (2, 2, 2);
732ec49d1ec5 Fix regressions caused by ismatrix definition change (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents: 20181
diff changeset
153 %! y(1, 1, 1) = 1;
732ec49d1ec5 Fix regressions caused by ismatrix definition change (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents: 20181
diff changeset
154 %! y(2, 2, 2) = -1;
732ec49d1ec5 Fix regressions caused by ismatrix definition change (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents: 20181
diff changeset
155 %! [in, on] = inpolygon (x, y, [-1, -1, 1, 1], [-1, 1, 1, -1]);
732ec49d1ec5 Fix regressions caused by ismatrix definition change (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents: 20181
diff changeset
156 %! IN = true (2, 2, 2);
732ec49d1ec5 Fix regressions caused by ismatrix definition change (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents: 20181
diff changeset
157 %! IN(2, 2, 2) = false;
732ec49d1ec5 Fix regressions caused by ismatrix definition change (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents: 20181
diff changeset
158 %! ON = false (2, 2, 2);
732ec49d1ec5 Fix regressions caused by ismatrix definition change (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents: 20181
diff changeset
159 %! ON(1, 1, 1) = true;
732ec49d1ec5 Fix regressions caused by ismatrix definition change (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents: 20181
diff changeset
160 %! assert (in, IN);
732ec49d1ec5 Fix regressions caused by ismatrix definition change (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents: 20181
diff changeset
161 %! assert (on, ON);
732ec49d1ec5 Fix regressions caused by ismatrix definition change (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents: 20181
diff changeset
162
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
163 ## Test input validation
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14222
diff changeset
164 %!error inpolygon ()
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14222
diff changeset
165 %!error inpolygon (1, 2)
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14222
diff changeset
166 %!error inpolygon (1, 2, 3)
20133
bef9086a6725 inpolygon.m: Overhaul function and fix bug #40970.
Rik <rik@octave.org>
parents: 19833
diff changeset
167 %!error inpolygon (1, 2, 3, 4, 5)
21222
732ec49d1ec5 Fix regressions caused by ismatrix definition change (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents: 20181
diff changeset
168 %!error <X and Y must be real> inpolygon (1i, 1, [3, 4], [5, 6])
732ec49d1ec5 Fix regressions caused by ismatrix definition change (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents: 20181
diff changeset
169 %!error <X and Y must be real> inpolygon (1, {1}, [3, 4], [5, 6])
20133
bef9086a6725 inpolygon.m: Overhaul function and fix bug #40970.
Rik <rik@octave.org>
parents: 19833
diff changeset
170 %!error <X and Y must be .* the same size> inpolygon (1, [1,2], [3, 4], [5, 6])
21222
732ec49d1ec5 Fix regressions caused by ismatrix definition change (partial fix bug #47036).
Colin Macdonald <cbm@m.fsf.org>
parents: 20181
diff changeset
171 %!error <X and Y must be .* the same size> inpolygon (1, ones (1,1,2), [3, 4], [5, 6])
20133
bef9086a6725 inpolygon.m: Overhaul function and fix bug #40970.
Rik <rik@octave.org>
parents: 19833
diff changeset
172 %!error <XV and YV must be real vectors> inpolygon (1, 1, [3i, 4], [5, 6])
bef9086a6725 inpolygon.m: Overhaul function and fix bug #40970.
Rik <rik@octave.org>
parents: 19833
diff changeset
173 %!error <XV and YV must be real vectors> inpolygon (1, 1, [3, 4], {5, 6})
bef9086a6725 inpolygon.m: Overhaul function and fix bug #40970.
Rik <rik@octave.org>
parents: 19833
diff changeset
174 %!error <XV and YV must .* the same size> inpolygon ([1,2], [3, 4], [5, 6], 1)