fix(infrastructure): test the ground, not the ellipsoid, for in-view sampling

An unsampled base sits at ellipsoid height 0. Over high terrain seen at an
angle that point projects below the screen while the ground above it is in
view, so the gate skipped ground the camera could see and never sampled it.
The gate now tests loaded globe terrain when there is some, and otherwise
the whole span of heights a sample can accept (0 to 9,000 m).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
quanticsoul4772andClaude Opus 5.5 committed 2026-10-29 01:25:57 -07:00
1 parent 189b30b545
commit ecc0ced47c
4 files changed
+106 -15

No files matched your search

+58
View File
@@ -787,6 +787,64 @@ test('an unseen base is not sampled and arms no retry until it is in view', asyn
assert.ok(Math.abs(baseHeightM(env) - 117) < 0.01);
});
for (const [label, globe] of [
['loaded terrain', { show: true, tilesLoaded: true, getHeight: () => 2_500 }],
['a hidden globe', { show: false, tilesLoaded: true, getHeight: () => undefined }],
]) {
test(`high ground in view is sampled with ${label} although its unsampled base projects off screen`, async (t) => {
// A base on 2,500 m terrain, seen from 3 km away at a shallow angle: its
// ellipsoid-height point is far below the bottom of the screen.
const env = await createRealLocalLayerHarness({
sampleHeightSupported: true, sampleHeight: () => 2_500,
});
const clock = installFakeClock(t);
t.after(() => { env.layer.destroy(env.viewer); env.cleanup(); });
env.viewer.scene.globe = globe;
const entity = env.dataSources[0].entities.values[0];
const base = Cesium.Cartographic.fromCartesian(entity.__localBaseCartesian);
const ground = Cesium.Cartesian3.fromRadians(base.longitude, base.latitude, 2_500);
const position = Cesium.Cartesian3.fromRadians(
base.longitude,
base.latitude - 3_000 / 6_371_000,
2_500 + 1_000,
);
const direction = Cesium.Cartesian3.normalize(
Cesium.Cartesian3.subtract(ground, position, new Cesium.Cartesian3()),
new Cesium.Cartesian3(),
);
const right = Cesium.Cartesian3.normalize(
Cesium.Cartesian3.cross(
direction,
Cesium.Ellipsoid.WGS84.geodeticSurfaceNormal(position),
new Cesium.Cartesian3(),
),
new Cesium.Cartesian3(),
);
const up = Cesium.Cartesian3.cross(right, direction, new Cesium.Cartesian3());
const frustum = new Cesium.PerspectiveFrustum({
fov: Math.PI / 3,
aspectRatio: 800 / 600,
near: 1,
far: 1e8,
});
Object.assign(env.viewer.camera, {
positionWC: position,
directionWC: direction,
upWC: up,
frustum,
});
const offScreen = frustum
.computeCullingVolume(position, direction, up)
.computeVisibility(new Cesium.BoundingSphere(entity.__localBaseCartesian, 1));
assert.equal(offScreen, Cesium.Intersect.OUTSIDE, 'precondition: the ellipsoid-height base is off screen');
clock.advance(2_100);
env.preRender.raise();
assert.equal(env.sampleCalls.count, 1, 'the ground in view is sampled');
assert.ok(Math.abs(baseHeightM(env) - 2_500) < 0.01);
});
}
test('settled terrain refinement lifts an already sampled stem without another GPU sample', async (t) => {
const env = await createRealLocalLayerHarness({
sampleHeightSupported: true, sampleHeight: () => 117,