From f63750b616f874c7f08bae13997e96dfded9c446 Mon Sep 17 00:00:00 2001 From: micheus Date: Tue, 22 Oct 2024 18:52:34 -0300 Subject: [PATCH] - Fixed a soft crash in wpc_ncube caused by computed value of -0.0; - Fixed the constant EPISILON used in wpc_oblong; --- plugins_src/primitives/wpc_ncube.erl | 29 ++++++++++++++++++--------- plugins_src/primitives/wpc_oblong.erl | 8 +++----- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/plugins_src/primitives/wpc_ncube.erl b/plugins_src/primitives/wpc_ncube.erl index 8db8ddb34..e7302ab5f 100644 --- a/plugins_src/primitives/wpc_ncube.erl +++ b/plugins_src/primitives/wpc_ncube.erl @@ -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}, @@ -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) -> @@ -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) -> diff --git a/plugins_src/primitives/wpc_oblong.erl b/plugins_src/primitives/wpc_oblong.erl index 2f80efd20..d6377059c 100644 --- a/plugins_src/primitives/wpc_oblong.erl +++ b/plugins_src/primitives/wpc_oblong.erl @@ -17,8 +17,6 @@ -export([init/0,menu/2,command/2]). -include_lib("wings/src/wings.hrl"). --define(EPSLON, 0.000001). - init() -> true. @@ -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) @@ -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 -> @@ -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)];