Skip to content

Commit

Permalink
Fix matching 0.0 in plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
dgud committed Sep 24, 2024
1 parent a8c811a commit 453a21f
Show file tree
Hide file tree
Showing 36 changed files with 184 additions and 183 deletions.
2 changes: 1 addition & 1 deletion plugins_src/autouv/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ TARGET_FILES= $(MODULES:%=$(EBIN)/%.beam)
# ----------------------------------------------------
# FLAGS
# ----------------------------------------------------
ERL_COMPILE_FLAGS += +nowarn_match_float_zero -Werror -pa $(WINGS_INTL) -I $(WINGS_TOP) $(TYPE_FLAGS) +debug_info
ERL_COMPILE_FLAGS += -Werror -pa $(WINGS_INTL) -I $(WINGS_TOP) $(TYPE_FLAGS) +debug_info

# ----------------------------------------------------
# Targets
Expand Down
16 changes: 8 additions & 8 deletions plugins_src/autouv/auv_mapping.erl
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ split_pinned([], _, Indx, PosL) ->
{reverse(Indx), reverse(PosL)}.

scaleVs(VUVs,Scale) ->
[{Id, {X*Scale,Y*Scale,0.0}} || {Id,{X,Y,0.0}} <- VUVs].
[{Id, {X*Scale,Y*Scale,0.0}} || {Id,{X,Y,_}} <- VUVs].

