From a210fa7eedb1c4a78e52cf108164fbcc94469501 Mon Sep 17 00:00:00 2001 From: Travis Askham Date: Thu, 30 May 2024 20:30:41 -0400 Subject: [PATCH] quick patch of chunkgraph behavior for old spec with two edges --- chunkie/@chunkgraph/chunkgraph.m | 2 +- devtools/test/chunkgraph_basicTest.m | 69 ++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 devtools/test/chunkgraph_basicTest.m diff --git a/chunkie/@chunkgraph/chunkgraph.m b/chunkie/@chunkgraph/chunkgraph.m index 40d5260..6ec0053 100644 --- a/chunkie/@chunkgraph/chunkgraph.m +++ b/chunkie/@chunkgraph/chunkgraph.m @@ -44,7 +44,7 @@ obj.verts = verts; nverts = size(verts(:,:),2); - if (size(edgesendverts,1) ~= 2) + if (size(edgesendverts,1) ~= 2 || any(edgesendverts(:) <= 0)) assert(nverts == size(edgesendverts,2),'edge specification not compatible with number of vertices'); nedge = size(edgesendverts,1); diff --git a/devtools/test/chunkgraph_basicTest.m b/devtools/test/chunkgraph_basicTest.m new file mode 100644 index 0000000..d771081 --- /dev/null +++ b/devtools/test/chunkgraph_basicTest.m @@ -0,0 +1,69 @@ +%chunkgraph_basicTest +% +% test of basic chunkgraph class constructors, methods, etc. +% + +clearvars +addpaths_loc(); + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% . . . builds a simple pentagonal chunkergraph + + +verts = exp(1i*2*pi*(0:4)/5); +verts = [real(verts);imag(verts)]; + +endverts = [1:5; [2:5 1]]; + +edge2verts = [-1, 1, 0, 0, 0; ... + 0,-1, 1, 0, 0; ... + 0, 0,-1, 1, 0; ... + 0, 0, 0,-1, 1; ... + 1, 0, 0, 0,-1]; + +edge2verts = sparse(edge2verts); +amp = 0.5; +frq = 6; +fchnks = {}; +for icurve = 1:size(edge2verts,1) + fchnks{icurve} = @(t) sinearc(t,amp,frq); +end + +prefs = []; +[cgrph1] = chunkgraph(verts,edge2verts,fchnks,prefs); +[cgrph2] = chunkgraph(verts,endverts,fchnks,prefs); + +assert(nnz(cgrph1.v2emat-cgrph2.v2emat) == 0); + +cgrph1 = balance(cgrph1); + +% adjacent triangles + +verts = [1 0 -1 0; 0 1 0 -1]; edgesendverts = [1:3, 3, 4; 2:3, 1, 4, 1]; +cg = chunkgraph(verts,edgesendverts); + +% a graph with two edges in the old format + +verts = [1 0 1; -1 0 1]; edge2verts = [-1 1 0; 0 -1 1]; +cg1 = chunkgraph(verts,edge2verts); + +edgesendverts = [1:2; 2:3]; +cg2 = chunkgraph(verts,edgesendverts); + +assert(nnz(cg1.v2emat-cg2.v2emat) == 0); + + +function [r,d,d2] = sinearc(t,amp,frq) + +xs = t; +ys = amp*sin(frq*t); +xp = ones(size(t)); +yp = amp*frq*cos(frq*t); +xpp = zeros(size(t)); +ypp = -frq*frq*amp*sin(t); + +r = [(xs(:)).'; (ys(:)).']; +d = [(xp(:)).'; (yp(:)).']; +d2 = [(xpp(:)).'; (ypp(:)).']; +end