% create line in matrix data matline(xyarea(x,y),x1,y1,x2,y2)
% copyright 2004 gerox(c) http://www.gerox.com
function xyarea = matline(xyarea,x1,y1,x2,y2)
x1=round(x1);
y1=round(y1);
x2=round(x2);
y2=round(y2);
for i=1:length(x1)
  xysize = size(xyarea);
  dx = abs(x2(i)-x1(i));
  dy = abs(y2(i)-y1(i));
  if(dx > dy) 
    if(x1(i) > x2(i))
     step =sign((y1(i) > y2(i))-0.5);
     s=x1(i);x1(i)=x2(i);x2(i)=s;y1(i)=y2(i);
    else 
      step = sign((y1(i) < y2(i)) -0.5);
    end
    if min(xysize >= [x1(i) y1(i)]) & min([x1(i) y1(i)])>0, xyarea(x1(i),y1(i)) = 1;end
    s = floor(dx / 2);
    while (x1(i) <= x2(i))
      x1(i) = x1(i) + 1;
      s = s - dy;
      if s < 0
        s = s + dx;
        y1 = y1 + step;
      end
      if min(xysize >= [x1(i) y1(i)]) & min([x1(i) y1(i)])>0, xyarea(x1(i),y1(i)) = 1;end
    end
  else 
    if(y1(i) > y2(i)) 
      step =sign((x1(i) > x2(i))-0.5);
      s=y1(i);y1(i)=y2(i);y2(i)=s;x1(i)=x2(i);
    else 
      step = sign((x1(i)<x2(i))-0.5);
    end
    if min(xysize >= [x1(i) y1(i)]) & min([x1(i) y1(i)])>0, xyarea(x1(i),y1(i)) = 1;end
    s = floor(dy / 2);
    while (y1(i) <= y2(i))
      y1(i) = y1(i) + 1;
      s = s - dx;
      if s < 0
        s = s + dy;
        x1(i) = x1(i) + step;
      end
      if min(xysize >= [x1(i) y1(i)]) & min([x1(i) y1(i)])>0, xyarea(x1(i),y1(i)) = 1;end
    end
  end
end
