function testnorm(varargin)
% testnorm([options])
% Demonstrates how estimatepolytopenorm() works
%
% Options:
%   'RNG',val                       Seed for the random-number generator
%   'nVV',val                       number of points of the polytope. Default=30
%   'STEP',val                      Resolution. Default=0.02
%   'type',val                      which polytope to generate. Default=0
%                                       0: cone
%                                       1: balanced polytope
%                                       otherwise: balanced polytope with undefined behaviour. See estimatepolytopenorm() for possible values
%   'removeinteriorpoints'          If set, interior points of the polytope are removed. Default: false
%                                   For this to work, testnorm() also needs the function computepolytopenorm()
%   'colorregion',val               Colors the regions where the points are for sure outside or inside the polytope. Default=1;
%
% Output:
%   A nice picture
%
% See also: testnorm2, estimatepolytopenorm
%
% Written by: tommsch, 2018



RNG=parsem('RNG',varargin,0); if(RNG); rng(RNG); end;
nVV=parsem('nVV',varargin,10);
STEP=parsem('STEP',varargin,0.02);
type=parsem('type',varargin,0);
removeinteriorpoints=parsem('removeinteriorpoints',varargin,0);
colorregion=parsem('colorregion',varargin,1);

dim=2; %dimension
comax=1.2;
if(type==0)
    comin=0;
else
    comin=-comax;
end
co=comin:STEP:comax;
pts=mixvector(co,dim);
vprintf('Number of points to compute: %i',size(pts,2));

%generate poyltope
if(type==0)
    VV=rand(dim,nVV)/3; 
    VV=abs((normalizematrix(VV,'colnorm',2))/2+rand(size(VV))*.3);
else
    VV=randn(dim,nVV)/3; 
    VV=(normalizematrix(VV,'colnorm',2))/2+rand(size(VV))*.3;
end

%remove interior points
if(removeinteriorpoints)
    [normval,~]=estimatepolytopenorm(VV, VV, [], 11);
    VV(:,normval<1)=[]; 
end

[normval,region]=estimatepolytopenorm(pts, VV, [], type);
if(colorregion)
    normval(normval<region(1))=normval(normval<region(1))/1.2;
    normval(normval>region(2))=normval(normval>region(2))*1.2;
end

clf; hold on;
normval=reshape(normval,length(co),[]);
image('XData',[comin comax], 'YData', [comin,comax], 'CData',normval,'CDataMapping','scaled');
if(type==0)
    plotm(VV,'k.');
else
    plotm([VV -VV],'k.');
end
colorbar
axis equal

end