function [new,theType] = combine2ldb(ldb1,ldb2,point1,point2)
%COMBINE2LDB  combine two ldbs for the given points that coincide.
%
%   More detailed description goes here.
%
%   Syntax:
%   [new,theType] = combine2ldb(ldb1,ldb2,point1,point2)
%
%   Input:
%   ldb1,ldb2     = the two ldb's to combine
%   point1,point2 = the points of the ldb's that coincide
%
%   Output:
%   new           = the newly, combined, created ldb
%   theType       = the type of combining used
%
%   Example
%   combineldb
%
%   See also 

%% Copyright notice
%   --------------------------------------------------------------------
%   Copyright (C) 2010 Deltares
%       Lou Verhage
%
%       lou.verhage@deltares.nl	
%
%       Deltares
%       P.O. Box 177
%       2600MH Delft
%       Tel: +31 (0)88 335  8273
%       
%       Visiting adress:
%       Rotterdamseweg 185
%       2629 HD Delft
%       Tel: +31 (0)88 335  8276
%
%   This library is free software: you can redistribute it and/or
%   modify it under the terms of the GNU Lesser General Public
%   License as published by the Free Software Foundation, either
%   version 2.1 of the License, or (at your option) any later version.
%
%   This library is distributed in the hope that it will be useful,
%   but WITHOUT ANY WARRANTY; without even the implied warranty of
%   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
%   Lesser General Public License for more details.
%
%   You should have received a copy of the GNU Lesser General Public
%   License along with this library. If not, see <http://www.gnu.org/licenses/>.
%   --------------------------------------------------------------------

% This tool is part of <a href="http://OpenEarth.nl">OpenEarthTools</a>.
% OpenEarthTools is an online collaboration to share and manage data and 
% programming tools in an open source, version controlled environment.
% Sign up to recieve regular updates of this function, and to contribute 
% your own tools.

%% Version <http://svnbook.red-bean.com/en/1.5/svn.advanced.props.special.keywords.html>
% Created: 20 Dec 2010
% Created with Matlab version: 7.8.0.347 (R2009a)

% $Id$
% $Date$
% $Author$
% $Revision$
% $HeadURL$
% $Keywords: $

%%

[delen1,ip11,ip12] = getParts(length(ldb1.x),point1);
[delen2,ip21,ip22] = getParts(length(ldb2.x),point2);
theType = [];

if delen1 == 2 && delen2 == 1 %situatie A
    theType = 'A';
    new.x = ldb1.x(1:ip11-1);
    new.y = ldb1.y(1:ip11-1);

    if ip22 < length(ldb2.x)
        new.x = [new.x;ldb2.x(ip21-1:ip22+1)];
        new.y = [new.y;ldb2.y(ip21-1:ip22+1)];
    else
        new.x = [new.x;ldb2.x(ip21-1:ip22);ldb2.x(1)];
        new.y = [new.y;ldb2.y(ip21-1:ip22);ldb2.y(1)];
    end

    new.x = [new.x;ldb1.x(ip12+1:length(ldb1.x));new.x(1)];
    new.y = [new.y;ldb1.y(ip12+1:length(ldb1.x));new.y(1)];
elseif delen1 == 2 && delen2 == 2 % situatie B
    theType = 'B';
    new.x = ldb1.x(1:ip11-1);
    new.y = ldb1.y(1:ip11-1);

    new.x = [new.x;ldb2.x(ip22:length(ldb2.x));ldb2.x(1:ip21)];
    new.y = [new.y;ldb2.y(ip22:length(ldb2.y));ldb2.y(1:ip21)];

    new.x = [new.x;ldb1.x(ip12+1:length(ldb1.x));ldb1.x(1)];
    new.y = [new.y;ldb1.y(ip12+1:length(ldb1.y));ldb1.y(1)];
elseif delen1 == 1 && delen2 == 1 % situatie C
    theType = 'C';
    new.x = ldb1.x(ip11:ip12);
    new.y = ldb1.y(ip11:ip12);

    if ip22 < length(ldb2.x)
        new.x = [new.x;ldb2.x(ip21-1:ip22+1)];
        new.y = [new.y;ldb2.y(ip21-1:ip22+1)];
    else
        new.x = [new.x;ldb2.x(ip21-1:ip22);ldb2.x(1)];
        new.y = [new.y;ldb2.y(ip21-1:ip22);ldb2.y(1)];
    end

    new.x = [new.x;new.x(1)];
    new.y = [new.y;new.y(1)];
elseif delen1 == 1 && delen2 == 2 % situatie D
    theType = 'D';
    new.x = ldb1.x(ip11:ip12);
    new.y = ldb1.y(ip11:ip12);

    new.x = [new.x;ldb2.x(ip22:length(ldb2.x));ldb2.x(1:ip21)];
    new.y = [new.y;ldb2.y(ip22:length(ldb2.y));ldb2.y(1:ip21)];

    new.x = [new.x;new.x(1)];
    new.y = [new.y;new.y(1)];
end

