Code:
%% Connect vertices (which must share a face).
connect(Vs, #we{}=We) when not(is_list(Vs)) ->
connect(gb_sets:to_list(Vs),We);
connect([], #we{}=We) -> We;
connect(Vs, #we{}=We) when is_list(Vs) ->
Fs = wings_face:from_vs(Vs, We),
connect(Fs,Vs,We).
%% connect verts on all faces as possible
connect([],_, #we{}=We) -> We;
connect([Fi|FsMore],Vs,#we{}=We) when is_list(Vs) ->
VsFace = wings_face:to_vertices([Fi],We),
case I = gb_sets:intersection(gb_sets:from_list(VsFace),gb_sets:from_list(Vs)) of
[_,_|_]=I ->
We2 = connect(Fi,I,We),
connect(FsMore,Vs,We2);
_ -> connect(FsMore,Vs,We)
end;
connect(_Face, [_], We) -> We;
connect(Face, Vs, #we{} = We0) ->
case polygon_pairs(Face, Vs, We0) of
no -> min_distance_pairs(Face, Vs, We0);
#we{} = We -> We
end.