%MXCURVEC_LINEAR_TEST simple test for mxcurvec
%
% determine 3 arrows in a strictly horizontal flow field
% determines by a 3x3 velociry matrix
%
%See also: mxcurvec, mxcurvec_circle_test

%% define scenario

    uabs = 1; % [m/s]
    
    X = [-1  0 +1;-1  0 +1;-1  0 +1].*1e5';% [m]
    Y = [-1 -1 -1; 0  0  0;+1 +1 +1].*1e5';% [m]
    U = [ 1  1  1; 1  1  1; 1  1  1].*uabs;% [m/s]
    V = [ 0  0  0; 0  0  0; 0  0  0];      % [m/s]
    
    OPT.dt               = 1e5; % [s], distance = dt * uabs: L = 1m/s.*1e5s= 1e5m
    OPT.nrvertices       = 10;
    OPT.headthickness    = 0.15;
    OPT.arrowthickness   = 0.05;
    OPT.nhead            = 2;
    OPT.iopt             = 0;
    
    x0     = [ 1 1 1].*-5e4; % [m] this needs to be passed as a [n x 1] array, so we pass it as x0(:)
    y0     = [-5 0 5].* 1e4; % [m]
    relwdt = [ 1 1 1].*1;
    
%% plot scenario

    pcolorcorcen(X,Y,U);
    colorbarwithtitle('U m/s')
    hold on
    quiver(X,Y,U,V,'k')
    plot(x0,y0,'r*')
    plot(x0+OPT.dt.*uabs,y0,'r>')
    
%% call mxcurvec

    [xar,yar,xax,yax,len] = mxcurvec(x0(:),y0,... % should be [n x 1], so use x(:), and can not have length==1
                                 X,Y,U,V,U,V,...  % does not have to be [n x 1]
                                 OPT.dt,...
                                 OPT.nrvertices,...
                                 OPT.headthickness,...
                                 OPT.arrowthickness,...
                                 OPT.nhead,...
                                 relwdt,...       % does not have to be [n x 1]
                                 0);

%% curvec.m code:

%% Set 999.999 arrow separators to nan values
    
    xar(xar<1000.0 & xar>999.998)=NaN;
    yar(yar<1000.0 & yar>999.998)=NaN;
    xax(xax<1000.0 & xax>999.998)=NaN;
    yax(yax<1000.0 & yax>999.998)=NaN;
    
%% Count number of points per arrow
    
    ic=1;while ~isnan(xar(ic,1));ic=ic+1;end % NOT: ic =  (OPT.nrvertices - OPT.nhead)*2+5 due to nhead cut-off in mxcurvec

%% Put all arrows in 2D matrix
    
    polx=reshape(xar,[ic               length(x0)]);
    poly=reshape(yar,[ic               length(x0)]);
    xax =reshape(xax,[OPT.nrvertices+1 length(x0)]);
    yax =reshape(yax,[OPT.nrvertices+1 length(x0)]);

%% add mxcurvec result
    
    plot(xar,yar)