www.gusucode.com > mbcdesign 工具箱 matlab 源码程序 > mbcdesign/@conboolean/and.m

    function c = and( c, c2 )
%AND Logical AND of two constraints (intersection of two constraints)
%
%  C = AND(C1,C2) is the intersection of the constraints C1 and C2, i.e., a
%  point X is in AND(C1,C2) if and only if it is inside C1 and it is inside
%  C2.
%
%  C1 and C2 must be the same size (as returned by GETSIZE)
%
%  See also CONBASE/NOT, CONBASE/OR, CONBASE/OR, CONBOOLEAN, GETSIZE.

%  Copyright 2000-2005 The MathWorks, Inc. and Ford Global Technologies, Inc.


% check n input factors to constraints
if nFactors( c ) ~= nFactors( c2 ),
    error(message('mbc:conboolean:InvalidArgument'));
end

% To keep things simple, we want to ensure that
%    c is a conboolean
%    c2 is any conbase object
if ~isa( c, 'conboolean' ),
    [c2, c] = deal( c, c2 ); % swap c and c2
end

if isa( c2, 'conboolean' ),
    if strcmpi( c.Op, 'And' ) && strcmpi( c2.Op, 'And' ) && ~c.Not && ~c2.Not,
        % Both c and c2 are AND constraints so just concatenate the two sets of
        % constraints held by each
        c.Constraints = [ c.Constraints, c2.Constraints ];

    elseif strcmpi( c.Op, 'And' ) && ~c.Not,
        % Since c is already an AND constraint we can just add c2 to the list of
        % constraints held by c
        c.Constraints{end+1} = c2;

    elseif strcmpi( c2.Op, 'And' ) && ~c2.Not,
        % Since c2 is already an AND constraint we can just add c to the list of
        % constraints held by c2
        [c2, c] = deal( c, c2 ); % swap c and c2
        c.Constraints{end+1} = c2;
    else
        % We can't just expand one of the constraints so we need to add another
        % layer of CONBOOLEAN objects.
        c = conboolean( 'And', c, c2 );
    end
else
    if strcmpi( c.Op, 'And' ) && ~c.Not,
        % Since c is already an AND constraint we can just add c2 to the list of
        % constraints held by c
        c.Constraints{end+1} = c2;
    else
        % We can't just expand one of the constraints so we need to add another
        % layer of CONBOOLEAN objects.
        c = conboolean( 'And', c, c2 );
    end
end