function [  ] = LiangBarsky2D2( 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;

%dx=x1-x2;
%dy=y1-y2;
global lineColor2
p=[-dx,dx,-dy,dy];
q=[x1-A1,B1-x1,y1-A2,B2-y1];


flag=1;
for i = 1:1:4
    if  ( p(i)== 0  &&  q(i) < 0 )
          flag=0; 
    end;
end;

 t0=0;
 t1=1;

values=[q(1)/p(1), q(2)/p(2), q(3)/p(3),q(4)/p(4)];

for i = 1:1:4
     if ( p(i)<0 )   
          if ( values(i) > t1 )  flag=0; 
          else if( values(i) > t0 )  t0=values(i);
              end;
          end;
      
     else if (p(i)>0) 
             if (values(i)  < t0)  flag=0;  
             else if (values(i) < t1) t1=values(i);
                 end
             end
         end
     end
end;

 if (flag == 1)
     
   C1=floor(x1+t0*dx);
 
   C2=floor(y1+t0*dy);
  
   D1=floor(x1+t1*dx);
     
   D2=floor(y1+t1*dy);
 
   
   DrawLine(C1,C2,D1,D2,lineColor2);
 end
 
end

  
