Skip to content

Commit

Permalink
- Fixed a soft crash in wpc_ncube caused by computed value of -0.0;
Browse files Browse the repository at this point in the history
- Fixed the constant EPISILON used in wpc_oblong;
  • Loading branch information
Micheus committed Oct 22, 2024
1 parent 8b62777 commit f63750b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
29 changes: 19 additions & 10 deletions plugins_src/primitives/wpc_ncube.erl
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ ncube_dialog() ->
[{key,nres},{range,{1,20}}]}}],[{title, ?__(1,"Number of Cuts")}]},
{hframe,[
{label_column, [
{wings_s:dir(x), {text,2.0,[{key,xcube},{range,{0.0,infinity}}]}},
{wings_s:dir(y), {text,2.0,[{key,ycube},{range,{0.0,infinity}}]}},
{wings_s:dir(z), {text,2.0,[{key,zcube},{range,{0.0,infinity}}]}}
{wings_s:dir(x), {text,2.0,[{key,xcube},{range,{+0.0,infinity}}]}},
{wings_s:dir(y), {text,2.0,[{key,ycube},{range,{+0.0,infinity}}]}},
{wings_s:dir(z), {text,2.0,[{key,zcube},{range,{+0.0,infinity}}]}}
]}
],[{margin,false}]},
{hradio,[{?__(2,"Yes"), true},
Expand All @@ -88,15 +88,24 @@ ncube_dialog() ->
ncube_verts(Nres) ->
S = 1.0,
Nverts = plane_verts(Nres),
Tverts = [{X, S, Z} || {X,Z} <- Nverts],
Bverts = [{X, -S, -Z} || {X,Z} <- Nverts],
Fverts = [{X, -Z, S} || {X,Z} <- Nverts],
Kverts = [{-X, -Z, -S} || {X,Z} <- Nverts],
Rverts = [{ S, -X, Z} || {X,Z} <- Nverts],
Lverts = [{-S, X, Z} || {X,Z} <- Nverts],
Tverts = [calc_vs({X, S, Z},{1.0,S,1.0}) || {X,Z} <- Nverts],
Bverts = [calc_vs({X, S, Z},{1.0,-S,-1.0}) || {X,Z} <- Nverts],
Fverts = [calc_vs({X, Z, S},{1.0,-1.0,S}) || {X,Z} <- Nverts],
Kverts = [calc_vs({X, Z, S},{-1.0,-1.0,-S}) || {X,Z} <- Nverts],
Rverts = [calc_vs({S, X, Z},{S,-1.0,1.0}) || {X,Z} <- Nverts],
Lverts = [calc_vs({S, X, Z},{-S,1.0,1.0}) || {X,Z} <- Nverts],
VertsWithDups = Tverts ++ Bverts ++ Fverts ++ Kverts ++ Rverts ++ Lverts,
VertsWithDups.

calc_vs({X,Y,Z},{Xm,Ym,Zm}) ->
{safe_multiply(X,Xm),safe_multiply(Y,Ym),safe_multiply(Z,Zm)}.

safe_multiply(N, M) ->
case abs(N) < ?EPSILON of
true -> +0.0;
false -> N*M
end.

transform_mesh(false, Box, Vs) ->
[transform(Box,V) || V <- Vs];
transform_mesh(true, Box, Vs) ->
Expand Down Expand Up @@ -172,7 +181,7 @@ ngon_verts(NumVerts, Radius) ->
Nres = NumVerts,
Delta = 2*pi()/Nres,
[{Radius*cos(I*Delta),
0.0,
+0.0,
Radius*sin(I*Delta)} || I <- lists:seq(0, Nres-1)].

ngon_faces(NumVerts) ->
Expand Down
8 changes: 3 additions & 5 deletions plugins_src/primitives/wpc_oblong.erl
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
-export([init/0,menu/2,command/2]).
-include_lib("wings/src/wings.hrl").

-define(EPSLON, 0.000001).


init() -> true.

Expand Down Expand Up @@ -135,7 +133,7 @@ make_oblong(Arg, _St) ->
regular ->
make_regular(Width,Middle,Height,Bevel,SideSec,HeightSec,ThickSec,BevelSec,Modify);
void ->
Min = (Width/2)-?EPSLON,
Min = (Width/2)-?EPSILON,
Thickness1 = min(Min, Thickness),
Bevel1 = min(Min-(Thickness1/2.0),Bevel),
make_void(Width,Middle,Height,Bevel1,SideSec,HeightSec,ThickSec,BevelSec,Thickness1,Modify)
Expand Down Expand Up @@ -173,7 +171,7 @@ make_void(Width, Middle, Height, Bevel, SideSec,
make_outer_contour(Width, Height0, Bevel0, HeightSec, BevelSec) ->
YTop = Height0/2.0,
ZRig = Width/2.0,
if Bevel0 > ?EPSLON ->
if Bevel0 > ?EPSILON ->
if BevelSec > 0 ->
Delta = (math:pi()/2.0)/(BevelSec+1);
true ->
Expand Down Expand Up @@ -208,7 +206,7 @@ calc_inner_contour(Width, Thickness0, ThickSec, [{XMin,YMin,ZMax}|_]=Vs2) ->
%% mirroring the outside contour and adjusting the thickness
[{_XMin,_YMax,ZMin}|_] = Vs1 = [{X,Y,-Z+Offset} || {X,Y,Z} <- lists:reverse(Vs2)],
Thickness = (ZMax-ZMin),
if Thickness > ?EPSLON ->
if Thickness > ?EPSILON ->
ZSeg = Thickness/(ThickSec+1),
ZBot = [{XMin,-YMin,ZMax-(I*ZSeg)} || I <- lists:seq(1,ThickSec)],
ZTop = [{X,-Y,Z} || {X,Y,Z} <- lists:reverse(ZBot)];
Expand Down

0 comments on commit f63750b

Please sign in to comment.