function pt = generateRectanglePoints(c,length,width,n,distribution,varargin)
%RECTANGLE Create a rectangle centered about an orthogonal plane
%   P = RECTANGLE(CENTER,LENGTH,WIDTH), creates a rectangle with corners at
%   location coordinates P, with sides measuring LENGTH,and WIDTH. The
%   rectangle is created on the X-Y plane along the Z-axis.
%
%   % Examples
%
%   % Example 1:
%   % Create a rectangular strip  with length of 1m and
%   % width of 0.1 m.
%
%   p = antenna.generateRectanglePoints([0,0],1,0.1,1);

%   Copyright 2013-2022 The MathWorks, Inc.

nameOfFunction = 'generateRectanglePoints';
validateattributes(c,{'numeric'},{'nonempty','vector',      ...
                                  'nonnan','finite','real','numel',2},   ...
                                   nameOfFunction,'Center',1);
                               
validateattributes(length,{'numeric'},{'nonempty','scalar',      ...
                                  'nonnan','finite','real','positive'},   ...
                                   nameOfFunction,'length',2);
                               
validateattributes(width,{'numeric'},{'nonempty','scalar',      ...
                                  'nonnan','finite','real','positive'},   ...
                                   nameOfFunction,'width',3); 
                               
if isscalar(n)
    validateattributes(n,{'numeric'},{'nonempty', 'nonnan',     ...
        'finite','real','integer','positive'},   ...
        nameOfFunction,'NumPoints',4);

else
    validateattributes(n,{'numeric'},{'nonempty', 'nonnan',     ...
        'finite','real','integer','positive','numel',4},   ...
        nameOfFunction,'NumPoints');
end
if n ==1
    n = 2;
end
if numel(n)==4
    if~(n(1)==n(3))||~(n(2)==n(4))
        error(message('antenna:antennaerrors:InvalidNumPoints'));
    end
end

if nargin==3
    pt      = em.internal.makerectangle(length,width);
elseif nargin==4
    pt      = em.internal.makeplate(length,width,n,'linear');
elseif nargin==5
    pt      = em.internal.makeplate(length,width,n,distribution);
else
    pt      = em.internal.makeplate(length,width,n,distribution,varargin{:});
end
% Center appropriately
pt(1,:) = pt(1,:) + c(1);
pt(2,:) = pt(2,:) + c(2);
end
