function res = consistency(triangles)
% input: n x 3 array of triangles, represented as vertex-index triples
% output: false, if there are any edges whose reverse is missing, or which
% appear more than once.

res = true;

edges = [triangles(:, [1 2]); triangles(:, [2 3]); triangles(:, [3, 1])];
edges = sortrows(edges);
ue = unique(edges, 'rows');
if (size(ue, 1) ~= size(edges, 1))
    'duplicated edges'
    res = false;
    return
end
re = edges(:, [2 1]);
re = sortrows(re);
if (re ~= ue)
    'missing back-edges'
    res = false;
    return
end
return

    
