Files
gods-eye-view/src/layers/radio/interaction.test.mjs
T
Sameh Khamis 8bcaced6ad Take the input dispatcher off Cesium: pointer input from the renderer's input port, picks from the query port
The dispatcher now builds on renderer.input and the query port, with
positions as plain {x, y}. Its viewer access count is zero and it leaves
the Cesium allow-list. Layers that read the raw engine pick read the Hit,
drawHit or event.native instead, and pickRegistry's resolvePickId and
pickContact take a Hit, with the raw versions kept in the Cesium adapter.

rendererOf gains findInput, provideUnboundInput and provideNativeClick.
event.native carries the engine's pick, drill and pickWindow, and picks
through the follow helper happen inside it. An unbound input port
survives the viewer being bound until it is released.

The query port's pick memo is now per task rather than per frame,
because Cesium's own picks advance the frame number. A click on the sky
skips the depth pass when nothing is on the ray. Touch contact search
keeps its eight-deep drill in a 14x14 window.
2026-11-09 00:47:30 -08:00

65 lines
2.0 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.
import test from 'node:test';
import assert from 'node:assert/strict';
import { createInteraction } from './interaction.js';
import { RADIO_PICK_WINDOW_PX } from './policy.js';
import { radioStationIdFromPick } from './rendering.js';
function interaction() {
const state = { _stationById: new Map([['kexp', {}]]) };
return createInteraction({
state,
services: {
picking: {
resolvePickId: (picked) => picked?.id ?? null,
isOwnedByOtherLayer: (layer, id) => id === 'flight-1',
registerPickOwner() {},
unregisterPickOwner() {},
},
overlays: { setOverlaySourceVisible() {} },
},
parts: { rendering: { radioStationIdFromPick } },
});
}
/** A draw-set item's hit. */
const hit = (id, set = 'radio:1:stations') => ({ set, id, surface: false });
/** A click event whose drill answers only with the window it is asked for. */
function clickEvent({ pick, windowHits = [] }) {
const drills = [];
return {
drills,
topHit: pick ?? null,
drill(limit, width, height) {
drills.push([limit, width, height]);
return width === RADIO_PICK_WINDOW_PX && height === RADIO_PICK_WINDOW_PX
? windowHits
: [];
},
};
}
test('a near miss finds the station through one windowed drill', () => {
const { pickedRadioStationAt } = interaction();
const event = clickEvent({
pick: undefined,
windowHits: [hit('notes:1', 'notes:1'), hit('radio:kexp')],
});
assert.equal(pickedRadioStationAt(event), 'kexp');
assert.deepEqual(event.drills, [
[16, RADIO_PICK_WINDOW_PX, RADIO_PICK_WINDOW_PX],
]);
});
test('a direct hit needs no drill, and another layer’s contact keeps its click', () => {
const { pickedRadioStationAt } = interaction();
const direct = clickEvent({ pick: hit('radio:kexp') });
assert.equal(pickedRadioStationAt(direct), 'kexp');
assert.deepEqual(direct.drills, []);
const other = clickEvent({
pick: hit('flight-1', 'flights:1'),
windowHits: [hit('radio:kexp')],
});
assert.equal(pickedRadioStationAt(other), null);
});