function tf = checkMeshWatertight(elements)
% Internal function to check whether input elements represent a watertight mesh.
% Strict 2nd order check is applied.
% 
% Copyright 2021-2023 The MathWorks, Inc.

tf = true;
if size(elements,2) == 3
    facets = [elements(:,1:2); elements(:,2:3); elements(:,3) elements(:,1)];
    ifacets = flip(facets,2);
    tf = ~any(~ismember(facets,ifacets,'rows'));
end
end
