mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 00:32:21 +00:00
The renderer contract is what the application asks of a 3D renderer, so a renderer other than Cesium can draw the same application. It is nine ports (frame, globe, draw, camera, query, input, effects, credits, quality) plus the renderer itself, one strict .d.ts per port in src/render/contract/. PORTS lists every member at run time, and a TypeScript-compiler test fails when the list and the types disagree on one member. An optional member exists only with its capability; a required one answers null or empty without it. Nothing in the application uses the contract yet. The stub renderer (src/render/stub/) implements every port in memory and draws nothing. Its camera is a port of the default camera's maths: views, lookAt, flights with their height arc and easing, rectangle framing on the geodesic midpoint, the view rectangle with its horizon and pole cases, changed thresholds, follows, and flights that finish inside the call. The conformance suite (src/render/conformance/) runs 59 checks against any renderer through the contract alone, in Node or in a browser page. The camera checks compare traces recorded from Cesium's own Camera, headless on a virtual clock (scripts/record-camera-goldens.mjs), to 1 mm, 1e-9 and 1e-3 px. The other checks cover listener rules on every subscription, the frame loop, draw sets, picks, motion clocks, heights, leases, imagery, styles, credits and quality knobs. The stub passes all of them but the model check, which needs a glTF asset. Reference scenes draw one scene per primitive family, a city and a calibration path from orbit to the street, from contract calls only and with no network. /dev/conformance/ draws them on the Cesium scene renderer (src/render/cesium/sceneRenderer.js), records references through a dev-server-only, loopback-only endpoint, and compares captures with pixelmatch's antialias detection plus a solid-pixel count. Measured on Cesium: every MSAA setting passes, and a dropped 4 px point, a dropped 2 px line and a 1 px shift of the view fail. visual.js states the limits. The package exports ./render/contract, ./render/stub and ./render/conformance. Documented in docs/RENDERER-CONTRACT.md, docs/CODE-BOUNDARIES.md and docs/CURRENT-STATE.md.
124 lines
4.4 KiB
JavaScript
124 lines
4.4 KiB
JavaScript
/**
|
|
* @module render/conformance
|
|
* @description The renderer conformance suite. It runs every check against
|
|
* a renderer through the contract alone, in Node or in a browser page, and
|
|
* reports each as passed, failed or skipped.
|
|
*
|
|
* A harness says how to make the renderer under test and drive its clock:
|
|
*
|
|
* ```js
|
|
* const report = await runConformance({
|
|
* name: 'stub',
|
|
* create: ({ viewport, capabilities }) => makeRenderer(...),
|
|
* frame: (r) => advanceOneFrame(r), // 1/60 s on a virtual clock
|
|
* now: (r) => clockMs(r),
|
|
* toEcef: ({ lon, lat, height }) => ecef,
|
|
* tolerance: DEFAULT_TOLERANCE,
|
|
* flightPaths: 'trace', // or 'endpoints'
|
|
* });
|
|
* ```
|
|
*
|
|
* Optional harness members widen what is checked: `pointer(r, type, x, y)`
|
|
* (synthetic input), `scriptHeights(r, fn)` (heights from a function),
|
|
* `wallTime(r)` (the wall clock a `live` motion clock reads),
|
|
* `assets.model` (a glTF URL). `create` may return null when it cannot
|
|
* make a renderer with fewer capabilities; those checks are then skipped.
|
|
*/
|
|
import { cameraChecks } from './checks/camera.js';
|
|
import { portChecks } from './checks/ports.js';
|
|
|
|
/**
|
|
* @typedef {object} ConformanceTolerance
|
|
* @property {number} metres Positions and heights.
|
|
* @property {number} unit Unit vectors (direction, up, right).
|
|
* @property {number} radians Heading, pitch and roll.
|
|
* @property {number} pixels Screen positions.
|
|
* @property {number} changedCount `changed` events per script.
|
|
*/
|
|
|
|
/**
|
|
* @typedef {object} ConformanceHarness
|
|
* @property {string} name
|
|
* @property {(options: {viewport: {width: number, height: number}, capabilities?: string[]}) => Promise<import('../contract/renderer').Renderer|null>} create
|
|
* @property {(r: import('../contract/renderer').Renderer) => void|Promise<void>} frame
|
|
* @property {(r: import('../contract/renderer').Renderer) => number} now
|
|
* @property {(p: {lon: number, lat: number, height?: number}) => {x: number, y: number, z: number}} toEcef
|
|
* @property {ConformanceTolerance} tolerance
|
|
* @property {'trace'|'endpoints'} flightPaths Whether flight paths are compared frame by frame, or only where flights end.
|
|
* @property {(r: object, type: string, x: number, y: number, extra?: object) => void|Promise<void>} [pointer]
|
|
* @property {(r: object, fn: (point: {lon: number, lat: number}, against?: string) => number|null) => void} [scriptHeights]
|
|
* @property {(r: object) => number} [wallTime] Epoch ms the renderer's `live` motion clock reads.
|
|
* @property {{model?: string}} [assets]
|
|
*/
|
|
|
|
/**
|
|
* Tolerances a renderer that reproduces the reference camera meets: under a
|
|
* millimetre at city scale, well under a pixel on screen.
|
|
* @type {Readonly<ConformanceTolerance>}
|
|
*/
|
|
export const DEFAULT_TOLERANCE = Object.freeze({
|
|
metres: 1e-3,
|
|
unit: 1e-9,
|
|
radians: 1e-9,
|
|
pixels: 1e-3,
|
|
changedCount: 0,
|
|
});
|
|
|
|
/** Every check, in run order. */
|
|
export function conformanceChecks() {
|
|
return [...portChecks(), ...cameraChecks()];
|
|
}
|
|
|
|
/**
|
|
* @param {ConformanceHarness} harness
|
|
* @param {{only?: (id: string) => boolean}} [options]
|
|
* @returns {Promise<{harness: string, passed: number, failed: number, skipped: number,
|
|
* results: Array<{id: string, port: string, title: string, status: 'pass'|'fail'|'skip', detail?: string, ms: number}>}>}
|
|
*/
|
|
export async function runConformance(harness, options = {}) {
|
|
const results = [];
|
|
for (const c of conformanceChecks()) {
|
|
if (options.only && !options.only(c.id)) continue;
|
|
const start = Date.now();
|
|
let status = 'pass';
|
|
let detail;
|
|
try {
|
|
const outcome = await c.run(harness);
|
|
if (outcome?.skip) {
|
|
status = 'skip';
|
|
detail = outcome.skip;
|
|
}
|
|
} catch (error) {
|
|
status = 'fail';
|
|
detail = error?.message ?? String(error);
|
|
}
|
|
results.push({
|
|
id: c.id,
|
|
port: c.port,
|
|
title: c.title,
|
|
status,
|
|
...(detail ? { detail } : {}),
|
|
ms: Date.now() - start,
|
|
});
|
|
}
|
|
const count = (s) => results.filter((r) => r.status === s).length;
|
|
return {
|
|
harness: harness.name,
|
|
passed: count('pass'),
|
|
failed: count('fail'),
|
|
skipped: count('skip'),
|
|
results,
|
|
};
|
|
}
|
|
|
|
export { CAMERA_SCRIPTS, SCRIPT_VIEWPORT } from './cameraScripts.js';
|
|
export { CALIBRATION_PATH, REFERENCE_SCENES, sceneSupport } from './scenes.js';
|
|
export {
|
|
VISUAL_TOLERANCE,
|
|
compareImages,
|
|
drawScene,
|
|
referenceName,
|
|
} from './visual.js';
|
|
export { contractDriver, runCameraScript, tracePose } from './cameraRunner.js';
|
|
export * as expect from './expect.js';
|