feat: the customer picks Agrupado or Misturado and sees free copies that fit the same metres (Rodada 5, C1, C2)

C2: encaixar takes an optional mode ('linhas', 'forma'; the Montar keeps
the automatic one); the buy box shows both billed lengths and the
difference in cm and R$ when they differ, marking the packing on screen.
C1: up to 5 arts are tried with up to 30 more copies, by binary search
with the packing in use, and up to 3 '+k file' buttons add the copies
that keep the billed metres. Both run after the order check, never
before it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-11-30 15:03:02 -03:00
parent 28c10aabf6
commit 030b66c697
7 changed files with 189 additions and 13 deletions

View File

@@ -48,12 +48,15 @@ const GANHO_FORMA_CM=1;
// pecas em centímetros: {w,h,img,a,travado}. W é a largura do filme em cm.
// Devolve {pos, altura, folga}: a altura já com as margens, a folga a menor
// usada na largura.
function encaixar(pecas,W){
function encaixar(pecas,W,modo){
if(pecas.some(p=>!Number.isFinite(p.w) || p.w<=0 || p.w>W))
throw new RangeError('A largura solicitada não cabe no filme.');
if(modo==='forma') return encaixarComMargens(pecas,W);
const linhas=encaixarEmLinhas(pecas,W);
const forma=encaixarComMargens(pecas,W);
if(forma.altura<=linhas.altura-GANHO_FORMA_CM) return forma;
if(modo!=='linhas'){
const forma=encaixarComMargens(pecas,W);
if(forma.altura<=linhas.altura-GANHO_FORMA_CM) return forma;
}
// A máscara de cada peça: a área de arte que a prévia mostra como aproveitada.
const mascaras=new Map();
linhas.pos.forEach(p=>{