annotate scripts/geometry/inpolygon.m @ 20565:e365a34a1c5c

Fix more installation discrepancies in scripts directory * scripts/module.mk (scripts_@ftpdir): Fix definition. (install-pkg-add): Strip "scripts/" prefix when installing PKG_ADD files. * scripts/set/module.mk (FCN_FILE_DIRS): Add scripts/set/private. (scripts_set_FCN_FILES) Remove scripts/set/private/validsetargs.m from the list. (scripts_set_PRIVATE_FCN_FILES, scripts_set_privatedir, scripts_set_private_DATA): New variables. (FCN_FILES): Add $(scripts_set_PRIVATE_FCN_FILES) to the list. * scripts/startup/module.mk (scripts_startup_DATA) Remove $(STARTUP_FILE_SRC) from the list.
author Mike Miller <mtmiller@octave.org>
date Thu, 16 Jul 2015 01:18:40 -0400
parents aa36fb998a4d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19898
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
1 ## Copyright (C) 2006-2015 Frederick (Rick) A Niles
17243
f4c8c66faf34 maint: Update source file encodings to UTF-8 and fix character errors
Mike Miller <mtmiller@ieee.org>
parents: 14868
diff changeset
2 ## and Søren Hauberg
6847
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
3 ##
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
4 ## This file is part of Octave.
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
5 ##
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
6 ## Octave is free software; you can redistribute it and/or modify it
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
7 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6847
diff changeset
8 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6847
diff changeset
9 ## your option) any later version.
6847
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
10 ##
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
11 ## 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
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
14 ## General Public License for more details.
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
15 ##
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
16 ## 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
17 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6847
diff changeset
18 ## <http://www.gnu.org/licenses/>.
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 ## -*- texinfo -*-
20343
bef9086a6725 inpolygon.m: Overhaul function and fix bug #40970.
Rik <rik@octave.org>
parents: 20038
diff changeset
21 ## @deftypefn {Function File} {@var{in} =} inpolygon (@var{x}, @var{y}, @var{xv}, @var{yv})
bef9086a6725 inpolygon.m: Overhaul function and fix bug #40970.
Rik <rik@octave.org>
parents: 20038
diff changeset
22 ## @deftypefnx {Function File} {[@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
23 ##
20343
bef9086a6725 inpolygon.m: Overhaul function and fix bug #40970.
Rik <rik@octave.org>
parents: 20038
diff changeset
24 ## 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: 20038
diff changeset
25 ## 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: 20038
diff changeset
26 ## of the polygon; Otherwise, return false.
bef9086a6725 inpolygon.m: Overhaul function and fix bug #40970.
Rik <rik@octave.org>
parents: 20038
diff changeset
27 ##
20368
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20343
diff changeset
28 ## 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: 20343
diff changeset
29 ##
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20343
diff changeset
30 ## 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: 20343
diff changeset
31 ## polygon edge, and false otherwise.
20343
bef9086a6725 inpolygon.m: Overhaul function and fix bug #40970.
Rik <rik@octave.org>
parents: 20038
diff changeset
32 ## @seealso{delaunay}
6847
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
33 ## @end deftypefn
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
34
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
35 ## Author: Frederick (Rick) A Niles <niles@rickniles.com>
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
36 ## Created: 14 November 2006
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
37
17243
f4c8c66faf34 maint: Update source file encodings to UTF-8 and fix character errors
Mike Miller <mtmiller@ieee.org>
parents: 14868
diff changeset
38 ## Vectorized by Søren Hauberg <soren@hauberg.org>
6847
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
39
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
40 ## The method for determining if a point is in in a polygon is based on
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
41 ## the algorithm shown on
20343
bef9086a6725 inpolygon.m: Overhaul function and fix bug #40970.
Rik <rik@octave.org>
parents: 20038
diff changeset
42 ## http://local.wasp.uwa.edu.au/~pbourke/geometry/insidepoly/
bef9086a6725 inpolygon.m: Overhaul function and fix bug #40970.
Rik <rik@octave.org>
parents: 20038
diff changeset
43 ## and is credited to Randolph Franklin.
6847
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
44
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
45 function [in, on] = inpolygon (x, y, xv, yv)
6847
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
46
7125
f084ba47812b [project @ 2007-11-08 02:29:23 by jwe]
jwe
parents: 7017
diff changeset
47 if (nargin != 4)
f084ba47812b [project @ 2007-11-08 02:29:23 by jwe]
jwe
parents: 7017
diff changeset
48 print_usage ();
f084ba47812b [project @ 2007-11-08 02:29:23 by jwe]
jwe
parents: 7017
diff changeset
49 endif
f084ba47812b [project @ 2007-11-08 02:29:23 by jwe]
jwe
parents: 7017
diff changeset
50
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
51 if (! (isreal (x) && isreal (y) && ismatrix (y) && ismatrix (y)
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
52 && size_equal (x, y)))
20343
bef9086a6725 inpolygon.m: Overhaul function and fix bug #40970.
Rik <rik@octave.org>
parents: 20038
diff changeset
53 error ("inpolygon: X and Y must be real matrices of the same size");
7125
f084ba47812b [project @ 2007-11-08 02:29:23 by jwe]
jwe
parents: 7017
diff changeset
54 elseif (! (isreal (xv) && isreal (yv) && isvector (xv) && isvector (yv)
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
55 && size_equal (xv, yv)))
20343
bef9086a6725 inpolygon.m: Overhaul function and fix bug #40970.
Rik <rik@octave.org>
parents: 20038
diff changeset
56 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
57 endif
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
58
7125
f084ba47812b [project @ 2007-11-08 02:29:23 by jwe]
jwe
parents: 7017
diff changeset
59 npol = length (xv);
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
60
20343
bef9086a6725 inpolygon.m: Overhaul function and fix bug #40970.
Rik <rik@octave.org>
parents: 20038
diff changeset
61 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
62
6847
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
63 j = npol;
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
64 for i = 1 : npol
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
65 delta_xv = xv(j) - xv(i);
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
66 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
67 ## 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
68 distance = delta_xv .* (y - yv(i)) - (x - xv(i)) .* delta_yv;
20343
bef9086a6725 inpolygon.m: Overhaul function and fix bug #40970.
Rik <rik@octave.org>
parents: 20038
diff changeset
69
bef9086a6725 inpolygon.m: Overhaul function and fix bug #40970.
Rik <rik@octave.org>
parents: 20038
diff changeset
70 ## 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
71 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
72 & 0 < distance.*delta_yv);
20038
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19898
diff changeset
73 in(idx1) = ! in(idx1);
6847
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
74
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 ## Check if (x,y) are actually on the boundary of the polygon.
20343
bef9086a6725 inpolygon.m: Overhaul function and fix bug #40970.
Rik <rik@octave.org>
parents: 20038
diff changeset
76 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: 20038
diff changeset
77 & ((xv(i) <= x & x <= xv(j)) | (xv(j) <= x & x <= xv(i)))
bef9086a6725 inpolygon.m: Overhaul function and fix bug #40970.
Rik <rik@octave.org>
parents: 20038
diff changeset
78 & (0 == distance | !delta_xv));
bef9086a6725 inpolygon.m: Overhaul function and fix bug #40970.
Rik <rik@octave.org>
parents: 20038
diff changeset
79 on(idx2) = true;
bef9086a6725 inpolygon.m: Overhaul function and fix bug #40970.
Rik <rik@octave.org>
parents: 20038
diff changeset
80
6847
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
81 j = i;
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
82 endfor
7125
f084ba47812b [project @ 2007-11-08 02:29:23 by jwe]
jwe
parents: 7017
diff changeset
83
20391
aa36fb998a4d maint: Remove unnecessary whitespace at end of lines.
Rik <rik@octave.org>
parents: 20368
diff changeset
84 ## Matlab definition include both in polygon and on polygon points.
20343
bef9086a6725 inpolygon.m: Overhaul function and fix bug #40970.
Rik <rik@octave.org>
parents: 20038
diff changeset
85 in |= on;
bef9086a6725 inpolygon.m: Overhaul function and fix bug #40970.
Rik <rik@octave.org>
parents: 20038
diff changeset
86
6847
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
87 endfunction
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
88
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
89
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
90 %!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
91 %! 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
92 %! 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
93 %! 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
94 %! 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
95 %! 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
96 %! 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
97 %! 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
98 %! 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
99 %! [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
100 %! [in,on] = inpolygon (x, y, 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
101 %! inside = in & !on;
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
102 %!
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14222
diff changeset
103 %! clf;
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14222
diff changeset
104 %! 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
105 %! 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
106 %! plot (x(inside), y(inside), "@g")
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14222
diff changeset
107 %! plot (x(!in), y(!in), "@m");
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 (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
109 %! 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
110 %! 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
111 %! disp ("and blue are on boundary.");
6847
956148c0d388 [project @ 2007-08-30 07:39:32 by dbateman]
dbateman
parents:
diff changeset
112
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14222
diff changeset
113 %!demo
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14222
diff changeset
114 %! 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
115 %! 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
116 %! 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
117 %! 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
118 %! 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
119 %! 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
120 %! 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
121 %! 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
122 %! 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
123 %! ya = [0:0.1:1.4];
20343
bef9086a6725 inpolygon.m: Overhaul function and fix bug #40970.
Rik <rik@octave.org>
parents: 20038
diff changeset
124 %! [x, y] = meshgrid (xa, ya);
bef9086a6725 inpolygon.m: Overhaul function and fix bug #40970.
Rik <rik@octave.org>
parents: 20038
diff changeset
125 %! [in, on] = inpolygon (x, y, xv, yv);
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14222
diff changeset
126 %! inside = in & !on;
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14222
diff changeset
127 %!
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14222
diff changeset
128 %! clf;
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14222
diff changeset
129 %! 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
130 %! 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
131 %! plot (x(inside), y(inside), "@g");
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14222
diff changeset
132 %! plot (x(!in), y(!in), "@m");
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 (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
134 %! 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
135 %! 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
136 %! disp ("and blue are on boundary.");
13057
85c77dd2e85b codesprint: tests for inpolygon
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
137
85c77dd2e85b codesprint: tests for inpolygon
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
138 %!test
20343
bef9086a6725 inpolygon.m: Overhaul function and fix bug #40970.
Rik <rik@octave.org>
parents: 20038
diff changeset
139 %! [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: 20038
diff changeset
140 %! assert (in, [true, true, false]);
bef9086a6725 inpolygon.m: Overhaul function and fix bug #40970.
Rik <rik@octave.org>
parents: 20038
diff changeset
141 %! 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
142
20038
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19898
diff changeset
143 ## 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
144 %!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
145 %!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
146 %!error inpolygon (1, 2, 3)
20343
bef9086a6725 inpolygon.m: Overhaul function and fix bug #40970.
Rik <rik@octave.org>
parents: 20038
diff changeset
147 %!error inpolygon (1, 2, 3, 4, 5)
bef9086a6725 inpolygon.m: Overhaul function and fix bug #40970.
Rik <rik@octave.org>
parents: 20038
diff changeset
148 %!error <X and Y must be real matrices> inpolygon (1i, 1, [3, 4], [5, 6])
bef9086a6725 inpolygon.m: Overhaul function and fix bug #40970.
Rik <rik@octave.org>
parents: 20038
diff changeset
149 %!error <X and Y must be real matrices> inpolygon (1, {1}, [3, 4], [5, 6])
bef9086a6725 inpolygon.m: Overhaul function and fix bug #40970.
Rik <rik@octave.org>
parents: 20038
diff changeset
150 %!error <X and Y must be .* the same size> inpolygon (1, [1,2], [3, 4], [5, 6])
bef9086a6725 inpolygon.m: Overhaul function and fix bug #40970.
Rik <rik@octave.org>
parents: 20038
diff changeset
151 %!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: 20038
diff changeset
152 %!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: 20038
diff changeset
153 %!error <XV and YV must .* the same size> inpolygon ([1,2], [3, 4], [5, 6], 1)
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14222
diff changeset
154