Skip to content

Commit

Permalink
Merge pull request #92 from fastalgorithms/chunkerfunc-notclosed-warning
Browse files Browse the repository at this point in the history
adds a warning to chunkerfunc when the curve is not closed but ifclos…
  • Loading branch information
mrachh authored Aug 23, 2024
2 parents 53869cf + 65e3b1c commit 60c7369
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
31 changes: 30 additions & 1 deletion chunkie/chunkerfunc.m
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@

% discover number of outputs
try
[r,d,d2] = fcurve(t);
[r,d,d2] = fcurve(ta);
nout = 3;
catch
try
Expand Down Expand Up @@ -314,6 +314,9 @@
rad_curr = max(xmax-xmin,ymax-ymin);
end

%



% the curve should be resolved to precision eps now on
% each interval ab(,i)
Expand Down Expand Up @@ -551,6 +554,32 @@
chnkr.d2stor(:,:,i) = reshape(out{3},dim,k)*h*h;
end

% check ends
lrinterpmat = lege.matrin(k,[-1;1],us);
left1 = lrinterpmat(1,:)*(chnkr.rstor(:,:,1).');
rightnch = lrinterpmat(2,:)*(chnkr.rstor(:,:,nch).');
dleft1 = lrinterpmat(1,:)*(chnkr.dstor(:,:,1).');
dleft1 = dleft1(:)/norm(dleft1(:));
drightnch = lrinterpmat(2,:)*(chnkr.dstor(:,:,nch).');
drightnch = drightnch(:)/norm(drightnch(:));

msgbase = "CHUNKERFUNC: ";
if norm(left1(:)-rightnch(:))/rad_curr > eps && ifclosed
msg = msgbase + ...
"start and end points of curve parameterization are not the same" + ...
" to target precision but ifclosed flag is true." + ...
" Check curve parameterization or if not a closed curve" + ...
" set flag appropriately and consider creating a chunkgraph object";
warning(msg);
elseif norm(dleft1(:)-drightnch(:)) > eps*k && ifclosed
msg = msgbase + ...
"unit tangent vectors at start and end points of curve are not the same" + ...
" to target precision but ifclosed flag is true." + ...
" Check curve parameterization or if not a closed curve" + ...
" set flag appropriately and consider creating a chunkgraph object";
warning(msg);
end

chnkr.adjstor(:,1:nch) = adjs(:,1:nch);

% update normals
Expand Down
19 changes: 19 additions & 0 deletions devtools/test/chunkerfuncTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,25 @@
a = area(chnkr);
assert(abs(a - pi*r^2) < 1e-12,'area wrong for circle domain')

% iflcosed flag testing

lastwarn(''); %clears warning state
cparams = [];
chnkr = chunkerfunc(@(t) [cos(t(:).'); sin(t(:).'/2)],cparams);
[warnmsg,warnID] = lastwarn;
assert(~isempty(warnmsg));

lastwarn(''); %clears warning state
cparams = []; cparams.ta=0; cparams.tb=2*pi-1e-3;
chnkr = chunkerfunc(@(t) [cos(t(:).'); sin(t(:).')],cparams);
[warnmsg,warnID] = lastwarn;
assert(~isempty(warnmsg));

lastwarn(''); %clears warning state
cparams = []; cparams.ta=0; cparams.tb=2*pi-1e-3; cparams.ifclosed = false;
chnkr = chunkerfunc(@(t) [cos(t(:).'); sin(t(:).')],cparams);
[warnmsg,warnID] = lastwarn;
assert(isempty(warnmsg));

% subplot(1,3,3)
% plot(chnkr)
Expand Down

0 comments on commit 60c7369

Please sign in to comment.