Mercurial > octave
annotate scripts/plot/appearance/view.m @ 29358:0a5b15007766 stable
update Octave Project Developers copyright for the new year
In files that have the "Octave Project Developers" copyright notice,
update for 2021.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 10 Feb 2021 09:52:15 -0500 |
parents | 11072ea6a16c |
children | 7854d5752dd2 |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 ######################################################################## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 ## |
29358
0a5b15007766
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
28067
diff
changeset
|
3 ## Copyright (C) 2007-2021 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27898
diff
changeset
|
4 ## |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 ## See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 ## distribution or <https://octave.org/copyright/>. |
6257 | 7 ## |
8 ## This file is part of Octave. | |
9 ## | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
10 ## Octave is free software: you can redistribute it and/or modify it |
6257 | 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:
24432
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:
22323
diff
changeset
|
13 ## (at your option) any later version. |
6257 | 14 ## |
15 ## Octave is distributed in the hope that it will be useful, but | |
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
18 ## GNU General Public License for more details. |
6257 | 19 ## |
20 ## You should have received a copy of the GNU General Public License | |
7016 | 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:
24432
diff
changeset
|
22 ## <https://www.gnu.org/licenses/>. |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 ## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 ######################################################################## |
6257 | 25 |
26 ## -*- texinfo -*- | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
27 ## @deftypefn {} {} view (@var{azimuth}, @var{elevation}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
28 ## @deftypefnx {} {} view ([@var{azimuth} @var{elevation}]) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
29 ## @deftypefnx {} {} view ([@var{x} @var{y} @var{z}]) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
30 ## @deftypefnx {} {} view (2) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
31 ## @deftypefnx {} {} view (3) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
32 ## @deftypefnx {} {} view (@var{hax}, @dots{}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
33 ## @deftypefnx {} {[@var{azimuth}, @var{elevation}] =} view () |
17122
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
16356
diff
changeset
|
34 ## Query or set the viewpoint for the current axes. |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
16356
diff
changeset
|
35 ## |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
16356
diff
changeset
|
36 ## The parameters @var{azimuth} and @var{elevation} can be given as two |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
16356
diff
changeset
|
37 ## arguments or as 2-element vector. The viewpoint can also be specified with |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
16356
diff
changeset
|
38 ## Cartesian coordinates @var{x}, @var{y}, and @var{z}. |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
16356
diff
changeset
|
39 ## |
17157
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17125
diff
changeset
|
40 ## The call @code{view (2)} sets the viewpoint to @w{@var{azimuth} = 0} |
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17125
diff
changeset
|
41 ## and @w{@var{elevation} = 90}, which is the default for 2-D graphs. |
17122
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
16356
diff
changeset
|
42 ## |
17157
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17125
diff
changeset
|
43 ## The call @code{view (3)} sets the viewpoint to @w{@var{azimuth} = -37.5} |
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17125
diff
changeset
|
44 ## and @w{@var{elevation} = 30}, which is the default for 3-D graphs. |
17122
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
16356
diff
changeset
|
45 ## |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
16356
diff
changeset
|
46 ## If the first argument @var{hax} is an axes handle, then operate on |
24431
0c6cedafc71e
doc: Use 'axes' rather than 'axis' appropriately in docstrings.
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
47 ## this axes rather than the current axes returned by @code{gca}. |
17122
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
16356
diff
changeset
|
48 ## |
21546
f7f97d7e9294
doc: Wrap m-file docstrings to 79 characters + newline (80 total).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
49 ## If no inputs are given, return the current @var{azimuth} and |
f7f97d7e9294
doc: Wrap m-file docstrings to 79 characters + newline (80 total).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
50 ## @var{elevation}. |
6257 | 51 ## @end deftypefn |
52 | |
11344 | 53 function [azimuth, elevation] = view (varargin) |
6257 | 54 |
17157
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17125
diff
changeset
|
55 [hax, varargin, nargin] = __plt_get_axis_arg__ ("view", varargin{:}); |
28067
11072ea6a16c
view.m: Overhaul function (bug #57800).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
56 |
11072ea6a16c
view.m: Overhaul function (bug #57800).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
57 if (nargin > 2) |
11072ea6a16c
view.m: Overhaul function (bug #57800).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
58 print_usage (); |
11072ea6a16c
view.m: Overhaul function (bug #57800).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
59 endif |
11072ea6a16c
view.m: Overhaul function (bug #57800).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
60 |
17157
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17125
diff
changeset
|
61 if (isempty (hax)) |
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17125
diff
changeset
|
62 hax = gca (); |
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17125
diff
changeset
|
63 endif |
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17125
diff
changeset
|
64 |
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17125
diff
changeset
|
65 if (nargin == 0) |
28067
11072ea6a16c
view.m: Overhaul function (bug #57800).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
66 vw = get (hax, "view"); |
11072ea6a16c
view.m: Overhaul function (bug #57800).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
67 az = vw(1); |
11072ea6a16c
view.m: Overhaul function (bug #57800).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
68 el = vw(2); |
11072ea6a16c
view.m: Overhaul function (bug #57800).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
69 elseif (numel (varargin) == 1) |
17157
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17125
diff
changeset
|
70 x = varargin{1}; |
28067
11072ea6a16c
view.m: Overhaul function (bug #57800).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
71 if (numel (x) == 2) |
17157
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17125
diff
changeset
|
72 az = x(1); |
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17125
diff
changeset
|
73 el = x(2); |
28067
11072ea6a16c
view.m: Overhaul function (bug #57800).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
74 elseif (numel (x) == 3) |
17157
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17125
diff
changeset
|
75 [az, el] = cart2sph (x(1), x(2), x(3)); |
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17125
diff
changeset
|
76 az *= 180/pi; |
28067
11072ea6a16c
view.m: Overhaul function (bug #57800).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
77 if (az != 0) |
11072ea6a16c
view.m: Overhaul function (bug #57800).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
78 az += 90; # Special fix for bug #57800 |
11072ea6a16c
view.m: Overhaul function (bug #57800).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
79 endif |
17157
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17125
diff
changeset
|
80 el *= 180/pi; |
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17125
diff
changeset
|
81 elseif (x == 2) |
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17125
diff
changeset
|
82 az = 0; |
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17125
diff
changeset
|
83 el = 90; |
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17125
diff
changeset
|
84 elseif (x == 3) |
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17125
diff
changeset
|
85 az = -37.5; |
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17125
diff
changeset
|
86 el = 30; |
11344 | 87 else |
17157
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17125
diff
changeset
|
88 print_usage (); |
11344 | 89 endif |
28067
11072ea6a16c
view.m: Overhaul function (bug #57800).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
90 elseif (numel (varargin) == 2) |
17165
bb60b1bb47cf
view.m: Fix args undefined error when calling with two arguments
Max Brister <max@2bass.com>
parents:
17157
diff
changeset
|
91 az = varargin{1}; |
bb60b1bb47cf
view.m: Fix args undefined error when calling with two arguments
Max Brister <max@2bass.com>
parents:
17157
diff
changeset
|
92 el = varargin{2}; |
17157
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17125
diff
changeset
|
93 endif |
6257 | 94 |
17157
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17125
diff
changeset
|
95 if (nargin > 0) |
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17125
diff
changeset
|
96 set (hax, "view", [az, el]); |
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17125
diff
changeset
|
97 else |
6257 | 98 if (nargout == 1) |
17157
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17125
diff
changeset
|
99 azimuth = [az, el]; |
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17125
diff
changeset
|
100 elseif (nargout == 2) |
6257 | 101 azimuth = az; |
102 elevation = el; | |
103 endif | |
104 endif | |
105 | |
106 endfunction | |
13096 | 107 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
108 |
13096 | 109 %!test |
13124
2ea1658ad049
Don't use explicit figure number for tests to avoid interference with any figures opened by user.
Kai Habel <kai.habel@gmx.de>
parents:
13096
diff
changeset
|
110 %! hf = figure ("visible", "off"); |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
13124
diff
changeset
|
111 %! unwind_protect |
13096 | 112 %! plot3 ([0,1], [0,1], [0,1]); |
113 %! [az, el] = view; | |
114 %! assert ([az, el], [-37.5, 30], eps); | |
115 %! view (2); | |
116 %! [az, el] = view; | |
117 %! assert ([az, el], [0, 90], eps); | |
118 %! view ([1 1 0]); | |
119 %! [az, el] = view; | |
120 %! assert ([az, el], [135, 0], eps); | |
121 %! unwind_protect_cleanup | |
122 %! close (hf); | |
123 %! end_unwind_protect | |
124 | |
125 %!test | |
13124
2ea1658ad049
Don't use explicit figure number for tests to avoid interference with any figures opened by user.
Kai Habel <kai.habel@gmx.de>
parents:
13096
diff
changeset
|
126 %! hf = figure ("visible", "off"); |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
13124
diff
changeset
|
127 %! unwind_protect |
13096 | 128 %! line; |
129 %! [az, el] = view; | |
130 %! assert ([az, el], [0, 90], eps); | |
131 %! view (3); | |
132 %! [az, el] = view; | |
133 %! assert ([az, el], [-37.5, 30], eps); | |
134 %! unwind_protect_cleanup | |
135 %! close (hf); | |
136 %! end_unwind_protect | |
28067
11072ea6a16c
view.m: Overhaul function (bug #57800).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
137 |
11072ea6a16c
view.m: Overhaul function (bug #57800).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
138 ## Test input validation |
11072ea6a16c
view.m: Overhaul function (bug #57800).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
139 %!error <Invalid call> view (0, 0, 1) |