Mercurial > hg > octave-lyh
annotate scripts/plot/rectangle.m @ 14868:5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
* lin2mu.m, loadaudio.m, wavread.m, accumarray.m, bicubic.m, celldisp.m,
colon.m, cplxpair.m, dblquad.m, divergence.m, genvarname.m, gradient.m,
int2str.m, interp1.m, interp1q.m, interp2.m, interpn.m, loadobj.m, nthargout.m,
__isequal__.m, __splinen__.m, quadgk.m, quadl.m, quadv.m, rat.m, rot90.m,
rotdim.m, saveobj.m, subsindex.m, triplequad.m, delaunay3.m, griddata.m,
inpolygon.m, tsearchn.m, voronoi.m, get_first_help_sentence.m, which.m,
gray2ind.m, pink.m, dlmwrite.m, strread.m, textread.m, textscan.m, housh.m,
ishermitian.m, issymmetric.m, krylov.m, logm.m, null.m, rref.m,
compare_versions.m, copyfile.m, dump_prefs.m, edit.m, fileparts.m,
getappdata.m, isappdata.m, movefile.m, orderfields.m, parseparams.m,
__xzip__.m, rmappdata.m, setappdata.m, swapbytes.m, unpack.m, ver.m, fminbnd.m,
fminunc.m, fsolve.m, glpk.m, lsqnonneg.m, qp.m, sqp.m, configure_make.m,
copy_files.m, describe.m, get_description.m, get_forge_pkg.m, install.m,
installed_packages.m, is_architecture_dependent.m, load_package_dirs.m,
print_package_description.m, rebuild.m, repackage.m, save_order.m, shell.m,
allchild.m, ancestor.m, area.m, axes.m, axis.m, clabel.m, close.m, colorbar.m,
comet.m, comet3.m, contour.m, cylinder.m, ezmesh.m, ezsurf.m, findobj.m,
fplot.m, hist.m, isocolors.m, isonormals.m, isosurface.m, isprop.m, legend.m,
mesh.m, meshz.m, pareto.m, pcolor.m, peaks.m, plot3.m, plotmatrix.m, plotyy.m,
polar.m, print.m, __add_datasource__.m, __add_default_menu__.m,
__axes_limits__.m, __bar__.m, __clabel__.m, __contour__.m, __errcomm__.m,
__errplot__.m, __ezplot__.m, __file_filter__.m, __fltk_print__.m,
__ghostscript__.m, __gnuplot_print__.m, __go_draw_axes__.m,
__go_draw_figure__.m, __interp_cube__.m, __marching_cube__.m, __patch__.m,
__pie__.m, __plt__.m, __print_parse_opts__.m, __quiver__.m, __scatter__.m,
__stem__.m, __tight_eps_bbox__.m, __uigetdir_fltk__.m, __uigetfile_fltk__.m,
__uiputfile_fltk__.m, quiver.m, quiver3.m, rectangle.m, refreshdata.m,
ribbon.m, scatter.m, semilogy.m, shading.m, slice.m, subplot.m, surface.m,
surfl.m, surfnorm.m, text.m, uigetfile.m, uiputfile.m, whitebg.m, deconv.m,
mkpp.m, pchip.m, polyaffine.m, polyder.m, polygcd.m, polyout.m, polyval.m,
ppint.m, ppjumps.m, ppval.m, residue.m, roots.m, spline.m, splinefit.m,
addpref.m, getpref.m, setpref.m, ismember.m, setxor.m, arch_fit.m, arch_rnd.m,
arch_test.m, autoreg_matrix.m, diffpara.m, fftconv.m, filter2.m, hanning.m,
hurst.m, periodogram.m, triangle_sw.m, sinc.m, spectral_xdf.m, spencer.m,
stft.m, synthesis.m, unwrap.m, yulewalker.m, bicgstab.m, gmres.m, pcg.m, pcr.m,
__sprand_impl__.m, speye.m, spfun.m, sprandn.m, spstats.m, svds.m,
treelayout.m, treeplot.m, bessel.m, factor.m, legendre.m, perms.m, primes.m,
magic.m, toeplitz.m, corr.m, cov.m, mean.m, median.m, mode.m, qqplot.m,
quantile.m, ranks.m, zscore.m, logistic_regression_likelihood.m,
bartlett_test.m, chisquare_test_homogeneity.m, chisquare_test_independence.m,
kolmogorov_smirnov_test.m, run_test.m, u_test.m, wilcoxon_test.m, z_test.m,
z_test_2.m, bin2dec.m, dec2base.m, mat2str.m, strcat.m, strchr.m, strjust.m,
strtok.m, substr.m, untabify.m, assert.m, demo.m, example.m, fail.m, speed.m,
test.m, now.m: Use Octave coding conventions for cuddling parentheses in
scripts directory.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Tue, 17 Jul 2012 07:08:39 -0700 |
parents | 4506eade9f04 |
children | 3e1b24a2454a |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
14019
diff
changeset
|
1 ## Copyright (C) 2012 David Bateman |
12697 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7 ## the Free Software Foundation; either version 3 of the License, or (at | |
8 ## your option) any later version. | |
9 ## | |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
16 ## along with Octave; see the file COPYING. If not, see | |
17 ## <http://www.gnu.org/licenses/>. | |
18 | |
19 ## -*- texinfo -*- | |
12698
fb93b94dfc82
Add rectangle to new functions list in NEWS.
Rik <octave@nomad.inbox5.com>
parents:
12697
diff
changeset
|
20 ## @deftypefn {Function File} {} rectangle () |
12697 | 21 ## @deftypefnx {Function File} {} rectangle (@dots{}, "Position", @var{pos}) |
22 ## @deftypefnx {Function File} {} rectangle (@dots{}, "Curvature", @var{curv}) | |
23 ## @deftypefnx {Function File} {} rectangle (@dots{}, "EdgeColor", @var{ec}) | |
24 ## @deftypefnx {Function File} {} rectangle (@dots{}, "FaceColor", @var{fc}) | |
25 ## @deftypefnx {Function File} {@var{h} =} rectangle (@dots{}) | |
26 ## | |
12698
fb93b94dfc82
Add rectangle to new functions list in NEWS.
Rik <octave@nomad.inbox5.com>
parents:
12697
diff
changeset
|
27 ## Draw rectangular patch defined by @var{pos} and @var{curv}. The variable |
12763
f511bfe00d14
maint: Periodic merge of stable to default
Rik <octave@nomad.inbox5.com>
parents:
12761
diff
changeset
|
28 ## @code{@var{pos}(1:2)} defines the lower left-hand corner of the patch |
f511bfe00d14
maint: Periodic merge of stable to default
Rik <octave@nomad.inbox5.com>
parents:
12761
diff
changeset
|
29 ## and @code{@var{pos}(3:4)} defines its width and height. By default, the |
12761
13bcd62824a7
doc: Add documentation for gmres, rectangle to manual
Rik <octave@nomad.inbox5.com>
parents:
12698
diff
changeset
|
30 ## value of @var{pos} is @code{[0, 0, 1, 1]}. |
12697 | 31 ## |
32 ## The variable @var{curv} defines the curvature of the sides of the rectangle | |
12761
13bcd62824a7
doc: Add documentation for gmres, rectangle to manual
Rik <octave@nomad.inbox5.com>
parents:
12698
diff
changeset
|
33 ## and may be a scalar or two-element vector with values between 0 and 1. |
13bcd62824a7
doc: Add documentation for gmres, rectangle to manual
Rik <octave@nomad.inbox5.com>
parents:
12698
diff
changeset
|
34 ## A value of 0 represents no curvature of the side, whereas a value of 1 |
13bcd62824a7
doc: Add documentation for gmres, rectangle to manual
Rik <octave@nomad.inbox5.com>
parents:
12698
diff
changeset
|
35 ## means that the side is entirely curved into the arc of a circle. |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12763
diff
changeset
|
36 ## If @var{curv} is a two-element vector, then the first element is the |
12697 | 37 ## curvature along the x-axis of the patch and the second along y-axis. |
38 ## | |
39 ## If @var{curv} is a scalar, it represents the curvature of the shorter of the | |
40 ## two sides of the rectangle and the curvature of the other side is defined | |
41 ## by | |
42 ## | |
43 ## @example | |
12763
f511bfe00d14
maint: Periodic merge of stable to default
Rik <octave@nomad.inbox5.com>
parents:
12761
diff
changeset
|
44 ## min (pos (1:2)) / max (pos (1:2)) * curv |
12697 | 45 ## @end example |
46 ## | |
14001
5f0bb45e615c
doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents:
13141
diff
changeset
|
47 ## Other properties are passed to the underlying patch command. |
5f0bb45e615c
doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents:
13141
diff
changeset
|
48 ## |
5f0bb45e615c
doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents:
13141
diff
changeset
|
49 ## The optional return value @var{h} is a graphics handle to the created |
5f0bb45e615c
doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents:
13141
diff
changeset
|
50 ## rectangle object. |
12697 | 51 ## @end deftypefn |
52 ## @seealso{patch} | |
53 | |
54 function h = rectangle (varargin) | |
55 | |
56 [hax, varargin] = __plt_get_axis_arg__ ("rectangle", varargin{:}); | |
57 | |
58 tmp = __rectangle__ (hax, varargin{:}); | |
59 | |
60 if (nargout > 0) | |
61 h = tmp; | |
62 endif | |
63 endfunction | |
64 | |
65 function hg = __rectangle__ (hax, varargin) | |
66 | |
67 iarg = 1; | |
68 pos = [0, 0, 1, 1]; | |
69 curv2 = [0, 0]; | |
70 ec = [0, 0, 0]; | |
71 fc = "none"; | |
72 | |
73 while (iarg < length (varargin)) | |
74 arg = varargin{iarg}; | |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14245
diff
changeset
|
75 if (ischar (arg)) |
12697 | 76 if (strcmpi (arg, "position")) |
77 pos = varargin{iarg+1}; | |
78 varargin(iarg:iarg+1) = []; | |
79 if (!isvector (pos) || numel (pos) != 4) | |
80 error ("rectangle: position must be a 4 element vector"); | |
81 endif | |
82 elseif (strcmpi (arg, "curvature")) | |
83 curv2 = varargin{iarg+1}; | |
84 varargin(iarg:iarg+1) = []; | |
85 if (!isnumeric (curv2) || (numel (curv2) != 1 && numel (curv2) != 2)) | |
86 error ("rectangle: curvature must be a 2 element vector or a scalar"); | |
87 endif | |
88 if (any (curv2 < 0) || any (curv2 > 1)) | |
89 error ("rectangle: curvature values must be between 0 and 1"); | |
90 endif | |
91 elseif (strcmpi (arg, "edgecolor")) | |
92 ec = varargin{iarg+1}; | |
93 varargin(iarg:iarg+1) = []; | |
94 elseif (strcmpi (arg, "facecolor")) | |
95 fc = varargin{iarg+1}; | |
96 varargin(iarg:iarg+1) = []; | |
97 else | |
98 iarg ++; | |
99 endif | |
100 else | |
101 iarg ++; | |
102 endif | |
103 endwhile | |
104 | |
105 if (numel (curv2) == 1) | |
106 [a, ai] = min (pos (3 : 4)); | |
107 [b, bi] = max (pos (3 : 4)); | |
108 if (ai < bi) | |
109 curv = [curv2, curv2 .* a ./ b]; | |
110 else | |
111 curv = [curv2 .* a ./ b, curv2]; | |
112 endif | |
113 else | |
114 curv = curv2; | |
115 endif | |
116 | |
117 if (all (curv) < 0.01) | |
118 ## Special case : no curvature | |
119 x = [pos(1), pos(1) + pos(3), pos(1) + pos(3), pos(1), pos(1)]; | |
120 y = [pos(2), pos(2), pos(2) + pos(4), pos(2) + pos(4), pos(2)]; | |
121 else | |
122 p = pi / 2 * [0 : 15] / 15; | |
123 c = curv .* pos(3 : 4) / 2; | |
124 cx = c(1) * sin (p) - c(1); | |
125 cy = c(2) * cos (p) - c(2); | |
126 x = [pos(1) - fliplr(cx), pos(1) + pos(3) + cx, ... | |
127 pos(1) + pos(3) + fliplr(cx), pos(1) - cx, pos(1)]; | |
128 y = [pos(2) - fliplr(cy), pos(2) - cy, pos(2) + pos(4) + fliplr(cy), ... | |
129 pos(2) + pos(4) + cy, pos(2) + c(2)]; | |
130 endif | |
131 | |
132 hg = hggroup (); | |
133 | |
134 h = patch ("xdata", x(:), "ydata", y(:), "facecolor", fc, "edgecolor", ec, ... | |
135 "parent", hg, varargin{:}); | |
136 | |
137 addproperty ("curvature", hg, "data", curv2); | |
138 addproperty ("position", hg, "data", pos); | |
139 addproperty ("edgecolor", hg, "patchedgecolor", get (h, "edgecolor")); | |
140 addproperty ("linewidth", hg, "patchlinewidth", get (h, "linewidth")); | |
141 addproperty ("linestyle", hg, "patchlinestyle", get (h, "linestyle")); | |
142 addproperty ("facecolor", hg, "patchfacecolor", get (h, "facecolor")); | |
143 | |
144 addlistener (hg, "curvature", @update_data); | |
145 addlistener (hg, "position", @update_data); | |
146 addlistener (hg, "edgecolor", @update_props); | |
147 addlistener (hg, "linewidth", @update_props); | |
148 addlistener (hg, "linestyle", @update_props); | |
149 addlistener (hg, "facecolor", @update_props); | |
150 endfunction | |
151 | |
152 function update_data (h, d) | |
153 persistent recursion = false; | |
154 | |
155 ## Don't allow recursion | |
156 if (!recursion) | |
157 unwind_protect | |
158 recursion = true; | |
159 | |
160 kids = get (h, "children"); | |
161 pos = get (h, "position"); | |
162 curv2 = get (h, "curvature"); | |
163 | |
164 if (numel (curv2) == 1) | |
165 [a, ai] = min (pos (3 : 4)); | |
166 [b, bi] = max (pos (3 : 4)); | |
167 if (ai < bi) | |
168 curv = [curv2, curv2 .* a ./ b]; | |
169 else | |
170 curv = [curv2 .* a ./ b, curv2]; | |
171 endif | |
172 else | |
173 curv = curv2; | |
174 endif | |
175 | |
176 if (all (curv) < 0.01) | |
177 ## Special case : no curvature | |
178 x = [pos(1), pos(1) + pos(3), pos(1) + pos(3), pos(1), pos(1)]; | |
179 y = [pos(2), pos(2), pos(2) + pos(4), pos(2) + pos(4), pos(2)]; | |
180 else | |
181 p = pi / 2 * [0 : 15] / 15; | |
182 c = curv .* pos(3 : 4) / 2; | |
183 cx = c(1) * sin (p) - c(1); | |
184 cy = c(2) * cos (p) - c(2); | |
185 x = [pos(1) - fliplr(cx), pos(1) + pos(3) + cx, ... | |
186 pos(1) + pos(3) + fliplr(cx), pos(1) - cx, pos(1)]; | |
187 y = [pos(2) - fliplr(cy), pos(2) - cy, pos(2) + pos(4) + fliplr(cy), ... | |
188 pos(2) + pos(4) + cy, pos(2) + c(2)]; | |
189 endif | |
190 | |
191 set (kids, "xdata", x, "ydata", y); | |
192 unwind_protect_cleanup | |
193 recursion = false; | |
194 end_unwind_protect | |
195 endif | |
196 endfunction | |
197 | |
198 function update_props (h, d) | |
199 kids = get (h, "children"); | |
200 set (kids, "edgecolor", get (h, "edgecolor"), | |
201 "linewidth", get (h, "linewidth"), | |
202 "linestyle", get (h, "linestyle"), | |
203 "facecolor", get (h, "facecolor")); | |
204 endfunction | |
205 | |
12698
fb93b94dfc82
Add rectangle to new functions list in NEWS.
Rik <octave@nomad.inbox5.com>
parents:
12697
diff
changeset
|
206 |
12697 | 207 %!demo |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
208 %! clf; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
209 %! axis equal; |
14245
4506eade9f04
Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
210 %! rectangle ('Position', [0.05, 0.05, 0.9, 0.9], 'Curvature', [0.5, 0.5]); |
12697 | 211 |
212 %!demo | |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
213 %! clf; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
214 %! axis equal; |
14245
4506eade9f04
Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
215 %! rectangle ('Position', [0.05, 0.05, 0.9, 0.4], 'Curvature', 1.0); |
12697 | 216 |
217 %!demo | |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
218 %! clf; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
219 %! axis equal; |
14245
4506eade9f04
Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
220 %! h = rectangle ('Position', [0.05, 0.05, 0.9, 0.4], 'Curvature', 1.0); |
4506eade9f04
Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
221 %! set (h, 'FaceColor', [0, 1, 0]); |
12697 | 222 |