fix: the layout lines up its columns and keeps 5 mm margins (layout version 3)
Some checks failed
Build and deploy / Validate source (push) Successful in 5s
Build and deploy / Integration suite on a real stack (push) Failing after 3m59s
Build and deploy / Secret scan and release gate (push) Successful in 6s
Build and deploy / Publish images (push) Has been skipped
Some checks failed
Build and deploy / Validate source (push) Successful in 5s
Build and deploy / Integration suite on a real stack (push) Failing after 3m59s
Build and deploy / Secret scan and release gate (push) Successful in 6s
Build and deploy / Publish images (push) Has been skipped
Dropstar's item 5 (2026-10-21). The engine placed pieces on a 5 mm grid, rounding each up: two 28,2 cm pieces needed 57,5 cm on a 57 cm film, so the second column slid 8 cm down, rows ended 8,6 mm apart and nothing was left at the edges. Order 1 came out 97,14 cm long. - pieces are laid out in rows with their exact sizes: 5 mm at the top, the bottom and between rows; across the width 5 mm at the edges and between pieces, or, when that does not fit, the space left shared out equally, never under 1,5 mm (order 1: 2 mm each, 89,42 cm long) - each artwork stands or lies down, whichever gives the shorter sheet - the shape packing (pieces fitting into each other) is kept only when it saves at least 1 cm; otherwise the columns stay aligned - the order records layout version 3; quotes made with version 2 still pass - the preview says the spacing really used Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -133,7 +133,7 @@ function carrinho(){
|
||||
fotos:(ehFolha()?folhas:artes).map(x=>x.fotoSrc||null),
|
||||
ext:extDe(((ehFolha()?folhas:artes)[0]||{f:{name:''}}).f.name),
|
||||
arquivos:(ehFolha()?folhas:artes).length,
|
||||
production:{version:2,film_width_cm:larguraFilme(),sources,...layout},
|
||||
production:{version:3,film_width_cm:larguraFilme(),sources,...layout},
|
||||
qualityStatus:$('ciente').classList.contains('recusa')?'rejected':
|
||||
$('ciente').classList.contains('on')?'warning':nota===0?'unverified':'ok',
|
||||
qualityAcknowledged:false,
|
||||
|
||||
@@ -89,6 +89,7 @@ const folhaTotalM=()=>folhas.reduce((t,x)=>t+(x.m||0)*(x.rep||1),0);
|
||||
const PAR={file:'avulsa', avulsa:'file', uvfile:'uv', uv:'uvfile'};
|
||||
let montagemCm=0; // altura da folha montada pelo motor, em cm
|
||||
let montagemLayout=null; // posições aprovadas de cada cópia, em cm
|
||||
let montagemFolgaCm=0.5; // a menor folga da montagem na largura
|
||||
const ZOOMS=[1,1.5,2,3,4]; let zoomI=0; // ampliação da montagem ao vivo
|
||||
let pedido=[]; // itens já fechados · o pagamento é um só
|
||||
// A escolha de entrega vale para o pedido inteiro, não por item. No Tiny, retirada
|
||||
|
||||
@@ -118,10 +118,94 @@ function mascara(img,w,h,rot,esp=false){
|
||||
return dilatar(bruto,cw,ch,cheias);
|
||||
}
|
||||
|
||||
// Encaixe pela forma, como o motor do servidor: mapa de ocupação real,
|
||||
// máscara por arte e candidatos numa grade ao longo da largura.
|
||||
// pecas em centímetros: {w,h,img}. W é a largura do filme em cm.
|
||||
// Margens e folgas da folha (regra da Dropstar, 21/10/2026): 5 mm em cima,
|
||||
// embaixo e entre as linhas. Na largura, 5 mm nas bordas e entre as peças como
|
||||
// alvo; quando não cabem, a sobra é dividida em partes iguais, e duas peças só
|
||||
// ficam lado a lado com pelo menos 1,5 mm entre elas e nas bordas.
|
||||
const MARGEM_CM=0.5, FOLGA_MIN_CM=0.15;
|
||||
// Pela forma, as peças se aproximam (favo de mel) e as colunas se deslocam.
|
||||
// Só compensa quando a folha encurta de verdade; senão, colunas alinhadas.
|
||||
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){
|
||||
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.');
|
||||
const linhas=encaixarEmLinhas(pecas,W);
|
||||
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=>{
|
||||
const k=p.ref.a||p.ref, giro=p.rot+(p.ref.a?.giro||0);
|
||||
if(!mascaras.has(k)) mascaras.set(k,new Map());
|
||||
const daArte=mascaras.get(k);
|
||||
if(!daArte.has(p.rot)) daArte.set(p.rot,mascara(p.ref.img,p.w,p.h,giro,p.ref.a?.esp));
|
||||
p.m=daArte.get(p.rot);
|
||||
});
|
||||
return linhas;
|
||||
}
|
||||
|
||||
// Em linhas, com as medidas exatas: cada arte (todas as cópias juntas) fica de
|
||||
// pé ou deitada, a que der a folha mais curta. Em arte retangular, girar 90° é
|
||||
// o que mais economiza filme.
|
||||
function encaixarEmLinhas(pecas,W){
|
||||
const arteDe=p=>p.a||p;
|
||||
const artes=[...new Set(pecas.map(arteDe))];
|
||||
const giraveis=artes.filter(arte=>{const p=pecas.find(q=>arteDe(q)===arte);
|
||||
return !p.mPronta && !p.travado && Math.abs(p.w-p.h)>1 && p.h<=W;});
|
||||
const deitadas=new Set();
|
||||
const montar=()=>emLinhas(pecas.map(p=>deitadas.has(arteDe(p))
|
||||
? {ref:p,w:p.h,h:p.w,rot:90} : {ref:p,w:p.w,h:p.h,rot:0}),W);
|
||||
const virar=arte=>deitadas.has(arte)?deitadas.delete(arte):deitadas.add(arte);
|
||||
let melhor=montar();
|
||||
for(let volta=0;volta<2;volta++){
|
||||
let mudou=false;
|
||||
for(const arte of giraveis){
|
||||
virar(arte);
|
||||
const teste=montar();
|
||||
if(teste.altura<melhor.altura-1e-9){melhor=teste;mudou=true;}
|
||||
else virar(arte);
|
||||
}
|
||||
if(!mudou) break;
|
||||
}
|
||||
return melhor;
|
||||
}
|
||||
// As mais altas primeiro; cada uma na primeira linha onde couber.
|
||||
function emLinhas(itens,W){
|
||||
const ordem=[...itens].sort((a,b)=>b.h-a.h||b.w-a.w);
|
||||
const linhas=[];
|
||||
for(const it of ordem){
|
||||
const linha=linhas.find(l=>l.soma+it.w+(l.itens.length+2)*FOLGA_MIN_CM<=W+1e-9);
|
||||
if(linha){ linha.itens.push(it); linha.soma+=it.w; }
|
||||
else linhas.push({itens:[it],soma:it.w,h:it.h}); // sozinha, cabe sempre
|
||||
}
|
||||
const pos=[];
|
||||
let y=MARGEM_CM, folgaMin=MARGEM_CM;
|
||||
linhas.forEach((l,i)=>{
|
||||
const folga=Math.min(MARGEM_CM,(W-l.soma)/(l.itens.length+1));
|
||||
folgaMin=Math.min(folgaMin,folga);
|
||||
let x=folga;
|
||||
for(const it of l.itens){ pos.push({x,y,w:it.w,h:it.h,rot:it.rot,ref:it.ref}); x+=it.w+folga; }
|
||||
y+=l.h+(i<linhas.length-1?MARGEM_CM:0);
|
||||
});
|
||||
return {pos, altura:y+MARGEM_CM, folga:folgaMin};
|
||||
}
|
||||
// O encaixe pela forma dentro das margens: 5 mm em cima e embaixo e, dos
|
||||
// lados, 5 mm ou o que a peça mais larga deixar.
|
||||
function encaixarComMargens(pecas,W){
|
||||
const maior=Math.max(...pecas.map(p=>p.w));
|
||||
const lado=Math.max(0,Math.min(MARGEM_CM,(W-maior)/2));
|
||||
const enc=encaixarPelaForma(pecas,W-2*lado);
|
||||
return {pos:enc.pos.map(p=>({...p, x:p.x+lado, y:p.y+MARGEM_CM})),
|
||||
altura:enc.altura+2*MARGEM_CM, folga:lado};
|
||||
}
|
||||
|
||||
// Encaixe pela forma: mapa de ocupação real, máscara por arte e candidatos
|
||||
// numa grade de 5 mm ao longo da largura.
|
||||
function encaixarPelaForma(pecas,W){
|
||||
const cols=Math.ceil(W/CEL)+1; // +1 = a coluna de folga da dilatação
|
||||
let linhas=0; const mapa=[];
|
||||
function garantir(ate){ while(linhas<ate){ mapa.push(new Uint8Array(cols)); linhas++; } }
|
||||
@@ -269,9 +353,9 @@ function desenhaMontagem(area,lista,mts,W,fora,aoTerminar){
|
||||
+ (girou? ' · <b style="display:inline">'+girou+
|
||||
(girou>1?' artes giradas':' arte girada')+' 90°</b> para caber melhor':'');
|
||||
(fora||area).appendChild(el);
|
||||
if(aoTerminar) aoTerminar({alturaCm, uso, girou,
|
||||
if(aoTerminar) aoTerminar({alturaCm, uso, girou, folgaCm:enc.folga,
|
||||
placements:enc.pos.map(p=>({source_index:p.ref.a.sourceIndex,
|
||||
copy_index:p.ref.copyIndex,x_cm:p.x,y_cm:p.y,
|
||||
copy_index:p.ref.copyIndex,x_cm:+p.x.toFixed(4),y_cm:+p.y.toFixed(4),
|
||||
width_cm:+p.w.toFixed(4),length_cm:+p.h.toFixed(4),
|
||||
rotation_degrees:(p.rot+(p.ref.a.giro||0))%360,
|
||||
mirrored:!!p.ref.a.esp}))});
|
||||
@@ -342,6 +426,7 @@ function previaAoVivo(){
|
||||
$('vArea').classList.toggle('ampliado', zoomI>0);
|
||||
desenhaMontagem($('vArea'), prontas, 0, W, $('vUso'), r=>{
|
||||
montagemCm = r.alturaCm; // altura real da folha montada
|
||||
montagemFolgaCm = r.folgaCm ?? MARGEM_CM;
|
||||
montagemLayout=r.placements ? {height_cm:+r.alturaCm.toFixed(4),
|
||||
placements:r.placements} : null;
|
||||
$('vMt').textContent = r.alturaCm? fmtM(cobrar(r.alturaCm/100))+' m' : '—';
|
||||
@@ -375,7 +460,9 @@ function previa(){
|
||||
$('pSub').textContent='folha montada por nós com as artes que você enviou';
|
||||
const linhas=[
|
||||
['var(--verde)','✓','Largura',larguraFilme()+' cm · dentro do padrão da máquina'],
|
||||
['var(--verde)','✓','Espaço entre artes','5 mm garantidos'],
|
||||
['var(--verde)','✓','Espaço entre artes', montagemFolgaCm>=MARGEM_CM-1e-9
|
||||
? '5 mm entre as artes e nas bordas'
|
||||
: n1(montagemFolgaCm*10)+' mm · 5 mm não cabem na largura, a sobra fica dividida por igual'],
|
||||
[nota>=75?'var(--verde)':'var(--laranja)', nota>=75?'✓':'!','Qualidade da folha',motivoNota()],
|
||||
['var(--verde)','✓','Metragem proporcional',
|
||||
'sua folha tem '+fmtM(metros)+' m e você paga '+fmtM(cob)+
|
||||
|
||||
Reference in New Issue
Block a user