mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Merge branch 'sameh/renderer-leftovers' into sameh/renderer-seam
# Conflicts: # src/render/cesium/draw.test.mjs # src/render/cesiumAllowList.json
This commit is contained in:
commit
481df0b093
25 files changed
+1823
-886
No files matched your search
@@ -224,6 +224,7 @@ test('consumer build includes only infrastructure code and resolves assets under
|
||||
'scenePick.js',
|
||||
'sensorPick.js',
|
||||
'sphere.js',
|
||||
'stockFollow.js',
|
||||
'styleStages.js',
|
||||
'vector.js',
|
||||
]);
|
||||
|
||||
@@ -8,13 +8,7 @@ import {
|
||||
findQuery,
|
||||
} from '../render/rendererOf.js';
|
||||
import { cssColor } from '../render/color.js';
|
||||
import {
|
||||
WGS84,
|
||||
fromDegrees,
|
||||
fromDegreesInto,
|
||||
toLonLatH,
|
||||
} from '../geo/ellipsoid.js';
|
||||
import { offsetFromHeadingPitchRange } from '../geo/frames.js';
|
||||
import { fromDegrees, fromDegreesInto, toLonLatH } from '../geo/ellipsoid.js';
|
||||
import { sphereFromPoints } from '../geo/sphere.js';
|
||||
import { densifyRhumb } from '../geo/rhumb.js';
|
||||
import { heightsOf } from '../queries/heights.js';
|
||||
@@ -25,6 +19,7 @@ import {
|
||||
} from '../sources/infrastructureData.js';
|
||||
import { createInfrastructureOverlayEntry } from './infrastructureOverlayEntry.js';
|
||||
import { createGeojsonPins } from './geojsonPins.js';
|
||||
import { followViewFrom } from './stockFollow.js';
|
||||
import { inputFor as defaultInputFor } from '../input/dispatcher.js';
|
||||
import {
|
||||
selectInfraLod,
|
||||
@@ -321,34 +316,6 @@ const STEM_WIDTH_PX = 3.5;
|
||||
const PIN_SIZE_PX = 8;
|
||||
const BLACK = Object.freeze([0, 0, 0, 1]);
|
||||
|
||||
/** The range the default renderer frames a sphere of no size from. */
|
||||
const MINIMUM_FIT_RANGE_M = 100;
|
||||
|
||||
/**
|
||||
* Where the camera frames a part it starts following, as the default
|
||||
* renderer framed an entity it started following with no view of its own:
|
||||
* looking at the bounds' centre, heading north, pitched down 45° (steeper
|
||||
* far from the ground), at the range that fits the bounds in view, within
|
||||
* the camera's zoom limits. Returned as the eye's offset from the centre,
|
||||
* east-north-up there; `at` is where the part stands.
|
||||
*/
|
||||
function followViewFrom(sphere, at, camera) {
|
||||
const pose = camera.pose?.();
|
||||
const fovy = Number.isFinite(pose?.fovy) ? pose.fovy : Math.PI / 3;
|
||||
const aspect = Number.isFinite(pose?.aspectRatio) ? pose.aspectRatio : 1;
|
||||
const tanPhi = Math.tan(fovy / 2);
|
||||
const tanTheta = aspect * tanPhi;
|
||||
let range =
|
||||
sphere.radius === 0
|
||||
? MINIMUM_FIT_RANGE_M
|
||||
: Math.max(sphere.radius / tanTheta, sphere.radius / tanPhi);
|
||||
const { minDistance = 0, maxDistance = Infinity } = camera.controls ?? {};
|
||||
range = Math.min(Math.max(range, minDistance), maxDistance);
|
||||
const factor =
|
||||
2 - 1 / Math.max(1, Math.hypot(at.x, at.y, at.z) / WGS84.radii.x);
|
||||
return offsetFromHeadingPitchRange(0, (-Math.PI / 4) * factor, range);
|
||||
}
|
||||
|
||||
/** The GeoJSON loader's `marker-size` names, in pixels. */
|
||||
const MARKER_SIZES = Object.freeze({ small: 24, medium: 48, large: 64 });
|
||||
/**
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import * as Cesium from 'cesium';
|
||||
import { bindRenderer } from '../render/rendererOf.js';
|
||||
import { fromDegrees } from '../geo/ellipsoid.js';
|
||||
import { bindFakeDraw } from '../testSupport/fakeDrawPort.mjs';
|
||||
import { fakeSceneFrame } from '../testSupport/fakeCesiumScene.mjs';
|
||||
import { gstime } from 'satellite.js';
|
||||
import { createModel } from '../layers/launches/model.js';
|
||||
@@ -1159,37 +1160,34 @@ test('real mission build, select, refresh, deselect, disable, and destroy paths
|
||||
removeEventListener(type) { listeners.delete(`document:${type}`); },
|
||||
};
|
||||
const canvas = new FakeElement('canvas');
|
||||
const dataSources = [];
|
||||
const camera = {
|
||||
positionCartographic: null,
|
||||
positionWC: Cesium.Cartesian3.fromDegrees(-80.604, 28.608, 18_000_000),
|
||||
cancelFlight() {},
|
||||
lookAtTransform() {},
|
||||
};
|
||||
let eye = fromDegrees(-80.604, 28.608, 18_000_000);
|
||||
const scene = {
|
||||
canvas,
|
||||
camera,
|
||||
frameState: { frameNumber: 1 },
|
||||
postRender: new Cesium.Event(),
|
||||
preRender: new Cesium.Event(),
|
||||
preUpdate: new Cesium.Event(),
|
||||
primitives: { add: (primitive) => primitive, remove: () => true },
|
||||
drillPick: () => [],
|
||||
};
|
||||
const viewer = {
|
||||
camera,
|
||||
scene,
|
||||
dataSources: {
|
||||
add(dataSource) { dataSources.push(dataSource); return dataSource; },
|
||||
remove(dataSource) {
|
||||
const index = dataSources.indexOf(dataSource);
|
||||
if (index >= 0) dataSources.splice(index, 1);
|
||||
return index >= 0;
|
||||
},
|
||||
const viewer = { scene };
|
||||
const { draw } = bindFakeDraw(viewer, {
|
||||
frame: fakeSceneFrame(viewer),
|
||||
camera: {
|
||||
// No pose to fly from: the full-globe framing on enable stays put.
|
||||
pose: () => ({ lon: Number.NaN, lat: Number.NaN, height: 18_000_000, position: eye, fovy: Number.NaN }),
|
||||
on: () => () => {},
|
||||
release() {},
|
||||
cancelFlight() {},
|
||||
},
|
||||
selectedEntity: undefined,
|
||||
query: { drillPick: () => [] },
|
||||
});
|
||||
// The mission sets' items by id, across the layer's draw sets.
|
||||
const missionItems = () => {
|
||||
const items = new Map();
|
||||
for (const record of draw.sets.values())
|
||||
if (!record.disposed && /:(lines|sites|markers)$/.test(record.spec.id))
|
||||
for (const [id, item] of record.items) items.set(id, item);
|
||||
return items;
|
||||
};
|
||||
bindRenderer(viewer, { frame: fakeSceneFrame(viewer) });
|
||||
const item = (id) => missionItems().get(id);
|
||||
const hostCalls = [];
|
||||
const host = {
|
||||
setEntries: (...args) => hostCalls.push(['entries', ...args]),
|
||||
@@ -1245,9 +1243,10 @@ test('real mission build, select, refresh, deselect, disable, and destroy paths
|
||||
await rocketLaunchesLayer.enable();
|
||||
await rocketLaunchesLayer.update();
|
||||
|
||||
const entities = dataSources[0].entities.values;
|
||||
assert.ok(entities.length >= 7, 'runtime guard requires the populated mission build path');
|
||||
assert.ok(entities.every((entity) => entity.label === undefined));
|
||||
assert.ok(missionItems().size >= 7, 'runtime guard requires the populated mission build path');
|
||||
// Every set is a kind with no world text: labels are the host's.
|
||||
const kinds = new Set(['lines', 'points', 'icons', 'shapes']);
|
||||
assert.ok([...draw.sets.values()].every((record) => kinds.has(record.kind)));
|
||||
const ambientPublication = hostCalls.findLast(([type, sourceId]) => (
|
||||
type === 'entries' && sourceId === ROCKET_MISSION_AMBIENT_OVERLAY_SOURCE_ID
|
||||
));
|
||||
@@ -1259,26 +1258,25 @@ test('real mission build, select, refresh, deselect, disable, and destroy paths
|
||||
collisionCapacity: ROCKET_MISSION_AMBIENT_OVERLAY_COLLISION_CAPACITY,
|
||||
moving: false,
|
||||
});
|
||||
const launchEntity = dataSources[0].entities.getById('rocket-launch:mission-runtime');
|
||||
assert.deepEqual(
|
||||
assert.equal(
|
||||
ambientPublication[2][0].position,
|
||||
launchEntity.position.getValue(Cesium.JulianDate.now()),
|
||||
'ambient host marker must reuse the entity anchor Cartesian',
|
||||
item('rocket-launch:mission-runtime').pos,
|
||||
'ambient host marker must reuse the site marker anchor',
|
||||
);
|
||||
const frameTime = Cesium.JulianDate.now();
|
||||
scene.preRender.raiseEvent(scene, frameTime);
|
||||
assert.equal(launchEntity.point.show.getValue(frameTime), true);
|
||||
camera.positionWC = Cesium.Cartesian3.fromDegrees(99.396, -28.608, 18_000_000);
|
||||
assert.equal(item('rocket-launch:mission-runtime').show, true);
|
||||
eye = fromDegrees(99.396, -28.608, 18_000_000);
|
||||
scene.preRender.raiseEvent(scene, frameTime);
|
||||
assert.equal(
|
||||
launchEntity.point.show.getValue(frameTime),
|
||||
item('rocket-launch:mission-runtime').show,
|
||||
false,
|
||||
'pre-render horizon pass must hide a rear-side depth-free mission dot before draw and pick',
|
||||
);
|
||||
camera.positionWC = Cesium.Cartesian3.fromDegrees(-80.604, 28.608, 18_000_000);
|
||||
eye = fromDegrees(-80.604, 28.608, 18_000_000);
|
||||
scene.preRender.raiseEvent(scene, frameTime);
|
||||
assert.equal(
|
||||
launchEntity.point.show.getValue(frameTime),
|
||||
item('rocket-launch:mission-runtime').show,
|
||||
true,
|
||||
'mission dot must return when its surface anchor faces the camera again',
|
||||
);
|
||||
@@ -1304,17 +1302,16 @@ test('real mission build, select, refresh, deselect, disable, and destroy paths
|
||||
&& entry.paintLane === 'selected'
|
||||
&& entry.edgeFade === 'keyhole'
|
||||
)));
|
||||
const satelliteEntity = dataSources[0].entities.getById('rocket-satellite:mission-runtime');
|
||||
const satellitePosition = satelliteEntity.position.getValue(Cesium.JulianDate.now());
|
||||
assert.equal(
|
||||
scene.preRender.raiseEvent(scene, frameTime);
|
||||
assert.deepEqual(
|
||||
selectedPublication[2][2].position(),
|
||||
satellitePosition,
|
||||
'payload host getter must return the exact per-frame live-position cache',
|
||||
item('rocket-satellite:mission-runtime').pos,
|
||||
'payload host getter must return where the frame drew the payload',
|
||||
);
|
||||
|
||||
// Jitter regression net: live-state propagation advances at most once per
|
||||
// frameNumber, and the host getter is a pure read that never advances it.
|
||||
// Without both halves, the host label and the native dot can propagate to
|
||||
// Jitter regression net: live-state propagation advances at most once a
|
||||
// frame, and the host getter is a pure read that never advances it.
|
||||
// Without both halves, the host label and the drawn dot can propagate to
|
||||
// different wall-clock instants inside one frame — the documented
|
||||
// label-separation jitter class.
|
||||
const payloadEntry = selectedPublication[2][2];
|
||||
@@ -1322,52 +1319,40 @@ test('real mission build, select, refresh, deselect, disable, and destroy paths
|
||||
try {
|
||||
let nowMs = realDateNow();
|
||||
Date.now = () => nowMs;
|
||||
scene.frameState.frameNumber = 41;
|
||||
const frameA = Cesium.Cartesian3.clone(
|
||||
satelliteEntity.position.getValue(Cesium.JulianDate.now()),
|
||||
);
|
||||
scene.preRender.raiseEvent(scene, frameTime);
|
||||
const frameA = { ...item('rocket-satellite:mission-runtime').pos };
|
||||
assert.deepEqual({ ...payloadEntry.position() }, frameA);
|
||||
nowMs += 30_000;
|
||||
assert.deepEqual(
|
||||
Cesium.Cartesian3.clone(satelliteEntity.position.getValue(Cesium.JulianDate.now())),
|
||||
{ ...payloadEntry.position() },
|
||||
frameA,
|
||||
'a second native read in the same frame must not re-propagate',
|
||||
'host getter must not advance propagation between frames',
|
||||
);
|
||||
nowMs += 30_000;
|
||||
scene.frameState.frameNumber = 42;
|
||||
scene.preRender.raiseEvent(scene, frameTime);
|
||||
const frameB = { ...item('rocket-satellite:mission-runtime').pos };
|
||||
assert.notDeepEqual(frameB, frameA, 'a new frame propagates (non-vacuous)');
|
||||
assert.deepEqual(
|
||||
Cesium.Cartesian3.clone(payloadEntry.position()),
|
||||
frameA,
|
||||
'host getter must not advance propagation, even on a new frame',
|
||||
);
|
||||
const frameB = Cesium.Cartesian3.clone(
|
||||
satelliteEntity.position.getValue(Cesium.JulianDate.now()),
|
||||
);
|
||||
assert.notDeepEqual(frameB, frameA, 'native read on a new frame propagates (non-vacuous)');
|
||||
assert.deepEqual(
|
||||
Cesium.Cartesian3.clone(payloadEntry.position()),
|
||||
{ ...payloadEntry.position() },
|
||||
frameB,
|
||||
'host getter reads the advanced cache after native propagation',
|
||||
'host getter reads the advanced cache after the frame drew it',
|
||||
);
|
||||
} finally {
|
||||
Date.now = realDateNow;
|
||||
scene.frameState.frameNumber = 1;
|
||||
}
|
||||
const reentryEntity = dataSources[0].entities.getById('rocket-reentry:mission-runtime:0');
|
||||
assert.deepEqual(
|
||||
selectedPublication[2][1].position,
|
||||
reentryEntity.polyline.positions.getValue(Cesium.JulianDate.now())[0],
|
||||
're-entry host label must reuse the recovery-path interface Cartesian',
|
||||
item('rocket-reentry:mission-runtime:0').positions[0],
|
||||
're-entry host label must reuse the recovery-path interface point',
|
||||
);
|
||||
const transferEntity = dataSources[0].entities.getById('rocket-transfer:mission-runtime');
|
||||
assert.deepEqual(
|
||||
selectedPublication[2][3].position,
|
||||
transferEntity.polyline.positions.getValue(Cesium.JulianDate.now()).at(-1),
|
||||
'orbit host label must reuse the insertion Cartesian',
|
||||
item('rocket-transfer:mission-runtime').positions.at(-1),
|
||||
'orbit host label must reuse the insertion point',
|
||||
);
|
||||
|
||||
launchName = 'Mission Refresh | Gauntlet Payload';
|
||||
await rocketLaunchesLayer.update();
|
||||
assert.ok(dataSources[0].entities.values.every((entity) => entity.label === undefined));
|
||||
assert.ok(missionItems().size >= 7);
|
||||
const refreshPublication = hostCalls.findLast(([type, sourceId]) => (
|
||||
type === 'entries' && sourceId === ROCKET_MISSION_SELECTED_OVERLAY_SOURCE_ID
|
||||
));
|
||||
@@ -1390,7 +1375,7 @@ test('real mission build, select, refresh, deselect, disable, and destroy paths
|
||||
]);
|
||||
await rocketLaunchesLayer.destroy(viewer);
|
||||
initialized = false;
|
||||
assert.equal(dataSources.length, 0);
|
||||
assert.ok([...draw.sets.values()].every((record) => record.disposed));
|
||||
assert.deepEqual(hostCalls.slice(-4), [
|
||||
['clear', ROCKET_MISSION_AMBIENT_OVERLAY_SOURCE_ID],
|
||||
['visible', ROCKET_MISSION_AMBIENT_OVERLAY_SOURCE_ID, false],
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
/**
|
||||
* @module data/stockFollow
|
||||
* @description A double-click on a layer's drawn item follows it, as the
|
||||
* default renderer's own double-click followed the entities layers drew
|
||||
* before they drew through the draw port: an item with a position is
|
||||
* followed, framed as that renderer framed an entity it started following;
|
||||
* one without (a line) is zoomed to at once instead. It runs only while the
|
||||
* renderer's own double-click follow is on (a tool can hold it off).
|
||||
*/
|
||||
import { WGS84 } from '../geo/ellipsoid.js';
|
||||
import { offsetFromHeadingPitchRange } from '../geo/frames.js';
|
||||
import { findCamera, findQuery } from '../render/rendererOf.js';
|
||||
|
||||
/** The range the default renderer frames a sphere of no size from. */
|
||||
const MINIMUM_FIT_RANGE_M = 100;
|
||||
|
||||
/**
|
||||
* Where the camera frames a part it starts following, as the default
|
||||
* renderer framed an entity it started following with no view of its own:
|
||||
* looking at the bounds' centre, heading north, pitched down 45° (steeper
|
||||
* far from the ground), at the range that fits the bounds in view, within
|
||||
* the camera's zoom limits. Returned as the eye's offset from the centre,
|
||||
* east-north-up there; `at` is where the part stands.
|
||||
* @param {{center: {x: number, y: number, z: number}, radius: number}} sphere
|
||||
* @param {{x: number, y: number, z: number}} at
|
||||
* @param {object} camera The camera port.
|
||||
*/
|
||||
export function followViewFrom(sphere, at, camera) {
|
||||
const pose = camera.pose?.();
|
||||
const fovy = Number.isFinite(pose?.fovy) ? pose.fovy : Math.PI / 3;
|
||||
const aspect = Number.isFinite(pose?.aspectRatio) ? pose.aspectRatio : 1;
|
||||
const tanPhi = Math.tan(fovy / 2);
|
||||
const tanTheta = aspect * tanPhi;
|
||||
let range =
|
||||
sphere.radius === 0
|
||||
? MINIMUM_FIT_RANGE_M
|
||||
: Math.max(sphere.radius / tanTheta, sphere.radius / tanPhi);
|
||||
const { minDistance = 0, maxDistance = Infinity } = camera.controls ?? {};
|
||||
range = Math.min(Math.max(range, minDistance), maxDistance);
|
||||
const factor =
|
||||
2 - 1 / Math.max(1, Math.hypot(at.x, at.y, at.z) / WGS84.radii.x);
|
||||
return offsetFromHeadingPitchRange(0, (-Math.PI / 4) * factor, range);
|
||||
}
|
||||
|
||||
/**
|
||||
* Follow (or zoom to) a layer's item on a double-click.
|
||||
* @param {object} options
|
||||
* @param {object} options.viewer
|
||||
* @param {(viewer: object) => object} options.inputFor The click dispatcher.
|
||||
* @param {string} options.name The layer, for warnings.
|
||||
* @param {() => boolean} options.enabled Whether the layer takes clicks now.
|
||||
* @param {(hit: import('../render/contract/query').Hit) =>
|
||||
* ({key: string, position: () => ({x: number, y: number, z: number}|null),
|
||||
* sphere?: {center: object, radius: number}}
|
||||
* | {zoomTo: {center: object, radius: number}}
|
||||
* | null)} options.targetFor What a hit on one of the layer's items is
|
||||
* followed by (`key`, its live `position`, the bounds it is framed by,
|
||||
* radius 0 by default), or zoomed to (`zoomTo`); null for anything else.
|
||||
* @returns {{readonly following: object|null, stop(): void, destroy(): void}}
|
||||
*/
|
||||
export function followOnDoubleClick({
|
||||
viewer,
|
||||
inputFor,
|
||||
name,
|
||||
enabled,
|
||||
targetFor,
|
||||
}) {
|
||||
const input = inputFor(viewer);
|
||||
/** The follow a double-click started, while the camera keeps it. */
|
||||
let follow = null;
|
||||
const off =
|
||||
input.onPointer?.('dblclick', (event) => {
|
||||
if (!enabled()) return;
|
||||
// The renderer's own double-click follow, off while a tool holds it
|
||||
// or on a renderer without one.
|
||||
if (input.stockEnabled?.('dblclickFollow') !== true) return;
|
||||
const hit = findQuery(viewer)?.pick(event.position.x, event.position.y);
|
||||
const found = hit && !hit.surface ? targetFor(hit) : null;
|
||||
if (!found) return;
|
||||
const camera = findCamera(viewer);
|
||||
if (!camera) return;
|
||||
try {
|
||||
if (found.zoomTo) {
|
||||
// As the default renderer zoomed to an entity with no position:
|
||||
// at once, north up, pitched down 45°, at the range that fits it
|
||||
// in view. Following nothing then, as that zoom stopped any
|
||||
// follow first.
|
||||
if (camera.followed) camera.follow(null);
|
||||
camera.flyToBounds(found.zoomTo, { durationS: 0 });
|
||||
return;
|
||||
}
|
||||
const at = found.position();
|
||||
if (!at) return;
|
||||
const target = {
|
||||
key: found.key,
|
||||
position: found.position,
|
||||
frame: 'enu',
|
||||
viewFrom: followViewFrom(
|
||||
found.sphere ?? { center: at, radius: 0 },
|
||||
at,
|
||||
camera,
|
||||
),
|
||||
};
|
||||
camera.follow(target);
|
||||
follow = target;
|
||||
} catch (error) {
|
||||
// A camera that cannot follow leaves the view where it is, as a
|
||||
// viewer without entity tracking did.
|
||||
console.warn(`${name}: cannot follow`, error);
|
||||
}
|
||||
}) ?? null;
|
||||
return {
|
||||
get following() {
|
||||
return follow && findCamera(viewer)?.followed === follow ? follow : null;
|
||||
},
|
||||
/** Stop a follow this started, if the camera still keeps it. */
|
||||
stop() {
|
||||
const camera = findCamera(viewer);
|
||||
if (follow && camera?.followed === follow) camera.follow(null);
|
||||
follow = null;
|
||||
},
|
||||
destroy() {
|
||||
this.stop();
|
||||
off?.();
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { followOnDoubleClick, followViewFrom } from './stockFollow.js';
|
||||
import { bindRenderer } from '../render/rendererOf.js';
|
||||
import { WGS84 } from '../geo/ellipsoid.js';
|
||||
|
||||
/** A viewer whose renderer answers picks with `hit` and records the camera. */
|
||||
function scene({ hit, stock = true, enabled = true }) {
|
||||
const viewer = {};
|
||||
const handlers = new Map();
|
||||
const calls = [];
|
||||
const camera = {
|
||||
followed: null,
|
||||
controls: { minDistance: 0, maxDistance: Infinity },
|
||||
pose: () => ({ fovy: Math.PI / 3, aspectRatio: 2 }),
|
||||
follow(target) {
|
||||
calls.push(['follow', target]);
|
||||
camera.followed = target;
|
||||
},
|
||||
flyToBounds(sphere, options) {
|
||||
calls.push(['flyToBounds', sphere, options]);
|
||||
},
|
||||
};
|
||||
const unbind = bindRenderer(viewer, {
|
||||
camera,
|
||||
query: { pick: () => hit },
|
||||
});
|
||||
const input = {
|
||||
onPointer(type, handler) {
|
||||
handlers.set(type, handler);
|
||||
return () => handlers.delete(type);
|
||||
},
|
||||
stockEnabled: (name) => name === 'dblclickFollow' && stock,
|
||||
};
|
||||
const at = { x: WGS84.radii.x, y: 0, z: 0 };
|
||||
const follow = followOnDoubleClick({
|
||||
viewer,
|
||||
inputFor: () => input,
|
||||
name: 'test-layer',
|
||||
enabled: () => enabled,
|
||||
targetFor: (picked) =>
|
||||
picked.id === 'point'
|
||||
? { key: 'layer:point', position: () => at }
|
||||
: picked.id === 'line'
|
||||
? { zoomTo: { center: at, radius: 50 } }
|
||||
: null,
|
||||
});
|
||||
const dblclick = () =>
|
||||
handlers.get('dblclick')?.({ position: { x: 1, y: 2 } });
|
||||
return { follow, camera, calls, dblclick, handlers, unbind };
|
||||
}
|
||||
|
||||
test('a double-click follows a point, framed as the default renderer framed an entity', () => {
|
||||
const s = scene({ hit: { set: 'layer', id: 'point', surface: false } });
|
||||
s.dblclick();
|
||||
const [[kind, target]] = s.calls;
|
||||
assert.equal(kind, 'follow');
|
||||
assert.equal(target.key, 'layer:point');
|
||||
assert.equal(target.frame, 'enu');
|
||||
// No size: the minimum fit range, 45 degrees down on the ground.
|
||||
const range = Math.hypot(
|
||||
target.viewFrom.x,
|
||||
target.viewFrom.y,
|
||||
target.viewFrom.z,
|
||||
);
|
||||
assert.ok(Math.abs(range - 100) < 1e-6);
|
||||
assert.ok(Math.abs(target.viewFrom.z + target.viewFrom.y) < 1e-6);
|
||||
assert.equal(s.follow.following, target);
|
||||
// Stopping ends only the follow it started.
|
||||
s.follow.stop();
|
||||
assert.equal(s.camera.followed, null);
|
||||
s.follow.destroy();
|
||||
assert.equal(s.handlers.size, 0);
|
||||
s.unbind();
|
||||
});
|
||||
|
||||
test('a double-click on a line zooms to it at once, following nothing', () => {
|
||||
const s = scene({ hit: { set: 'layer', id: 'line', surface: false } });
|
||||
s.camera.followed = { key: 'other' };
|
||||
s.dblclick();
|
||||
assert.deepEqual(
|
||||
s.calls.map(([kind]) => kind),
|
||||
['follow', 'flyToBounds'],
|
||||
);
|
||||
assert.equal(s.calls[0][1], null);
|
||||
assert.deepEqual(s.calls[1][2], { durationS: 0 });
|
||||
s.follow.destroy();
|
||||
s.unbind();
|
||||
});
|
||||
|
||||
test('no follow while the stock double-click is held off, the layer is off, or the pick is not its own', () => {
|
||||
for (const options of [
|
||||
{ hit: { id: 'point', surface: false }, stock: false },
|
||||
{ hit: { id: 'point', surface: false }, enabled: false },
|
||||
{ hit: { id: 'other', surface: false } },
|
||||
{ hit: { surface: true } },
|
||||
{ hit: null },
|
||||
]) {
|
||||
const s = scene(options);
|
||||
s.dblclick();
|
||||
assert.deepEqual(s.calls, []);
|
||||
s.follow.destroy();
|
||||
s.unbind();
|
||||
}
|
||||
});
|
||||
|
||||
test('the frame view fits a sphere and steepens far from the ground', () => {
|
||||
const camera = { pose: () => ({ fovy: Math.PI / 2, aspectRatio: 1 }) };
|
||||
const ground = { x: WGS84.radii.x, y: 0, z: 0 };
|
||||
const near = followViewFrom({ center: ground, radius: 1000 }, ground, camera);
|
||||
assert.ok(Math.abs(Math.hypot(near.x, near.y, near.z) - 1000) < 1e-6);
|
||||
const high = { x: WGS84.radii.x * 2, y: 0, z: 0 };
|
||||
const far = followViewFrom({ center: high, radius: 0 }, high, camera);
|
||||
// Looking down 45 degrees times 1.5 at twice the radius: the eye that
|
||||
// far above, south of the point.
|
||||
const elevation = Math.atan2(far.z, Math.hypot(far.x, far.y));
|
||||
assert.ok(Math.abs(elevation - (Math.PI / 4) * 1.5) < 1e-9);
|
||||
assert.ok(far.y < 0);
|
||||
});
|
||||
Reference in new issue
Block a user