%
%  Abgel. Klasse für Rechteck-Objekte
%
classdef ShRect < ShLines
  properties (Access = private)
    lenX = 0;
    lenY = 0;
  end  % properties
    
  methods
    function obj = ShRect( varargin )
      obj@ShLines(0,0);
      obj.hnd = [];
      
      isCopyConstr = 0;
      posX = 0;
      posY = 0;
      % 1 Argument: Copy-Konstruktor
      if( nargin == 1 )
        obj1 = varargin{1}; 
        if( isa( obj1, 'ShRect' ) )
          isCopyConstr = 1;
        else     % Fehlerfall 
          obj = ShRect.empty;
          return;
        end
      % mindestens 2 Argumente: lenX, lenY    
      elseif( nargin >= 2 )
        len_X = varargin{1};
        len_Y = varargin{2};
        % und noch posX und posX
        if( nargin == 4 )
          posX = varargin{3};
          posY = varargin{4};  
        end
      end
  
      if( isCopyConstr )    % Fall Copy Konstruktor 
        setData( obj, obj1 );
      else
        obj.x = posX;
        obj.y = posY;
        obj.lenX = len_X;
        obj.lenY = len_Y;
      end
    end      
      
    function disp( obj )
      disp@Shape(obj);
      fprintf( 'Länge = %g, Breite = %g \n', obj.lenX, obj.lenY );
    end
  
    function draw( obj )      
      clear( obj );    % Methode von Shape: alte Grafik löschen 
      % Koordinaten   
      x1 = obj.x; 
      x2 = obj.x + obj.lenX; 
      y1 = obj.y; 
      y2 = obj.y + obj.lenY;
      % 5 Punkte für 4 Linien 
      x = [x1,x2,x2,x1,x1];
      y = [y1,y1,y2,y2,y1];
      % Plotten und MATLAB Handle merken 
      obj.hnd = plot( x,y );           
      % Lines-Eigenschaften setzen
      obj.setLnData();
    end
    
  end  % methods
  
  % private Funktionen
  methods ( Access = private )
    
    function setData( obj, obj1 )  
      obj.x = obj1.x;
      obj.y = obj1.y;
      obj.lenX = obj1.lenX;
      obj.lenY = obj1.lenY;
      setLnData( obj, obj1 );
    end
    
  end  
end