- in NestProcess.PartTemplates:AddPart si salvano i MaxHeadRecess testa e coda; creata funzione FindBestPartForBeam, da completare

This commit is contained in:
luca.mazzoleni
2026-05-15 10:10:25 +02:00
parent f90dd95880
commit f27000b7bc
+41 -12
View File
@@ -16,12 +16,12 @@ local RawInventory = {
}
function RawInventory:GetNewBeam( dLength)
local NewBeam = {
dTotalLength = dLength,
dResidual = dLength,
dResidual = dLength - NEST.STARTOFFSET,
LastOffsetX = { 0, 0, 0, 0},
LastVtN = Vector3d( 1, 0, 0),
dLastHeadRecess = 0,
NestedParts = {}
}
@@ -43,13 +43,12 @@ function RawInventory:BuildStock()
return RawInventory
end
-- aggiunge una nuova barra attiva rimuovendo il corrispondente dalla lista stock disponibili
-- aggiunge una nuova barra attiva rimuovendo la corrispondente dalla lista stock disponibili
function RawInventory:AddActiveBeam( nStockIndex)
local CurrentStock = self.Stock[nStockIndex]
-- se barra disponibile posso aggiungerla a quelle attive
if CurrentStock and CurrentStock.nCount > 0 then
-- update quantità a stock
CurrentStock.nCount = CurrentStock.nCount - 1
@@ -64,7 +63,8 @@ function RawInventory:AddActiveBeam( nStockIndex)
end
----------------------------------------------------------------------------------------------------------
-- PartTemplates (informazioni geometriche pezzi univoci) e JobPool (lista di tutti i singoli pezzi, multipli compresi, da nestare)
-- PartTemplates (informazioni geometriche pezzi univoci)
-- JobPool (lista di tutti i singoli pezzi, multipli compresi, da nestare)
local PartTemplates = {}
local JobPool = {}
@@ -80,7 +80,7 @@ function PartTemplates:GetInfoFromPart( id, sStateWithSide)
local Info = EgtSplitString( sInfo, ';')
OffsetX = EgtSplitString( Info[1], ',')
vtN = VectorFromString( Info[2])
-- si convertono gli offset in numeri
for i = 1, #OffsetX do
OffsetX[i] = tonumber( OffsetX[i]) or 0
@@ -93,6 +93,7 @@ function PartTemplates:AddPart( id)
self[id] = {}
self[id].dLength = EgtGetInfo( id, 'L', 'd')
self[id].States = {}
self[id].dMaxGlobalTailRecess = 0
local States = { '1000', '0010', '1000_INV', '0010_INV' }
@@ -122,6 +123,26 @@ function PartTemplates:AddPart( id)
OffsetX = OffsetXTail,
vtN = vtNTail
}
-- overlap massimi in testa e in coda per questo pezzo
local dMaxHeadRecess = 0
for i = 1, 4 do
if State.Head.OffsetX[i] > dMaxHeadRecess + 10 * GEO.EPS_SMALL then
dMaxHeadRecess = State.Head.OffsetX[i]
end
end
State.dMaxHeadRecess = dMaxHeadRecess
local dMaxTailRecess = 0
for i = 1, 4 do
if abs( State.Tail.OffsetX[i]) > dMaxTailRecess + 10 * GEO.EPS_SMALL then
dMaxTailRecess = abs( State.Tail.OffsetX[i])
end
end
State.dMaxTailRecess = dMaxTailRecess
if dMaxTailRecess > self[id].dMaxGlobalTailRecess + 10 * GEO.EPS_SMALL then
self[id].dMaxGlobalTailRecess = dMaxTailRecess
end
end
end
end
@@ -136,6 +157,13 @@ local function BuildPartTemplatesAndJobPool()
end
return PartTemplates, JobPool
end
----------------------------------------------------------------------------------------------------------
local function FindBestPartForBeam( Beam)
end
----------------------------------------------------------------------------------------------------------
@@ -152,10 +180,10 @@ BuildPartTemplatesAndJobPool()
while true do
local BestMove
local dHighestScore = -GEO.INFINITO
-- 1 Si provano le barre già attive
for i = 1, #RawInventory.ActiveBeams do
local CurrentMove = FindBestPartForBeam( RawInventory.ActiveBeams[i], JobPool)
local CurrentMove = FindBestPartForBeam( RawInventory.ActiveBeams[i])
if CurrentMove and CurrentMove.dScore > dHighestScore then
dHighestScore = CurrentMove.dScore
BestMove = CurrentMove
@@ -167,7 +195,7 @@ while true do
for i = 1, #RawInventory.Stock do
local VirtualBeam = RawInventory:GetNewBeam( RawInventory.Stock[i].dLength)
if RawInventory.Stock[i].nCount > 0 then
local CurrentMove = FindBestPartForBeam( VirtualBeam, JobPool)
local CurrentMove = FindBestPartForBeam( VirtualBeam)
if CurrentMove and CurrentMove.dScore > dHighestScore then
dHighestScore = CurrentMove.dScore
BestMove = CurrentMove
@@ -176,9 +204,10 @@ while true do
end
end
-- 3 Procedi con nesting
-- 3 Se BestMove trovata si aggiornano lista pezzi e barre
if BestMove then
CommitBestMove()
CommitBestMove( BestMove)
-- se non c'è più niente di compatibile si esce
else
break
end