% compute boundingbox of p-vector
%
% finds low and high limits of indices normalized to [0,0]..[1,1]
%
% examples: [Ml,Nl,Mh,Nh] = boundingbox(p);
%           bb = boundingbox(p);              % creates vector of lenght 4
%           boundingbox(p)                    % displays to stdout
%
% see also boundingboxextrema.m

function [Ml_outarglist,Nl,Mh,Nh] = relativeto00011011(p);

% check that input is the correct dimension
[M,N] = size(p);
if min(M,N) ~= 1
  disp( 'boundingbox: you might want to take a look at boundingboxextrema.m')
  error('boundingbox: input parameter not vector')
end%if
if max(M,N) ~= 8
  error('boundingbox: input should be a vector of 8 elements')
end%if

mdomain=[0 0 1 1];
ndomain=[0 1 0 1];
X=[mdomain;ndomain];                % X is [x;y] colvec coords
pinver=pinverse(p);
A=[pinver(1) pinver(2); pinver(4) pinver(5)];           % linear part
b=[pinver(3);pinver(6)];                      % trans. colvec
c=[pinver(7) pinver(8)];                      % chirpiness rowvec
Y=(A*X+b*ones(1,4))./(ones(2,1)*(c*X+ones(1,4)));
mrange=Y(1,:);
nrange=Y(2,:);
Ml=min(mrange);
Mh=max(mrange);
Nl=min(nrange);
Nh=max(nrange);
if nargout > 0
  if nargout == 1
    Ml_outarglist=[Ml Nl Mh Nh];
  elseif nargout == 4
    Ml_outarglist = Ml;
  else%if
    error('boundingbox: must have 0, 1, or 4 output arguments')
  end%if
end%if
dis=sprintf('boundingbox:  Ml=%g, Nl=%g   Mh=%g, Nh=%g',Ml,Nl,Mh,Nh);
disp(dis)


