Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/pr/550'
Browse files Browse the repository at this point in the history
  • Loading branch information
dgud committed Jul 3, 2023
2 parents c6b3dd2 + 862d752 commit 3b97ff1
Show file tree
Hide file tree
Showing 15 changed files with 34 additions and 28 deletions.
4 changes: 4 additions & 0 deletions e3d/e3d.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
%% $Id$
%%

-ifndef(EPSILON).
-define(EPSILON, 1.0e-7).
-endif.

%% Types for e3d_bv
-define(E3D_INFINITY, 3.402823e+38). %% 32 bits float max
-type e3d_bbox() :: {e3d_vec:point(), e3d_vec:point()}.
Expand Down
4 changes: 2 additions & 2 deletions e3d/e3d__tri_quad.erl
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
-define(ANGFAC, 1.0).
-define(DEGFAC, 10.0).
-define(GTHRESH, 75).
-define(TOL, 0.0000001).
-define(TOL, ?EPSILON).

% Triangulate an entire mesh.
%% Triangulate an entire mesh.
triangulate(#e3d_mesh{type=triangle}=Mesh) -> Mesh;
triangulate(#e3d_mesh{type=polygon,fs=Fs0,vs=Vs}=Mesh) ->
Fs = triangulate(Fs0, list_to_tuple(Vs), []),
Expand Down
1 change: 0 additions & 1 deletion e3d/e3d_bvh.erl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
-define(I32, 32/signed-native).
-define(U32, 32/unsigned-native).

-define(EPSILON, 1.0e-7).
-define(IsLeaf(NodeData), ((NodeData) band 16#80000000) > 1).
-define(GetSkipIndex(NodeData), ((NodeData) band 16#7fffffff)).
-define(ENTRY_SZ, 8*4).
Expand Down
2 changes: 0 additions & 2 deletions e3d/e3d_mat.erl
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@

-spec identity() -> compact_matrix().

-define(EPSILON, 1.0e-06).

identity() ->
Zero = 0.0,
One = 1.0,
Expand Down
2 changes: 1 addition & 1 deletion e3d/e3d_mesh.erl
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ add_hard_edges(_, _, _, _, _, Acc) ->
Acc.

is_equal_v(N,N) -> true;
is_equal_v(N1,N2) -> e3d_vec:dist_sqr(N1,N2) < 0.00001.
is_equal_v(N1,N2) -> e3d_vec:dist_sqr(N1,N2) < ?EPSILON.

%%%
%%% Mesh triangulation.
Expand Down
6 changes: 4 additions & 2 deletions e3d/e3d_q.erl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
rotate_s_to_t/2,
vec_rotate/2]).

-include("e3d.hrl").

-compile(inline).

%% Multiplicative identity
Expand All @@ -53,7 +55,7 @@ norm(Q = {{Qx,Qy,Qz},Qw})
when is_float(Qx),is_float(Qy),is_float(Qz),is_float(Qw) ->
M = magnitude(Q),
if M =:= 1.0 -> Q;
M < 0.00001 -> {{0.0,0.0,0.0},0.0};
M < ?EPSILON -> {{0.0,0.0,0.0},0.0};
true ->
IM = 1/M,
{{Qx*IM,Qy*IM,Qz*IM},Qw*IM}
Expand All @@ -78,7 +80,7 @@ slerp(Q0={{X0,Y0,Z0},W0}, {{X1,Y1,Z1},W1}, T)
true ->
HalfTheta = math:acos(HalfCosTheta),
HalfSinTheta = math:sin(HalfTheta),
if abs(HalfSinTheta) < 0.00001 ->
if abs(HalfSinTheta) < ?EPSILON ->
R0 = 1.0 - T,
R1 = T,
{{X0*R0+X1*R1, Y0*R0+Y1*R1, Z0*R0+Z1*R1},W0*R0+W1*R1};
Expand Down
2 changes: 1 addition & 1 deletion e3d/e3d_vec.erl
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ line_dist_sqr(P,A,B) ->
%% Pb = P3 + mub (P4 - P3)
%% Return FALSE if no solution exists.
%% (from http://paulbourke.net/geometry/pointlineplane/)
-define(EPS, 0.000001).
-define(EPS, ?EPSILON).
-spec line_line_intersect(point(),point(),point(),point()) ->
false | {point(), point(), float(), float()}.
line_line_intersect(P1,P2,P3,P4) ->
Expand Down
6 changes: 3 additions & 3 deletions plugins_src/autouv/auv_mapping.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1192,7 +1192,7 @@ calc_scale([{Face,[{Id1,P1},{Id2,P2},{Id3,P3}]}|R], Ovs, A2D, A3D,F2A,F2OVs) ->
A3 = area3d(Q1,Q2,Q3),
calc_scale(R,Ovs,A2+A2D,A3+A3D,[{Face,A3}|F2A],[{Face,{Q1,Q2,Q3}}|F2OVs]);
calc_scale([],_Ovs,A2D,A3D,F2A,F2OVs) ->
{math:sqrt(A3D/A2D),
{math:sqrt(A3D/wings_util:nonzero(A2D)),
gb_trees:from_orddict(lists:sort(F2A)),
gb_trees:from_orddict(lists:sort(F2OVs))}.

Expand Down Expand Up @@ -1226,7 +1226,7 @@ l2({S1,T1}, {S2,T2}, {S3,T3},
T23 = T2-T3, T31 = T3-T1, T12 = T1-T2,
S32 = S3-S2, S13 = S1-S3, S21 = S2-S1,
case S21*T31-S13*T12 of
DoubleArea when DoubleArea > 0.00000001 ->
DoubleArea when DoubleArea > ?EPSILON ->
SX = Q1x*T23+Q2x*T31+Q3x*T12,
SY = Q1y*T23+Q2y*T31+Q3y*T12,
SZ = Q1z*T23+Q2z*T31+Q3z*T12,
Expand All @@ -1244,7 +1244,7 @@ l2({S1,T1}, {S2,T2}, {S3,T3},

l8(P1,P2,P3,Q1,Q2,Q3) -> %% Worst stretch value
A2 = area2d2(P1,P2,P3),
if A2 > 0.00000001 ->
if A2 > ?EPSILON ->
SS = ss(P1,P2,P3,Q1,Q2,Q3,A2),
ST = st(P1,P2,P3,Q1,Q2,Q3,A2),
A = e3d_vec:dot(SS,SS),
Expand Down
11 changes: 5 additions & 6 deletions plugins_src/autouv/wpc_autouv.erl
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,7 @@ handle_command_1({scale,normalize}, St0) -> %% Normalize chart sizes
end, {0.0,0.0,[]}, St0),
TScale = TA2D/TA3D,
Scale = fun({A2D,A3D,We0 = #we{id=WId}},Sh) ->
Scale = math:sqrt(TScale * A3D/A2D),
Scale = math:sqrt(TScale * A3D/wings_util:nonzero(A2D)),
Center = wings_vertex:center(We0),
T0 = e3d_mat:translate(e3d_vec:neg(Center)),
SM = e3d_mat:scale(Scale, Scale, 1.0),
Expand Down Expand Up @@ -1525,7 +1525,7 @@ displace_edges([{_,{Id,Edge1,{Vs1,Ve1}},{Id,_,{Vs2,Ve2}}}|Eds], Sh) ->
displace_edges(Eds,Sh);
_ ->
%% What Direction should we displace the verts?
[Move1,Move2] = displace_dirs(0.0000001,Edge1,We),
[Move1,Move2] = displace_dirs(?EPSILON,Edge1,We),
%% Make the move
Vpos = foldl(fun({V1,V2},VpIn) ->
Pos1 = e3d_vec:add(Move1,array:get(V1,Vpos0)),
Expand All @@ -1549,9 +1549,9 @@ displace_charts([{_,{Id1,_,_},{Id2,_,_}}|Eds], Moved, Sh) ->
We0 = #we{vp=Vpos0} = gb_trees:get(Id1,Sh),
C1 = wings_vertex:center(We0),
C2 = wings_vertex:center(gb_trees:get(Id2,Sh)),
Disp0 = e3d_vec:mul(e3d_vec:norm(e3d_vec:sub(C1,C2)),0.0000001),
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,0.0000001,0.0};
{0.0,0.0,0.0} -> {0.0,?EPSILON,0.0};
Disp -> Disp
end,
Vpos= [{V,e3d_vec:add(Pos,Move)} ||
Expand Down Expand Up @@ -1964,7 +1964,7 @@ stretch(Dir,We) ->
[{X1,Y1,_},{X2,Y2,_}] = wings_vertex:bounding_box(We),
Center = {CX,CY,CZ} = {X1+(X2-X1)/2, Y1+(Y2-Y1)/2, 0.0},
T0 = e3d_mat:translate(e3d_vec:neg(Center)),
SX0 = 1.0/(X2-X1), SY0= 1.0/(Y2-Y1),
SX0 = 1.0/wings_util:nonzero(X2-X1), SY0= 1.0/wings_util:nonzero(Y2-Y1),
{SX,SY} = case Dir of
max_x -> {SX0, 1.0};
max_y -> {1.0, SY0};
Expand Down Expand Up @@ -2246,4 +2246,3 @@ geom2auv_edges(Es, #we{name=#ch{emap=Emap0}}) ->
{value,Hits} -> Hits ++ Acc
end
end, [], Es).

2 changes: 0 additions & 2 deletions plugins_src/commands/wpc_absolute_scale.erl
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

-export([init/0,menu/2,command/2]).

-define(EPSILON,0.0000005).

%%%
%%% plugin interface
%%%
Expand Down
2 changes: 0 additions & 2 deletions plugins_src/commands/wpc_shift.erl
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
-include_lib("wings/src/wings.hrl").

-define(HUGE, 1.0E307).
-define(EPSILON, 1.0E-6).


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
Expand Down
3 changes: 3 additions & 0 deletions src/wings.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
-define(F32, 32/float-native).
-define(I32, 32/signed-native).
-define(UI32, 32/native).
-ifndef(EPSILON).
-define(EPSILON, 1.0e-7).
-endif.

-define(PANE_COLOR, {0.52,0.52,0.52}).
-define(BEVEL_HIGHLIGHT, {0.9,0.9,0.9}).
Expand Down
6 changes: 3 additions & 3 deletions src/wings_extrude_edge.erl
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,14 @@ bevel_min_limit([{_Edge,[{O1,D1},{O2,D2}]}|Tail], We, Min0) ->
Z when Z < (0.01*?DEFAULT_EXTRUDE_DIST*?DEFAULT_EXTRUDE_DIST) ->
%% There is no intersection between the lines.
case e3d_vec:len(O2MinusO1) of
Odist when Odist < 0.000001 ->
Odist when Odist < ?EPSILON ->
%% As the vertices are already near each other,
%% we will assume that they will be moving apart.
bevel_min_limit(Tail, We, Min0);
Odist ->
D1Len = e3d_vec:len(D1),
case e3d_vec:dist(e3d_vec:mul(D1, Odist/D1Len), O2MinusO1) of
Dist when Dist < 0.000001 ->
Dist when Dist < ?EPSILON ->
%% The vertices will be moved directly towards each
%% others.
S = Odist / (2*D1Len),
Expand All @@ -213,7 +213,7 @@ bevel_min_limit([{{Va,Vb},[{_,D1}]}|Tail], #we{vp=Vtab}=We, Min0) ->
VaPos = array:get(Va, Vtab),
VbPos = array:get(Vb, Vtab),
case e3d_vec:len(D1) of
DLen when DLen < 0.000001 ->
DLen when DLen < ?EPSILON ->
bevel_min_limit(Tail, We, 0.0);
DLen ->
case e3d_vec:len(e3d_vec:sub(VaPos, VbPos)) / DLen of
Expand Down
4 changes: 2 additions & 2 deletions src/wings_sel_cmd.erl
Original file line number Diff line number Diff line change
Expand Up @@ -796,15 +796,15 @@ vertex_dots_and_sqlens(Vecs, [VecB|_], Dot, Sq) ->
vertex_dots_and_sqlens(Vecs++[VecB], [], Dot, Sq);
vertex_dots_and_sqlens(_Other, _More, Dot, Sq) -> {Dot,Sq}.

-define(EPSILON, 1.0E-5).
-define(TOLERANCE, 1.0E-5).
compare(A, B) ->
%% Comparison with a relative tolerance for large
%% values and an absolute tolerance for small values
%% as described by Christer Ericson in
%% http://realtimecollisiondetection.net/blog/?p=89
%% and in his book "Real-Time Collision Detection".
%%
abs(A-B) =< ?EPSILON*max(1.0, max(abs(A), abs(B))).
abs(A-B) =< ?TOLERANCE*max(1.0, max(abs(A), abs(B))).

%%
%% Select Random.
Expand Down
7 changes: 6 additions & 1 deletion src/wings_util.erl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
mapsfind/3,
wxequal/2, wxset_pid/2, min_wx/1,
nice_float/1,nice_vector/1,nice_abs_vector/1,
string_to_float/1,
nonzero/1,
string_to_float/1,
unique_name/2,
is_name_masked/2,
lib_dir/1,
Expand Down Expand Up @@ -214,6 +215,10 @@ simplify_float_1("0."++_=F) -> F;
simplify_float_1("0"++F) -> simplify_float_1(F);
simplify_float_1(F) -> F.

nonzero(Value) ->
if abs(Value) < ?EPSILON -> ?EPSILON;
true -> Value
end.

string_to_float("NaN") -> 0.0;
string_to_float(Str) ->
Expand Down

0 comments on commit 3b97ff1

Please sign in to comment.