function isConfinedVector = isConfinedDec(hcMatrix, dec, zerotol)
% determine confinement for a matrix of hC-vectors
%
% Syntax: isValidVecor = isValidDec(hcMatrix, dec)
%
% See also: obtainDec, isValidDec, mapToConfinementCone

% The elk-library: convex geometry applied to crystallization modeling.
%   Copyright (C) 2014 Alexander Reinhold
%
% This program is free software: you can redistribute it and/or modify it 
%   under the terms of the GNU General Public License as published by the 
%   Free Software Foundation, either version 3 of the License, or (at your 
%   option) any later version.
%
% This program 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 
%   General Public License for more details.
%
% You should have received a copy of the GNU General Public License along 
%   with this program.  If not, see <http://www.gnu.org/licenses/>.

%% input handling
% ensure zerotol exists
if ~exist('zerotol', 'var')
    zerotol = elkZerotol;
end

% ensure hcMatrix has proper size
if size(hcMatrix, 1) == dec.nC
    % everything OK
elseif size(hcMatrix, 2) == dec.nC
    hcMatrix = hcMatrix';
else
    error('elk:decomposition:wrongInput', ['hcMatrix must be a matrix '...
        ' of column hC-vectors']);
end

%% Operation
if dec.isOrdinary
    isConfinedVector = all(dec.confinementCone.A * hcMatrix < zerotol, 1);
else
    isConfinedVector = false(1, size(hcMatrix, 2));
    for iPart = 1:dec.nPU
        thisFilter = all(dec.unifiedPartition{iPart}.A * hcMatrix < zerotol, 1);
        isConfinedVector(thisFilter) = true;
    end
end