function [ C1,C2,D1,D2 ] = LiangBarsky2D( x1,y1,x2,y2,A1, A2, B1, B2 )
%  x1,y1 = first coordinate of line
%  x2,y2 = second coordinate of line   
%  A1,A2= left bottom coordinate of rectangle
%  B1,B2 = RIGHT top coordinate of rectangle

dx= x2-x1;
dy= y2-y1;
global tin;
tin=0;
global tout;
tout=1;
  first= CalcT(dx, B1-x1,tin,tout);
  second =  CalcT(-dx, x1-A1,tin,tout);
  third = CalcT(dy, B2-y1,tin,tout);
  fourth =  CalcT(-dy,y1-A2,tin,tout);


  if  first 
     if second 
      if third 
          if fourth
            if (tin == 0) C1=x1+tin*dx; C2=y1+tin*dy;
                     else C1=x1; C2=y1; end
        if (tout == 1) D1=x1+tout*dx; D2=y1+tout*dy;
                 else  D1=x2; D2=y2; end
              end          
        end
    end
  end
  
  
%%if(CalcT(dx, B1-x1,tin,tout))
 %    if(CalcT(-dx, x1-A1,tin,tout))
   %      if(CalcT(dY, B2-y1,tin,tout))
      %       if(CalcT(dx,y1-A2,tin,tout))
       %          if (tin > 0) A1=x1+tin*dx; A2=y1+tin*dx;
     %               else A1=x1; A2=y1; end
      %           if (tout< 1) B1=x1+tout*dx; B2=y1+tout*dx;
       %          else  B1=x2; B2=y2; end
     %         end          
    %     end
   %   end
  %  end

 
   end