Define the renderer contract, with a stub renderer and a conformance suite

The renderer contract is what the application asks of a 3D renderer. 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
a 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.
This commit is contained in:
Sameh Khamis committed 2026-11-04 14:21:48 -08:00
1 parent 464c29a9ed
commit 8db995acfc
65 files changed
+12759 -9

No files matched your search

+93
View File
@@ -0,0 +1,93 @@
/**
* Pointer input over the scene, through one dispatcher.
*
* A tool takes the pointer with a lease; while a lease is out, ambient
* subscribers (those without a lease) get only `move` and `up`: no presses,
* clicks, double-clicks, wheel or pinch. Suspending camera
* input is separate and counted, and takes effect on the same pointerdown
* that asked for it.
*
* A click is delivered with its pick already made, once, and shared by
* every subscriber (`PointerEv.pick`). Where the renderer's picks answer a
* or two late delivers the click that much later rather than answering
* without them; `query.pick` stays synchronous for everything else.
*
* The engine's stock behaviours (select on click, follow on double-click)
* are explicit and removable here, never implicit.
*/
import type { Hit, PickWindow } from './query';
import type { Ecef, Off, Release, ScreenXY } from './common';
export type PointerEventType =
'down' | 'move' | 'up' | 'click' | 'dblclick' | 'wheel' | 'pinch';
export interface Modifiers {
shift: boolean;
ctrl: boolean;
alt: boolean;
meta: boolean;
}
export interface PointerEv {
type: PointerEventType;
position: ScreenXY;
/** For `move`: where the pointer is now (`position` is where it was). */
endPosition?: ScreenXY;
button: 0 | 1 | 2;
modifiers: Modifiers;
/** Event time, ms (`performance.now()` timeline). */
timestamp: number;
pointerType: 'mouse' | 'touch' | 'pen';
/** `click`: how far the pointer travelled and how long the press lasted. */
gesture?: { travelPx: number; durationMs: number };
/** `wheel`: lines scrolled; `pinch`: scale since the last event. */
delta?: number;
/** `click` and `dblclick`: the hit under the pointer, picked once for every subscriber. */
pick?(): Hit | null;
/** `click` and `dblclick`: every hit under the pointer, from the same pick. */
drill?(options?: PickWindow & { limit?: number }): Hit[];
/** `click` and `dblclick`: the surface position under the pointer. */
ground?(): Ecef | null;
}
/** A tool's hold on the pointer. */
export interface Lease {
readonly owner: string;
readonly current: boolean;
release(): void;
}
/** A stock behaviour, on until suppressed. */
export interface StockBehaviour {
readonly enabled: boolean;
/** Turn it off until released. Holds are counted. */
suppress(): Release;
}
export interface InputPort {
on(
type: PointerEventType,
cb: (ev: PointerEv) => void,
options?: { lease?: Lease | (() => Lease | null) },
): Off;
/** Take the pointer for a tool. A new claim ends the previous lease. */
claimPointer(owner: string): Lease;
isPointerFree(): boolean;
/** Suspend user camera input until released. Holds are counted. */
suspendCameraControls(reason: string): Release;
/**
* Every behaviour the renderer does on its own in answer to input, each
* suppressible. `select` and `dblclickFollow` are always listed (a
* renderer without one reports it disabled); any other built-in one (a
* double-click zoom) is listed under its own name.
*/
readonly behaviours: {
/** Select the item under a click. */
readonly select: StockBehaviour;
/** Follow the item under a double-click. */
readonly dblclickFollow: StockBehaviour;
readonly [name: string]: StockBehaviour;
};
/** Ctrl+wheel zooms (rather than the page). */
ctrlWheelZoom: boolean;
}