function [x,y] = rect(bs,s)
%
% *** NOTE!!! - be sure to change the coordinates of the corners of the
% *** rectangle to the values you want...
%
%
%   NE=SQUAREG gives the number of boundary segment
%
%   D=SQUAREG(BS) gives a matrix with one column for each boundary segment
%   specified in BS.
%   Row 1 contains the start parameter value.
%   Row 2 contains the end parameter value.
%   Row 3 contains the number of the left hand region.
%   Row 4 contains the number of the right hand region.
%
%   [X,Y]=resg(BS,S) gives coordinates of boundary points. BS specifies the
%   boundary segments and S the corresponding parameter values. BS may be
%   a scalar.
% Copyright (c) 1994-98 by The MathWorks, Inc.
% $Revision: 1.7 $


% You will need to change these values to be the coordinates of
% the corners of the rectangle you wish to model:
% lower left is (x1,y1), upper right is (x2,y2)
X1 = 0;
X2 = 1;
Y1 = 0;
Y2 = 1;



nbs=4;

if nargin==0,
  x=nbs; % number of boundary segments
  return
end

d=[
  0 0 0 0 % start parameter value
  1 1 1 1 % end parameter value
  0 0 0 0 % left hand region
  1 1 1 1 % right hand region
];

bs1=bs(:)';

if find(bs1<1 | bs1>nbs),
  error('Non existent boundary segment number')
end

if nargin==1,
  x=d(:,bs1);
  return
end

x=zeros(size(s));
y=zeros(size(s));
[m,n]=size(bs);
if m==1 & n==1,
  bs=bs*ones(size(s)); % expand bs
elseif m~=size(s,1) | n~=size(s,2),
  error('bs must be scalar or of same size as s');
end

if ~isempty(s),

% boundary segment 1
ii=find(bs==1);
if length(ii)
x(ii)=interp1([d(1,1),d(2,1)],[X1 X2],s(ii));
y(ii)=interp1([d(1,1),d(2,1)],[Y2 Y2],s(ii));
end

% boundary segment 2
ii=find(bs==2);
if length(ii)
x(ii)=interp1([d(1,2),d(2,2)],[X2 X2],s(ii));
y(ii)=interp1([d(1,2),d(2,2)],[Y2 Y1],s(ii));
end

% boundary segment 3
ii=find(bs==3);
if length(ii)
x(ii)=interp1([d(1,3),d(2,3)],[X2 X1],s(ii));
y(ii)=interp1([d(1,3),d(2,3)],[Y1 Y1],s(ii));
end

% boundary segment 4
ii=find(bs==4);
if length(ii)
x(ii)=interp1([d(1,4),d(2,4)],[X1 X1],s(ii));
y(ii)=interp1([d(1,4),d(2,4)],[Y1 Y2],s(ii));
end

end

