From fe309e338b1487dd9970d91e2a713390b24ab7f3 Mon Sep 17 00:00:00 2001 From: "luca.mazzoleni" Date: Thu, 8 Jan 2026 16:49:22 +0100 Subject: [PATCH] - in FaceData migliorata la scelta della BottomFace 1 --- LuaLibs/FaceData.lua | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/LuaLibs/FaceData.lua b/LuaLibs/FaceData.lua index d488119..e716295 100644 --- a/LuaLibs/FaceData.lua +++ b/LuaLibs/FaceData.lua @@ -190,6 +190,8 @@ function FaceData.GetFacesInfo( Proc, Part, FacesToGet) Faces[i].dArea = dShortDimension * dLongDimension Faces[i].dLMinRectangle = dLongDimension Faces[i].dWMinRectangle = dShortDimension + -- volume approssimato di materiale asportato lavorando questa faccia + Faces[i].dMachinedVolumeApprox = Faces[i].dArea * Faces[i].dElevation local nFaceType, Edges = FaceData.GetEdgesInfo( Proc, i - 1) Faces[i].bIsOkForMachining = nFaceType < 1 @@ -248,6 +250,26 @@ function FaceData.IsFaceParallelogram( Face) return bIsRhomboid end +------------------------------------------------------------------------------------------------------------- +local function CompareBottomFaces( FaceA, FaceB) + local dMaxVolumeRelativeChange = 0.15 + -- si prende la faccia con volume lavorato maggiore + if FaceA.dMachinedVolumeApprox > ( 1 + dMaxVolumeRelativeChange) * FaceB.dMachinedVolumeApprox + 10 * GEO.EPS_SMALL then + return true + elseif FaceB.dMachinedVolumeApprox > ( 1 + dMaxVolumeRelativeChange) * FaceA.dMachinedVolumeApprox + 10 * GEO.EPS_SMALL then + return false + -- se volume lavorato simile, si prende la faccia con minore elevazione + else + if FaceA.dElevation < FaceB.dElevation - 10 * GEO.EPS_SMALL then + return true + elseif FaceB.dElevation < FaceA.dElevation - 10 * GEO.EPS_SMALL then + return false + else + return false + end + end +end + ------------------------------------------------------------------------------------------------------------- local function CompareEdgesBottomFace( EdgeA, EdgeB) -- prima i lati con facce adiacenti @@ -369,8 +391,8 @@ local function GetBottomFaces( Proc) end nCurrentFace = nCurrentFace + 1 end - -- la BottomFace 1 è sempre quella con minor elevazione - table.sort( BottomFaces, function (a, b) return a.dElevation < b.dElevation end) + -- la BottomFace 1 è quella che permette di asportare il volume maggiore; nei casi ambigui si sceglie quella a minor elevazione + table.sort( BottomFaces, CompareBottomFaces) end if #BottomFaces == 0 then