11-05-2014, 07:43 PM
I rewrote this function in wings_body to be more than 10% faster. Maybe 15% faster.
This is my rewrite. I didn't know module sofs ... but when I got familiar with it ... I decided
it was at very least overkill. It's cool ... but overkill and slower ... and for me ... hard to read.
I think the issue is simple ... someone was trying to handle a case with multiple coincident faces to
be potentially welded. AKAIK ... and can see ... that's not reasonable possibility. The coinicident faces to weld should ultimately be in tuples like [{Fa,Fb}] but right now are in list like [[Fa,Fb]]
This is my rewrite. I didn't know module sofs ... but when I got familiar with it ... I decided
it was at very least overkill. It's cool ... but overkill and slower ... and for me ... hard to read.
I think the issue is simple ... someone was trying to handle a case with multiple coincident faces to
be potentially welded. AKAIK ... and can see ... that's not reasonable possibility. The coinicident faces to weld should ultimately be in tuples like [{Fa,Fb}] but right now are in list like [[Fa,Fb]]
Code:
weld_1(Tol, #we{id=Id,fs=Fs0}=We0, {Sel,Status0}) ->
Fs = qualified_fs(gb_trees:keys(Fs0), Tol, We0, []),
%% Don't use sofs module ... that's WAY OVERKILL and slower.
%% Not to mention ... harder to read
MyAcc = fun({Center,F}, Acc) ->
case gb_trees:is_defined(Center,Acc) of
true ->
Val = gb_trees:get(Center,Acc),
gb_trees:enter(Center, lists:append(Val,[F]), Acc);
false -> gb_trees:enter(Center,[F],Acc)
end
end,
Tree = lists:foldl(MyAcc, gb_trees:empty(), Fs),
Part = gb_trees:values(Tree),
case weld_part(Part, Tol, We0, Status0) of
{We0,Status} ->
{We0,{[{Id,gb_sets:singleton(0)}],Status}}; % Nothing to weld or done
{We,Status} ->
{We,{[{Id,weld_selection(lists:append(Part), We0, We)}|Sel],Status}}
end.