find_pinned({Circumference, BorderEdges}, We) ->
Vs = [array:get(V1, We#we.vp) || #be{vs=V1} <- BorderEdges],
Expand Down Expand Up @@ -489,7 +489,7 @@ chart_normal(Fs,We = #we{es=Etab}) ->
CalcNormal = fun(Face,Area) -> face_normal(Face,Area,We) end,
N0 = foldl(CalcNormal, e3d_vec:zero(), Fs),
case e3d_vec:norm(N0) of
{0.0,0.0,0.0} -> %% Bad normal Fallback1
{+0.0,+0.0,+0.0} -> %% Bad normal Fallback1
%% BE = auv_util:outer_edges(Fs,We,false),
[{_,BE}|_] = auv_placement:group_edge_loops(Fs,We),
EdgeNormals =
Expand All @@ -500,7 +500,7 @@ chart_normal(Fs,We = #we{es=Etab}) ->
end,
N1 = foldl(EdgeNormals, e3d_vec:zero(), BE),
case e3d_vec:norm(N1) of
{0.0,0.0,0.0} -> %% Bad normal Fallback2
{+0.0,+0.0,+0.0} -> %% Bad normal Fallback2
NewFs = decrease_chart(Fs,BE),
chart_normal(NewFs, We);
N -> e3d_vec:neg(N)
Expand Down Expand Up @@ -603,11 +603,11 @@ lsq_init_fs([F|Fs],P,We = #we{vp=Vtab},Ds0,N,Re0,Im0) ->
array:get(C0,Vtab)),
%% Raimos old solution.
SqrtDT0 = try math:sqrt(abs((X2-X1)*(Y3-Y1)-(Y2-Y1)*(X3-X1)))
catch _:_ -> 0.000001
end,
SqrtDT = if SqrtDT0 =:= 0.0 -> 1.0; % this can happen e.g. in a bevel/extrude without offset
true -> SqrtDT0
end,
catch _:_ -> 0.000001
end,
SqrtDT = if SqrtDT0 < ?EPSILON -> 1.0; % this can happen e.g. in a bevel/extrude without offset
true -> SqrtDT0
end,
W1re = X3-X2, W1im = Y3-Y2,
W2re = X1-X3, W2im = Y1-Y3,
W3re = X2-X1, W3im = Y2-Y1,
Expand Down
6 changes: 3 additions & 3 deletions plugins_src/autouv/auv_matrix.erl
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ reduce_sort([Row | A], C) ->

reduce_presort(Z, []) ->
{Z, infinity, []};
reduce_presort(Z, [0.0 | Row]) ->
reduce_presort(Z, [+0.0 | Row]) ->
reduce_presort(Z+1, Row);
reduce_presort(Z, [V | _] = Row) when is_float(V) ->
{Z, 1.0/abs(V), Row};
Expand Down Expand Up @@ -518,7 +518,7 @@ backsubst_rev_z(Z, Za, _, _, _) when Za > Z ->
{error, not_reduced};
backsubst_rev_z(_, _, [_], _, _) ->
{error, not_reduced};
backsubst_rev_z(Z, Za, [0.0 | RowA], A, C) ->
backsubst_rev_z(Z, Za, [+0.0 | RowA], A, C) ->
backsubst_rev_z(Z, Za+1, RowA, A, C);
backsubst_rev_z(Z, Za, [Va | _] = RowA, A, C) when is_float(Va) ->
if Z == Za ->
Expand Down Expand Up @@ -692,7 +692,7 @@ vec_sq([_ | A], S) ->


%% Push value; zeros or float
push_v(0.0, C) ->
push_v(+0.0, C) ->
case C of
[Z | R] when is_integer(Z) ->
[Z+1 | R];
Expand Down
4 changes: 2 additions & 2 deletions plugins_src/autouv/auv_texture.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1277,7 +1277,7 @@ build_tangents([], _, Bin) -> Bin.

add_tangents1([V|Vs], Ts, H0, N, Prev, Bin0) ->
case array:get(V, Ts) of
{{0.0, 0.0, 0.0}, BiT} ->
{{+0.0, +0.0, +0.0}, BiT} ->
{Tan = {X,Y,Z}, H} = get_tangent(Prev, BiT, H0, N),
Bin = <<Bin0/binary, X:?F32,Y:?F32,Z:?F32, H:?F32>>,
add_tangents1(Vs, Ts, H, N, Tan, Bin);
Expand All @@ -1294,7 +1294,7 @@ add_tangents1([V|Vs], Ts, H0, N, Prev, Bin0) ->
end;
add_tangents1([], _, _, _, _, Bin) -> Bin.

get_tangent(undefined, {0.0,0.0,0.0}, H0, N) ->
get_tangent(undefined, {+0.0,+0.0,+0.0}, H0, N) ->
H = if H0 =:= 0 -> -1; true -> H0 end,
{cross_axis(N), H};
get_tangent(undefined, BiT, 0, N) ->
Expand Down
40 changes: 20 additions & 20 deletions plugins_src/autouv/wpc_autouv.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1333,9 +1333,9 @@ make_proportional([Link0|R],We = #we{vp=Vtab1}, [LinkObj0|RObj], WeObj = #we{vp=
{Xd,Yd,_} = e3d_vec:sub(array:get(Ve,Vtab1),
array:get(Vs,Vtab1)),
ELen = e3d_vec:len({Xd,Yd,0.0}),
Dir = if (ELen =:= 0.0) -> none;
true -> e3d_vec:norm({Xd,Yd,0.0})
end,
Dir = if abs(ELen) < ?EPSILON -> none;
true -> e3d_vec:norm({Xd,Yd,0.0})
end,
{Len+ELen,[{E,Dir}|Acc]}
end,{0.0,[]},Link),
EsLen = validate_dir(EsLen0,[]),
Expand All @@ -1357,8 +1357,8 @@ make_proportional([Link0|R],We = #we{vp=Vtab1}, [LinkObj0|RObj], WeObj = #we{vp=
Vtab0 =
lists:foldr(fun({{E,Ve,Vs},Dir0}, Acc) ->
EObjLen = proplists:get_value(E,EsObjLen),
if LinkObjLen =/= 0.0 -> Prc = EObjLen/LinkObjLen;
true -> Prc = 1.0
if abs(LinkObjLen) > ?EPSILON -> Prc = EObjLen/LinkObjLen;
true -> Prc = 1.0
end,
ELen = Prc*LinkLen,
Dir = e3d_vec:mul(Dir0,ELen),
Expand All @@ -1377,25 +1377,25 @@ make_proportional([Link0|R],We = #we{vp=Vtab1}, [LinkObj0|RObj], WeObj = #we{vp=
D1 = e3d_vec:len(Vec1),

%% making the new loop arrangement fit in the old BB length and alignment
if D1 =/= 0.0 -> Scl = round((D0/D1)*100.0)/100.0;
true -> Scl = 1.0
if abs(D1) > ?EPSILON -> Scl = round((D0/D1)*100.0)/100.0;
true -> Scl = 1.0
end,
{_,_,RotSide} = e3d_vec:norm(e3d_vec:cross(Vec1,Vec0)),
Rot = round(e3d_vec:degrees(Vec1,Vec0)*10.0)/10.0*RotSide,
MToOri = e3d_mat:translate(e3d_vec:neg(Mid1)),
if (Rot=/=0.0) or (Scl=/=1.0) ->
%% preparing transform matrices
MRot = e3d_mat:rotate(Rot,wings_util:make_vector(z)),
MScl = e3d_mat:scale({Scl,Scl,1.0}),
MToDst = e3d_mat:translate(Mid0),
M2 = e3d_mat:mul(MScl,MToOri),
M1 = e3d_mat:mul(MRot,M2),
M0 = e3d_mat:mul(MToDst,M1);
true ->
MToDst = e3d_mat:translate(Mid0),
M0 = e3d_mat:mul(MToDst,MToOri)
if abs(Rot) > ?EPSILON orelse (Scl=/=1.0) ->
%% preparing transform matrices
MRot = e3d_mat:rotate(Rot,wings_util:make_vector(z)),
MScl = e3d_mat:scale({Scl,Scl,1.0}),
MToDst = e3d_mat:translate(Mid0),
M2 = e3d_mat:mul(MScl,MToOri),
M1 = e3d_mat:mul(MRot,M2),
M0 = e3d_mat:mul(MToDst,M1);
true ->
MToDst = e3d_mat:translate(Mid0),
M0 = e3d_mat:mul(MToDst,MToOri)
end,

Vtab =
lists:foldr(fun(V, Acc) ->
Pos = e3d_mat:mul_point(M0,array:get(V,Acc)),
Expand Down Expand Up @@ -1647,7 +1647,7 @@ displace_charts([{_,{Id1,_,_},{Id2,_,_}}|Eds], Moved, Sh) ->
C2 = wings_vertex:center(gb_trees:get(Id2,Sh)),
Disp0 = e3d_vec:mul(e3d_vec:norm(e3d_vec:sub(C1,C2)),?EPSILON),
Move = case Disp0 of
{0.0,0.0,0.0} -> {0.0,?EPSILON,0.0};
{+0.0,+0.0,_} -> {0.0,?EPSILON,0.0};
Disp -> Disp
end,
Vpos= [{V,e3d_vec:add(Pos,Move)} ||
Expand Down
2 changes: 1 addition & 1 deletion plugins_src/commands/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ TARGET_FILES= $(MODULES:%=$(EBIN)/%.beam)
# ----------------------------------------------------
# FLAGS
# ----------------------------------------------------
ERL_COMPILE_FLAGS += -pa $(WINGS_INTL) +nowarn_match_float_zero -Werror -I $(WINGS_TOP) $(TYPE_FLAGS) +debug_info
ERL_COMPILE_FLAGS += -pa $(WINGS_INTL) -Werror -I $(WINGS_TOP) $(TYPE_FLAGS) +debug_info

# ----------------------------------------------------
# Targets
Expand Down
2 changes: 1 addition & 1 deletion plugins_src/commands/wpc_absolute_scale.erl
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ getSuggestedCenter([{AX1,AY1,AZ1},{AX2,AY2,AZ2}],
getC(AY1,AY2,BY1,BY2),
getC(AZ1,AZ2,BZ1,BZ2)}.

getC(A1, A2, B1, B2) when A1 =/= A2, B1 =/= B2, ((A1 - A2)-(B1 - B2))=/=0.0 ->
getC(A1, A2, B1, B2) when A1 =/= A2, B1 =/= B2, abs((A1 - A2)-(B1 - B2)) > ?EPSILON ->
(B1*A2-B2*A1)/((A2-A1) - (B2-B1));
getC(A1, A2, _, _) -> (A1+A2)/2.

Expand Down
6 changes: 3 additions & 3 deletions plugins_src/commands/wpc_align_to_axis.erl
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,9 @@ trunc_axis(x, {_,Y,Z}) -> {0.0,Y,Z};
trunc_axis(y, {X,_,Z}) -> {X,0.0,Z};
trunc_axis(z, {X,Y,_}) -> {X,Y,0.0}.

translate_axis(x, {0.0,_Y,_Z}) -> {-1.0,0.0,0.0};
translate_axis(x, {+0.0,_Y,_Z}) -> {-1.0,0.0,0.0};
translate_axis(x, {X,_Y,_Z}) -> {-1.0*(X/abs(X)),0.0,0.0};
translate_axis(y, {_X,0.0,_Z}) -> {0.0,1.0,0.0};
translate_axis(y, {_X,+0.0,_Z}) -> {0.0,1.0,0.0};
translate_axis(y, {_X,Y,_Z}) -> {0.0,Y/abs(Y),0.0};
translate_axis(z, {_X,_Y,0.0}) -> {0.0,0.0,1.0};
translate_axis(z, {_X,_Y,+0.0}) -> {0.0,0.0,1.0};
translate_axis(z, {_X,_Y,Z}) -> {0.0,0.0,Z/abs(Z)}.
4 changes: 2 additions & 2 deletions plugins_src/commands/wpc_arc_intersect.erl
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,10 @@ arc_intersect_fun(Axis,Center,Deg,VsInf0,{_,R}=Magnet0,State0) ->
end.


arc_intersect(_Axis,_Center,_Deg,Vpos,_State,0.0) ->
arc_intersect(_Axis,_Center,_Deg,Vpos,_State, +0.0) ->
Vpos;

arc_intersect(Axis,Center,Deg,Vpos,_State,Percent) when Deg =:= 0.0; Deg =:= 180.0 ->
arc_intersect(Axis,Center,Deg,Vpos,_State,Percent) when Deg =:= +0.0; Deg =:= 180.0 ->
Rotate = 180.0 * Percent,
rotate(Vpos,Axis,Center,Rotate);

Expand Down
6 changes: 3 additions & 3 deletions plugins_src/commands/wpc_bend.erl
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ bend_setup_clamps(#bend_data{rodCenter=RC, rodNormal=RN}=BD,

bend_verts(BendData, St) ->
case BendData#bend_data.rodLength of
0.0 ->
+0.0 ->
wpa:error_msg(?__(1,"Configuration does not result in bending"));
_ ->
%% FIXME
Expand Down Expand Up @@ -288,9 +288,9 @@ bend_verts(BendData, Vs0, We) ->
%% The return value is the new position. {X,Y,Z}
%%

bend_vertex(Pos, _, #bend_data{rodLength = 0.0}) ->
bend_vertex(Pos, _, #bend_data{rodLength = +0.0}) ->
Pos;
bend_vertex(Pos, 0.0, #bend_data{dragMode = fixed_length}) ->
bend_vertex(Pos, +0.0, #bend_data{dragMode = fixed_length}) ->
Pos;
bend_vertex(Pos, Angle, #bend_data{dragMode = DragMode,
rodCenter = RC,
Expand Down
12 changes: 6 additions & 6 deletions plugins_src/commands/wpc_circularise.erl
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ get_radius([], Center, _, _, RayLen0, NearestVert, Pos, LastPos, FirstPos, AtInd
false -> {Pos, math:sqrt(NearestVert), Index}
end;

get_radius([Vert|Vs], Center, Plane, Vtab, 0.0, 0.0, _Pos, _LastPos, _FirstPos, AtIndex, _Index) ->
get_radius([Vert|Vs], Center, Plane, Vtab, +0.0, +0.0, _Pos, _LastPos, _FirstPos, AtIndex, _Index) ->
Pos = array:get(Vert, Vtab),
RayPos = intersect_vec_plane(Pos, Center, Plane),
Dist = len_sqrt(e3d_vec:sub(RayPos, Center)),
Expand Down Expand Up @@ -713,9 +713,9 @@ make_circular_fun(Data, State) ->
end.

%%%% Arc Main Functions
arc(Vpos, _Index, _Data, _State, 0.0, 0.0) -> Vpos;
arc(Vpos, _Index, _Data, _State, +0.0, +0.0) -> Vpos;
arc(Vpos, Index, {CwNorm, _, Opp, Plane0, Pos, Hinge, NumVs},
{Flatten,Orientation,_}, Percent, 0.0) ->
{Flatten,Orientation,_}, Percent, +0.0) ->
Segment = (Opp * 2) / NumVs,
ChordNorm = e3d_vec:norm(e3d_vec:sub(Hinge, Pos)),
Plane = reverse_norm(CwNorm,Plane0,Orientation),
Expand Down Expand Up @@ -764,7 +764,7 @@ arc(Vpos, Index, {CwNorm, Cross0, Opp, Plane0, Pos, Hinge, NumVs},
% %
% % % % % % % % % % % % % % % % % %

arc_center(Vpos, _, _, _, _, _, _, _, 0.0) -> Vpos;
arc_center(Vpos, _, _, _, _, _, _, _, +0.0) -> Vpos;
arc_center(Vpos, Angle, Index, NumVs, Pos, Center, Plane, {Flatten,AxisMode,AngleMode}, Percent) ->
DegIncrement = acute_obtuse(AngleMode, Angle, NumVs),
RotationAmount = rotation_amount(AxisMode, DegIncrement, Index),
Expand All @@ -782,7 +782,7 @@ rotation_amount(reverse, Deg, Index) -> -Deg * Index.
%%%% Closed Loop. Calculate the final position of each vertex (NewPos).
%%%% Measure the distance between NewPos and the Center (Factor). Move the
%%%% vertex towards the NewPos by a distance of the drag Dist * Factor.
make_circular(_Center, _Ray, _Nearest, _Axis, _Deg, Vpos, _State, 0.0, 0.0) -> Vpos;
make_circular(_Center, _Ray, _Nearest, _Axis, _Deg, Vpos, _State, +0.0, +0.0) -> Vpos;
make_circular(Center, Ray, Nearest, Plane, Deg, Vpos, {Flatten,_,Mode}, Percent, Dia) ->
Pos0 = static_pos(Mode, Center, Ray, Nearest, Dia),
Pos1 = rotate(Pos0, Plane, Center, Deg),
Expand Down Expand Up @@ -822,7 +822,7 @@ intersect_vec_plane(PosA, PosB, PlaneNorm) ->
Intersection = e3d_vec:dot(e3d_vec:sub(PosB, PosA), PlaneNorm),
e3d_vec:add(PosA, e3d_vec:mul(PlaneNorm, Intersection)).

reverse_norm({0.0,0.0,0.0}, Norm, reverse) -> e3d_vec:neg(Norm);
reverse_norm({+0.0,+0.0,+0.0}, Norm, reverse) -> e3d_vec:neg(Norm);
reverse_norm(_, Norm, _) -> Norm.

%%%% Selection errors
Expand Down
12 changes: 6 additions & 6 deletions plugins_src/commands/wpc_constraints.erl
Original file line number Diff line number Diff line change
Expand Up @@ -515,9 +515,9 @@ check_selection(sub_angle,none,none,#st{sel=[{_Id0,Sel0},{_Id1,Sel1}]}=St,OrigSt
OrigA = measure_angle(normal,OrigSt),
Angle = measure_angle(normal,St),
A0 = abs(Angle - OrigA),
A1 = case A0 of
0.0 -> 180.0;
_ -> A0
A1 = case A0 < ?EPSILON of
true -> 180.0;
false -> A0
end,
Str = [?__(11," Original Angle ~s"),?DEGREE,?__(12,"\n Current Angle ~s"),
?DEGREE,?__(13,"\n Difference ~s"),?DEGREE],
Expand All @@ -534,9 +534,9 @@ check_selection(sub_angle,none,none,#st{sel=[{_Id,Sel}]}=St,OrigSt) ->
OrigA = wings_util:nice_float(Angle),
CurrA = wings_util:nice_float(CAngle),
A0 = abs(Angle - CAngle),
A1 = case A0 of
0.0 -> 180.0;
_ -> A0
A1 = case A0 < ?EPSILON of
true -> 180.0;
false -> A0
end,
A2 = wings_util:nice_float(A1),
Str1 = [wings_util:format(?__(16," Angle ~s"),[OrigA]),?DEGREE],
Expand Down
2 changes: 1 addition & 1 deletion plugins_src/commands/wpc_corner.erl
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ corner_error() ->

corner_tension_fun(VD) ->
fun
([0.0], A) ->
([+0.0], A) ->
lists:foldl(fun
({V,Vpos,_Rad,_Vec}, VsAcc) ->
[{V,Vpos}|VsAcc];
Expand Down
18 changes: 9 additions & 9 deletions plugins_src/commands/wpc_flow_connect.erl
Original file line number Diff line number Diff line change
Expand Up @@ -266,22 +266,22 @@ get_result(Deg, Len, false) ->

opposite(Deg, Adjacent, Divider) ->
D0 = (180 - Deg)/Divider,
case D0 of
0.0 -> 0.0;
_ ->
case abs(D0) < ?EPSILON of
true -> 0.0;
false ->
Radians = math:pi()/(180/D0),
Adjacent * math:tan(Radians)
end.

intersect_vec_plane(PosA, PosB, Plane, Vec) ->
%% Return point where Vec through PosA intersects with Plane at PosB
case e3d_vec:dot(Vec,Plane) of
0.0 ->
Intersection = e3d_vec:dot(e3d_vec:sub(PosB, PosA), Plane),
e3d_vec:add(PosB, e3d_vec:mul(Plane, Intersection));
Dot ->
Intersection = e3d_vec:dot(e3d_vec:sub(PosB, PosA), Plane) / Dot,
e3d_vec:add(PosA, e3d_vec:mul(Vec, Intersection))
Dot when abs(Dot) < ?EPSILON ->
Intersection = e3d_vec:dot(e3d_vec:sub(PosB, PosA), Plane),
e3d_vec:add(PosB, e3d_vec:mul(Plane, Intersection));
Dot ->
Intersection = e3d_vec:dot(e3d_vec:sub(PosB, PosA), Plane) / Dot,
e3d_vec:add(PosA, e3d_vec:mul(Vec, Intersection))
end.

%% Drag option cut
Expand Down
4 changes: 2 additions & 2 deletions plugins_src/commands/wpc_greebles.erl
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,11 @@ inset(Fs, InsetP, BumpP, State, #we{vp=Vp0}=We) ->
end, Vp0, FacesData),
We#we{vp=Vp}.

inset_faces(_,{Vpos,_},0.0) -> Vpos;
inset_faces(_,{Vpos,_},+0.0) -> Vpos;
inset_faces(SFDist,{Vpos,Dir},Percent) ->
e3d_vec:add(Vpos, e3d_vec:mul(Dir, SFDist * Percent)).

bump(Vpos,_,0.0) -> Vpos;
bump(Vpos,_,+0.0) -> Vpos;
bump(Vpos,FNorm,Bump)->
e3d_vec:add(Vpos, e3d_vec:mul(FNorm,Bump)).

Expand Down
Loading

0 comments on commit 453a21f

Please sign in to comment.