-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathgridcurves.m
158 lines (132 loc) · 3.51 KB
/
gridcurves.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
classdef gridcurves
% GRIDCURVES class holds grid curves for regions.
%
% grid = gridcurves(curves)
% The given cell array curves is stored in the object. This is mainly to
% facilitate the use of plot(grid) to give a standard look to grid plots.
%
% Stores grid curves as entries in cell array. Consider
% gd = gridcurves;
% We overload gd(n) and gd(n,m) to retrieve those cell array entries. Why
% not just use the '{}' syntax? Wouldn't it be clearer we're using cell arrays?
% This file is a part of the CMToolbox.
% It is licensed under the BSD 3-clause license.
% (See LICENSE.)
% Copyright Toby Driscoll, 2014.
% (Re)written by Everett Kropf, 2014,
% adapted from an idea by Toby Driscoll, 20??.
properties
curveList
end
methods
function gc = gridcurves(curves)
if ~nargin
return
end
if nargin > 1 || ~isa(curves, 'cell')
error('CMT:InvalidArgument', ...
'Expected a cell array of individual grid curves.')
end
gc.curveList = curves;
end
function gc = conj(gc)
% Complex conjugation.
for k = 1:numel(gc.curveList)
gc.curveList{k} = conj(gc.curveList{k});
end
end
function disp(gd)
fprintf('gridcurves object:\n\n')
fprintf(' with %d gridlines.\n\n', numel(gd.curveList))
end
function gc = minus(gc, b)
if ~isa(gc, 'gridcurves')
gc = plus(-b, gc);
return
end
gc.scalaronly(b)
for k = 1:numel(gc.curveList)
gc.curveList{k} = gc.curveList{k} - b;
end
end
function gc = mtimes(gc, b)
if ~isa(gc, 'gridcurves')
[gc, b] = deal(b, gc);
end
gc.scalaronly(b)
for k = 1:numel(gc.curveList)
gc.curveList{k} = b*gc.curveList{k};
end
end
function gc = mrdivide(gc, b)
gc = rdivide(gc, b);
end
function n = numel(gc, varargin)
% Overloaded for subsref.
n = numel(gc.curveList, varargin{:});
end
function gc = rdivide(gc, b)
if isa(gc, 'gridcurves')
gc.scalaronly(b)
gc = mtimes(gc, 1/b);
else
[gc, b] = deal(b, gc);
gc.scalaronly(b)
for k = 1:numel(gc.curveList)
gc.curveList{k} = b./gc.curveList{k};
end
end
end
function out = plot(gc, varargin)
washold = ishold;
ah = newplot;
gctag = sprintf('gridcurve_%s', num2hex(rand));
hold on
[gargs, pargs] = cmtplot.gridArgs(varargin{:});
for k = 1:numel(gc.curveList)
zg = gc.curveList{k};
line(real(zg), imag(zg), pargs{:}, gargs{:}, 'tag', gctag)
end
if ~washold
hold off
end
if nargout
out = findobj(ah, 'tag', gctag);
end
end
function gc = plus(gc, b)
if ~isa(gc, 'gridcurves')
[gc, b] = deal(b, gc);
end
gc.scalaronly(b)
for k = 1:numel(gc.curveList)
gc.curveList{k} = gc.curveList{k} + b;
end
end
function varargout = subsref(gc, S)
% Provide C(j) or C(j,k) access to curve cell array.
% Why? See gridcurves help.
switch S(1).type
case {'()', '{}'}
if S(1).type(1) == '('
S(1).type = '{}';
end
[varargout{1:nargout}] = subsref(gc.curveList, S);
otherwise
[varargout{1:nargout}] = builtin('subsref', gc, S);
end
end
function gc = uminus(gc)
for k = 1:numel(gc.curveList)
gc.curveList{k} = -gc.curveList{k};
end
end
end
methods(Access=private)
function scalaronly(~, b)
if ~isa(b, 'double') || numel(b) ~= 1
error('CMT:NotDefined', 'Operation only defined for scalar values.')
end
end
end
end