function [newxdata,newydata]=adj_line(newx,newy)

% function [newxdata,newydata]=adj_line(newx,newy)
%
% This function is used in conjunction with FD3.  It is called when the user
% is manually creating horizontal/vertical streams by clicking on each
% stream corner.   After the [x, y] coordinate is adjusted so that the
% resulting line will be either perfectly horizontal or perfectly vertical,
% the 'newx' and 'newy' are fed to adj_line.  This program adds the 'newx' and
% 'newy' to FD3OBJECT's xdata and ydata.  If the new [x, y] coordinate lies
% on the same line as the previous [x, y] coordinate, the previous [x, y]
% coordinate is removed before the new one is added.  Adj_line returns the
% modified xdata, 'newxdata', and the modified ydata, 'newydata'.
%
% ACP

% Last update:  July 11, 1993
% Author:       Adrian C. Penisson

global FD3OBJECT

% Get object's currect xdata and ydata

oldxdata=get(FD3OBJECT,'Xdata');
oldydata=get(FD3OBJECT,'Ydata');
len=length(oldxdata);

% Determine if the new [x, y] coordinate lies on the same line as the previous
% coordinate.

logical1=newx==oldxdata(len-1);
logical2=newy==oldydata(len-1);

if logical1 | logical2

   % If so, remove the previous coordinate before adding the new one.

   newxdata=[oldxdata(1:len-1) newx];
   newydata=[oldydata(1:len-1) newy];

else

   % If not so, simply add the new coordinate.

   newxdata=[oldxdata newx];
   newydata=[oldydata newy];

end
