Skip to content

Commit 063eb73

Browse files
committed
Merge branch 'feature/new-oop' into feature/repackage
2 parents 47cf582 + 585294a commit 063eb73

File tree

11 files changed

+1239
-1315
lines changed

11 files changed

+1239
-1315
lines changed

@crdiskmap/crdiskmap.m

+143-158
Original file line numberDiff line numberDiff line change
@@ -1,161 +1,146 @@
1-
function M = crdiskmap(poly,varargin)
2-
%CRDISKMAP Schwarz-Christoffel cross-ratio disk map object.
3-
% CRDISKMAP(P) constructs a Schwarz-Christoffel crossratio disk map
4-
% object for the polygon P. The parameter problem is solved using
5-
% default options for the crossratios of the prevertices.
6-
%
7-
% CRDISKMAP(P,OPTIONS) uses an options structure of the type created
8-
% by SCMAPOPT in solving the parameter problem.
9-
%
10-
% CRDISKMAP(P,CR,Q) creates a crdiskmap object having the given
11-
% prevertex crossratios CR and quadrilateral graph Q. An OPTIONS
12-
% argument can be added, although only the error tolerance will be
13-
% used.
14-
%
15-
% CRDISKMAP(M), where M is a crdiskmap object, just returns M.
16-
%
17-
% CRDISKMAP(M,P) returns a new crdiskmap object for the polygon P
18-
% using the options in crdiskmap M. The crossratios in M will be used
19-
% as the starting guess for the parameter problem of the new map. Thus
20-
% P should properly be a perturbation of the polygon for M. An OPTIONS
21-
% structure may be added to override options in M.
22-
%
23-
% Use CRDISKMAP instead of DISKMAP when the polygon has elongations,
24-
% or when DISKMAP fails to converge.
25-
%
26-
% See also SCMAPOPT, classes POLYGON, DISKMAP.
27-
28-
% Copyright 1998-2001 by Toby Driscoll.
29-
% $Id: crdiskmap.m 129 2001-05-07 15:04:13Z driscoll $
30-
31-
superiorto('double');
32-
33-
34-
if nargin == 0
35-
M.crossratio = [];
36-
M.affine = [];
37-
M.qlgraph = [];
38-
M.qdata = [];
39-
M.original = [];
40-
M.center = {};
41-
M_sc = scmap;
42-
M.accuracy = [];
43-
M = class(M,'crdiskmap',M_sc);
44-
return
45-
end
46-
47-
% Assign empties to optional args
48-
cr = [];
49-
c = [];
50-
opt = [];
51-
52-
% Branch based on class of first argument
53-
switch class(poly)
54-
55-
case 'crdiskmap'
56-
M = poly;
57-
if nargin == 1
58-
% Self-return
59-
return
60-
else
61-
% Continuation of given map to given polygon
62-
poly = varargin{1};
63-
opt = scmapopt(M);
64-
cr0 = M.crossratio;
65-
if length(cr0) ~= length(poly)-3
66-
msg = 'Polygon %s must have the same length as that in %s.';
67-
error(sprintf(msg,inputname(2),inputname(1)))
68-
end
69-
if nargin > 2
70-
opt = scmapopt(opt,varargin{2});
1+
classdef (InferiorClasses = {?double}) crdiskmap < scmap
2+
3+
properties
4+
crossratio
5+
affine
6+
qlgraph
7+
qdata
8+
original
9+
center
10+
accuracy
7111
end
72-
opt = scmapopt(opt,'initial',cr0);
73-
orig = M.original;
74-
end
75-
76-
case 'polygon'
77-
% Parse optional arguments
78-
for j = 1:length(varargin)
79-
arg = varargin{j};
80-
% Each arg is an options struct, cr, or quadrilateral graph
81-
if isa(arg,'struct')
82-
if strmatch('edge',fieldnames(arg))
83-
Q = arg;
84-
else
85-
opt = arg;
86-
end
87-
elseif length(arg) == length(poly)-3
88-
cr = arg;
89-
cr = cr(:);
90-
else
91-
msg = 'Unable to parse argument ''%s''.';
92-
error(sprintf(msg,inputname(j+1)))
12+
13+
methods
14+
function map = crdiskmap(poly,varargin)
15+
%CRDISKMAP Schwarz-Christoffel cross-ratio disk map object.
16+
% CRDISKMAP(P) constructs a Schwarz-Christoffel crossratio disk map
17+
% object for the polygon P. The parameter problem is solved using
18+
% default options for the crossratios of the prevertices.
19+
%
20+
% CRDISKMAP(P,OPTIONS) uses an options structure of the type created
21+
% by SCMAPOPT in solving the parameter problem.
22+
%
23+
% CRDISKMAP(P,CR,Q) creates a crdiskmap object having the given
24+
% prevertex crossratios CR and quadrilateral graph Q. An OPTIONS
25+
% argument can be added, although only the error tolerance will be
26+
% used.
27+
%
28+
% CRDISKMAP(M), where M is a crdiskmap object, just returns M.
29+
%
30+
% CRDISKMAP(M,P) returns a new crdiskmap object for the polygon P
31+
% using the options in crdiskmap M. The crossratios in M will be used
32+
% as the starting guess for the parameter problem of the new map. Thus
33+
% P should properly be a perturbation of the polygon for M. An OPTIONS
34+
% structure may be added to override options in M.
35+
%
36+
% Use CRDISKMAP instead of DISKMAP when the polygon has elongations,
37+
% or when DISKMAP fails to converge.
38+
%
39+
% See also SCMAPOPT, classes POLYGON, DISKMAP.
40+
41+
% Copyright 1998-2001 by Toby Driscoll.
42+
43+
% Assign empties to optional args
44+
cr = [];
45+
c = [];
46+
opt = [];
47+
48+
% Branch based on class of first argument
49+
switch class(poly)
50+
51+
case 'crdiskmap'
52+
oldmap = poly;
53+
% Continuation of given map to given polygon
54+
poly = varargin{1};
55+
opt = scmapopt(oldmap);
56+
cr0 = oldmap.crossratio;
57+
if length(cr0) ~= length(poly)-3
58+
msg = 'Polygon %s must have the same length as that in %s.';
59+
error(msg,inputname(2),inputname(1))
60+
end
61+
if nargin > 2
62+
opt = scmapopt(opt,varargin{2});
63+
end
64+
opt = scmapopt(opt,'initial',cr0);
65+
orig = oldmap.original;
66+
67+
case 'polygon'
68+
% Parse optional arguments
69+
for j = 1:length(varargin)
70+
arg = varargin{j};
71+
% Each arg is an options struct, cr, or quadrilateral graph
72+
if isa(arg,'struct')
73+
if strmatch('edge',fieldnames(arg))
74+
Q = arg;
75+
else
76+
opt = arg;
77+
end
78+
elseif length(arg) == length(poly)-3
79+
cr = arg;
80+
cr = cr(:);
81+
else
82+
msg = 'Unable to parse argument ''%s''.';
83+
error(msg,inputname(j+1))
84+
end
85+
end
86+
87+
otherwise
88+
msg = 'Expected ''%s'' to be of class polygon or crdiskmap.';
89+
error(msg,inputname(1))
90+
91+
end % switch
92+
93+
94+
% Retrieve options
95+
opt = scmapopt(opt);
96+
97+
% Get data for the low-level functions
98+
w = vertex(poly);
99+
beta = angle(poly)-1;
100+
101+
% Find prevertices if necessary
102+
if isempty(cr)
103+
% Apply SCFIX to enforce solver rules
104+
[w,beta] = scfix('d',w,beta);
105+
106+
% Solve
107+
if isempty(opt.InitialGuess)
108+
% Standard solution
109+
[w,beta,cr,aff,Q,orig,qdata] = ...
110+
crparam(w,beta,opt.InitialGuess,opt);
111+
% Remake polygon to reflect change in w
112+
poly = polygon(w,beta+1);
113+
else
114+
% Continutation syntax
115+
[cr,aff,Q] = crparam(w,beta,opt.InitialGuess,opt);
116+
nqpts = ceil(-log10(opt.Tolerance));
117+
qdata = scqdata(beta,nqpts);
118+
end
119+
120+
else
121+
orig = true(size(w));
122+
% Base accuracy of quadrature on given options
123+
nqpts = ceil(-log10(opt.Tolerance));
124+
qdata = scqdata(beta,nqpts);
125+
end
126+
127+
map = map@scmap(poly,opt);
128+
129+
map.crossratio = cr;
130+
map.affine = aff;
131+
map.qlgraph = Q;
132+
map.qdata = qdata;
133+
map.original = orig;
134+
135+
% Set conformal center as center of 1st triangle
136+
T = Q.qlvert(1:3,1);
137+
wc = mean(w(T));
138+
wcfix = crfixwc(w,beta,cr,aff,Q,wc);
139+
map.center = {wc,wcfix};
140+
141+
% Now fill in true accuracy
142+
map.accuracy = accuracy(map);
143+
144+
end
93145
end
94-
end
95-
96-
otherwise
97-
msg = 'Expected ''%s'' to be of class polygon or crdiskmap.';
98-
error(sprintf(msg,inputname(1)))
99-
100-
end % switch
101-
102-
103-
% Retrieve options
104-
opt = scmapopt(opt);
105-
106-
% Get data for the low-level functions
107-
w = vertex(poly);
108-
beta = angle(poly)-1;
109-
110-
% Find prevertices if necessary
111-
if isempty(cr)
112-
% Apply SCFIX to enforce solver rules
113-
[w,beta] = scfix('d',w,beta);
114-
115-
% Solve
116-
if isempty(opt.InitialGuess)
117-
% Standard solution
118-
[w,beta,cr,aff,Q,orig,qdata] = ...
119-
crparam(w,beta,opt.InitialGuess,opt);
120-
% Remake polygon to reflect change in w
121-
poly = polygon(w,beta+1);
122-
else
123-
% Continutation syntax
124-
[cr,aff,Q] = crparam(w,beta,opt.InitialGuess,opt);
125-
nqpts = ceil(-log10(opt.Tolerance));
126-
qdata = scqdata(beta,nqpts);
127-
end
128-
129-
else
130-
orig = logical(ones(size(w)));
131-
% Base accuracy of quadrature on given options
132-
nqpts = ceil(-log10(opt.Tolerance));
133-
qdata = scqdata(beta,nqpts);
134-
end
135-
136-
M.crossratio = cr;
137-
M.affine = aff;
138-
M.qlgraph = Q;
139-
M.qdata = qdata;
140-
M.original = orig;
141-
142-
% Set conformal center as center of 1st triangle
143-
T = Q.qlvert(1:3,1);
144-
wc = mean(w(T));
145-
wcfix = crfixwc(w,beta,cr,aff,Q,wc);
146-
M.center = {wc,wcfix};
147-
148-
% Make a parent scmap object
149-
M_sc = scmap(poly,opt);
150-
151-
% Leave a spot for accuracy and create object
152-
M.accuracy = [];
153-
if ~isa(M,'crdiskmap')
154-
M = class(M,'crdiskmap',M_sc);
155-
else
156-
M.scmap = M_sc;
157146
end
158-
159-
% Now fill in true accuracy
160-
M.accuracy = accuracy(M);
161-

0 commit comments

Comments
 (0)