comparison scripts/geometry/voronoi.m @ 11587:c792872f8942

all script files: untabify and strip trailing whitespace
author John W. Eaton <jwe@octave.org>
date Thu, 20 Jan 2011 17:35:29 -0500
parents fd0a3ac60b0e
children d0b799dafede
comparison
equal deleted inserted replaced
11586:12df7854fa7c 11587:c792872f8942
69 narg++; 69 narg++;
70 if (! strcmp (get (handl, "type"), "axes")) 70 if (! strcmp (get (handl, "type"), "axes"))
71 error ("voronoi: expecting first argument to be an axes object"); 71 error ("voronoi: expecting first argument to be an axes object");
72 endif 72 endif
73 else 73 else
74 if (nargout < 2) 74 if (nargout < 2)
75 handl = gca (); 75 handl = gca ();
76 endif 76 endif
77 endif 77 endif
78 78
79 if (nargin < 1 + narg || nargin > 3 + narg) 79 if (nargin < 1 + narg || nargin > 3 + narg)
80 print_usage (); 80 print_usage ();
81 endif 81 endif
82 82
83 x = varargin{narg++}; 83 x = varargin{narg++};
84 y = varargin{narg++}; 84 y = varargin{narg++};
85 85
86 opts = {}; 86 opts = {};
87 if (narg <= nargin) 87 if (narg <= nargin)
88 if (iscell (varargin{narg})) 88 if (iscell (varargin{narg}))
89 opts = varargin(narg++); 89 opts = varargin(narg++);
90 elseif (ismatrix (varargin{narg})) 90 elseif (ismatrix (varargin{narg}))
91 ## Accept but ignore the triangulation 91 ## Accept but ignore the triangulation
92 narg++; 92 narg++;
93 endif 93 endif
94 endif 94 endif
95 95
96 linespec = {"b"}; 96 linespec = {"b"};
97 if (narg <= nargin) 97 if (narg <= nargin)
98 if (ischar (varargin{narg})) 98 if (ischar (varargin{narg}))
99 linespec = varargin(narg); 99 linespec = varargin(narg);
100 endif 100 endif
101 endif 101 endif
102 102
128 128
129 idx = find (!infi); 129 idx = find (!infi);
130 ll = length (idx); 130 ll = length (idx);
131 c = c(idx).'; 131 c = c(idx).';
132 k = sum (cellfun ('length', c)); 132 k = sum (cellfun ('length', c));
133 edges = cell2mat(cellfun (@(x) [x ; [x(end), x(1:end-1)]], c, 133 edges = cell2mat(cellfun (@(x) [x ; [x(end), x(1:end-1)]], c,
134 "uniformoutput", false)); 134 "uniformoutput", false));
135 135
136 ## Identify the unique edges of the Voronoi diagram 136 ## Identify the unique edges of the Voronoi diagram
137 edges = sortrows (sort (edges).').'; 137 edges = sortrows (sort (edges).').';
138 edges = edges (:, [(edges(1, 1: end - 1) != edges(1, 2 : end) | ... 138 edges = edges (:, [(edges(1, 1: end - 1) != edges(1, 2 : end) | ...
148 148
149 ## Get points of the diagram 149 ## Get points of the diagram
150 vx = reshape (p (edges, 1), size(edges)); 150 vx = reshape (p (edges, 1), size(edges));
151 vy = reshape (p (edges, 2), size(edges)); 151 vy = reshape (p (edges, 2), size(edges));
152 152
153 if (nargout < 2) 153 if (nargout < 2)
154 lim = [xmin, xmax, ymin, ymax]; 154 lim = [xmin, xmax, ymin, ymax];
155 h = plot (handl, vx, vy, linespec{:}, x, y, '+'); 155 h = plot (handl, vx, vy, linespec{:}, x, y, '+');
156 axis (lim + 0.1 * [[-1, 1] * (lim (2) - lim (1)), ... 156 axis (lim + 0.1 * [[-1, 1] * (lim (2) - lim (1)), ...
157 [-1, 1] * (lim (4) - lim (3))]); 157 [-1, 1] * (lim (4) - lim (3))]);
158 if (nargout == 1) 158 if (nargout == 1)