Files
quartier/scripts/banc-contour.mjs
T
Jules NényandClaude Opus 5.5 64d62010ed Lot Q contour-dette, étape A : banc (scripts/banc-contour.mjs), mesures et captures d'avant, tests/contour-dette.test.ts rouge (6 cas)
Avant (0eea6db) : 849 272 triangles, 1 068 appels à 1 280 × 800 ; voiture partagée : 3 traversées du minibus en 10 min, 1 sur deux cycles (simulation).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 09:23:36 +01:00

71 lines
5.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Banc du lot Q-contour-arbres-et-dette (20/11) : triangles et appels de dessin de la vue quartier (1 280 × 800, la mesure
// des lots M1 et maisons), les captures avant / après, le mode fond et `?rendu=avant` (comparés au pixel par
// scripts/banc-m1-diff.mjs). Sur le modèle de scripts/banc-maisons.mjs (Chromium headless, swiftshader, horloge figée
// sous mouvement réduit).
// node scripts/banc-contour.mjs <base-url> <label> <dossier> [captures|mesures|croisement|tout]
// SHOTS=1280-fond,… : seulement ces captures · CROISE=<s> : l'instant (s de scène) de la capture minibus / voiture
import { createRequire } from 'node:module';
import { writeFileSync, mkdirSync } from 'node:fs';
const require = createRequire(process.env.PW_CORE || '/home/julesneny8/.npm/_npx/9833c18b2d85bc59/node_modules/');
const { chromium } = require('playwright-core');
const [base, label, out, quoi = 'tout'] = process.argv.slice(2);
mkdirSync(out, { recursive: true });
const EXE = process.env.CHROMIUM || '/home/julesneny8/.cache/ms-playwright/chromium-1254/chrome-linux64/chrome';
const browser = await chromium.launch({ executablePath: EXE, args: ['--use-angle=swiftshader', '--enable-unsafe-swiftshader', '--ignore-gpu-blocklist'] });
const erreurs = [];
// horloge : figée (mouvement réduit, comme les bancs précédents), ou « pas à pas » : chaque image avance de 50 ms de scène
async function ouvrir(w, h, dpr, q, hash, { pas = false } = {}) {
const ctx = await browser.newContext({ viewport: { width: w, height: h }, deviceScaleFactor: dpr, reducedMotion: pas ? 'no-preference' : 'reduce' });
const page = await ctx.newPage();
if (pas) await page.addInitScript(() => { let T = 5000; window.__avance = true; performance.now = () => T; const r = window.requestAnimationFrame.bind(window); window.requestAnimationFrame = (f) => r(() => { if (window.__avance) T += 50; f(T); }); });
else await page.addInitScript(() => { const T = 5000; performance.now = () => T; const r = window.requestAnimationFrame.bind(window); window.requestAnimationFrame = (f) => r(() => f(T)); });
page.on('console', (m) => { if (m.type() === 'error') erreurs.push(`${w} ${q}#${hash}: ${m.text()}`); });
page.on('pageerror', (e) => erreurs.push(`${w} ${q}#${hash}: ${e.message}`));
await page.goto(`${base}/?${q}${hash ? '#' + hash : ''}`, { waitUntil: 'networkidle' });
await page.waitForTimeout(3500);
return { ctx, page };
}
const res = { label, erreurs };
if (quoi === 'captures' || quoi === 'tout') {
const SH = [['1280-M-01-ensemble', 1280, 800, 1, 'mesure', ''], ['390-M-01-arrivee', 390, 844, 3, 'mesure', ''],
// les arbres de près : le jardin témoin (#parcelle-25, la maison témoin) et la place (« Le parking devient le marché »)
['1280-M-arbres-gros-plan', 1280, 800, 1, 'mesure', 'parcelle-25'], ['1280-M-arbres-place', 1280, 800, 1, 'mesure', 'quartier-marche'],
['390-M-arbres-gros-plan', 390, 844, 3, 'mesure', 'parcelle-25'],
['1280-fond', 1280, 800, 1, 'mode=fond', ''], ['1280-avant', 1280, 800, 1, 'mesure&rendu=avant', ''], ['390-S-maison', 390, 844, 3, 'mesure', 'maison']];
const garder = (process.env.SHOTS || '').split(',').filter(Boolean);
for (const [nom, w, h, dpr, q, hash] of SH) {
if (garder.length && !garder.includes(nom)) continue;
const { ctx, page } = await ouvrir(w, h, dpr, q, hash);
if (hash === 'maison') await page.waitForTimeout(2500);
await page.screenshot({ path: `${out}/${nom}-${label}.png` });
if (hash === 'maison') res.s390 = await page.evaluate(() => { const ms = document.getElementById('maison-s'); return { dessin: !!(ms && !ms.hidden && ms.offsetWidth > 0), velosTemoin: window.__quartier.velosTemoinEcran ? window.__quartier.velosTemoinEcran() : null, W: innerWidth, H: innerHeight }; });
await ctx.close();
}
}
if (quoi === 'mesures' || quoi === 'tout') {
const { ctx, page } = await ouvrir(1280, 800, 1, 'mesure', '');
res.info = await page.evaluate(() => { const r = window.__quartier.renderer, i = r.info.render; return { calls: i.calls, triangles: i.triangles, lines: i.lines, geometries: r.info.memory.geometries }; });
res.trait = await page.evaluate(() => window.__quartier.trait);
await ctx.close();
// la même mesure, de près (le jardin témoin) : ce que la coque coûte là où elle se voit
const p = await ouvrir(1280, 800, 1, 'mesure', 'parcelle-25');
res.infoJardin = await p.page.evaluate(() => { const i = window.__quartier.renderer.info.render; return { calls: i.calls, triangles: i.triangles }; });
await p.ctx.close();
}
if (quoi === 'croisement') {
// la voiture partagée et le minibus sur la route principale : la scène avance de 50 ms par image jusqu'à CROISE s,
// la caméra suit le minibus (fiche « quartier-bus »)
const T = +(process.env.CROISE || 30), { ctx, page } = await ouvrir(1280, 800, 1, 'mesure', 'quartier-bus', { pas: true });
await page.waitForFunction((T) => (window.__quartier.temps ? window.__quartier.temps() >= T : false), T, { timeout: 540000, polling: 500 });
await page.evaluate(() => { window.__avance = false; });
await page.waitForTimeout(600);
res.croisement = await page.evaluate(() => ({ t: window.__quartier.temps(), ...(window.__quartier.partagee ? window.__quartier.partagee() : {}) }));
await page.screenshot({ path: `${out}/1280-M-minibus-voiture-${label}.png` }); await ctx.close();
}
await browser.close();
writeFileSync(`${out}/mesures-${label}${quoi === 'tout' ? '' : '-' + quoi}.json`, JSON.stringify(res, null, 1));
console.log(JSON.stringify({ label, info: res.info, infoJardin: res.infoJardin, coques: res.trait && res.trait.coques, s390: res.s390, croisement: res.croisement, erreurs: erreurs.length }, null, 0));
if (erreurs.length) console.log(erreurs.join('\n'));