mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
fix(street-level): Panoramax IC8 round 2 — shared point budget, selected line, cone cache, DP segments
From the round-2 verification (approve with follow-ups), all follow-ups: - The point budget is shared across the tiles in view once loading settles (water-filling): a sparse tile keeps what it has, a dense city centre takes the rest instead of drawing thinner than its suburbs. The selected sequence is always drawn, and selecting one a cap had left out draws it. - The cones' picture-list cache keeps only finished lists: a re-centre while the cones loaded inherited the aborted load's tiles and drew none in them. - Douglas–Peucker measures to the segment, so dead ends and U-turns keep their far end. - Switching Panoramax off lets its decoded tiles and lists go. - Picture downloads are counted while they stream (a host sending no length cannot fill memory before the cap). - Comments on the via caption and the simplification tolerance match the code. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
1a546bec72
commit
3ae367d0dd
11 files changed
+343
-33
No files matched your search
@@ -9,7 +9,8 @@ import {
|
||||
|
||||
/**
|
||||
* Douglas–Peucker in tile units: the points of `line` ({x, y}) that keep
|
||||
* it within `tolerance` of the original, first and last always kept.
|
||||
* it within `tolerance` of the original (measured to each segment, so
|
||||
* dead ends and U-turns stay), first and last always kept.
|
||||
* Iterative, so a long track cannot overflow the stack.
|
||||
*/
|
||||
export function simplifyLine(line, tolerance) {
|
||||
@@ -24,15 +25,20 @@ export function simplifyLine(line, tolerance) {
|
||||
const b = line[to];
|
||||
const dx = b.x - a.x;
|
||||
const dy = b.y - a.y;
|
||||
const span = Math.hypot(dx, dy);
|
||||
const span2 = dx * dx + dy * dy;
|
||||
let far = -1;
|
||||
let farthest = tolerance;
|
||||
for (let i = from + 1; i < to; i++) {
|
||||
const p = line[i];
|
||||
// Distance to the chord, or to `a` where the chord has no length.
|
||||
const d = span
|
||||
? Math.abs((p.x - a.x) * dy - (p.y - a.y) * dx) / span
|
||||
: Math.hypot(p.x - a.x, p.y - a.y);
|
||||
// Distance to the segment, not the infinite line: a dead end or a
|
||||
// U-turn (a point beyond the chord's ends) is kept.
|
||||
const t = span2
|
||||
? Math.max(
|
||||
0,
|
||||
Math.min(1, ((p.x - a.x) * dx + (p.y - a.y) * dy) / span2),
|
||||
)
|
||||
: 0;
|
||||
const d = Math.hypot(p.x - (a.x + t * dx), p.y - (a.y + t * dy));
|
||||
if (d > farthest) {
|
||||
farthest = d;
|
||||
far = i;
|
||||
|
||||
@@ -216,6 +216,13 @@ test('lines are simplified within a few tile units, ends and corners kept', () =
|
||||
];
|
||||
assert.equal(simplifyLine(loop, 4).length, 3);
|
||||
assert.equal(simplifyLine(zigzag, 0).length, 1000, 'no tolerance, no change');
|
||||
// A dead end: out to 100 and back to 50 keeps its far end.
|
||||
const deadEnd = [
|
||||
{ x: 0, y: 0 },
|
||||
{ x: 100, y: 0 },
|
||||
{ x: 50, y: 0 },
|
||||
];
|
||||
assert.deepEqual(simplifyLine(deadEnd, 4), deadEnd);
|
||||
});
|
||||
|
||||
test('a decoded GPS track keeps a fraction of its points', () => {
|
||||
|
||||
@@ -286,11 +286,15 @@ export function createPanoramaxProvider({
|
||||
});
|
||||
/** A z15 tile's pictures of one sequence, by `z/x/y:sequence`. */
|
||||
const pictureLists = createLru(PICTURE_LIST_CACHE_SIZE);
|
||||
function picturesIn(tile, sequenceId, signal) {
|
||||
/**
|
||||
* Only finished lists are kept: a load in flight belongs to its own
|
||||
* selection, whose abort (a re-centre) must not empty the next one's.
|
||||
*/
|
||||
async function picturesIn(tile, sequenceId, signal) {
|
||||
const key = `${tileKey(tile)}:${sequenceId}`;
|
||||
const kept = pictureLists.get(key);
|
||||
if (kept) return kept;
|
||||
const list = readable(async () =>
|
||||
const list = await readable(async () =>
|
||||
decodePictures(
|
||||
await source.getTile(tile, { signal, lane: 'pictures' }),
|
||||
tile,
|
||||
@@ -298,7 +302,6 @@ export function createPanoramaxProvider({
|
||||
),
|
||||
);
|
||||
pictureLists.set(key, list);
|
||||
list.catch(() => pictureLists.delete(key));
|
||||
return list;
|
||||
}
|
||||
|
||||
@@ -418,6 +421,9 @@ export function createPanoramaxProvider({
|
||||
cones.setVisible(false);
|
||||
drawn = null;
|
||||
preferred = null;
|
||||
// Off: decoded tiles and lists go (several MB each over a city).
|
||||
coverageTiles.clear();
|
||||
pictureLists.clear();
|
||||
},
|
||||
|
||||
destroy(cesiumViewer) {
|
||||
|
||||
@@ -62,8 +62,8 @@ export const COVERAGE_TUNING = Object.freeze({
|
||||
});
|
||||
/**
|
||||
* Lines are simplified (Douglas–Peucker) to this many tile units of a
|
||||
* 4,096 extent: under a pixel at every height lines are drawn from, and
|
||||
* 6–10% of the points GPS tracks carry.
|
||||
* 4,096 extent: about a pixel where each zoom is drawn (1.6 m at z14,
|
||||
* within GPS noise), and 6–10% of the points GPS tracks carry.
|
||||
*/
|
||||
export const SIMPLIFY_TOLERANCE_UNITS = 4;
|
||||
/**
|
||||
@@ -280,8 +280,8 @@ export function normalizeItem(item) {
|
||||
isPano: isEquirectangular(item),
|
||||
capturedAt: panoramaxTimeMs(props.datetime),
|
||||
creator: creatorOf(item),
|
||||
// Licences ask for the source to be named: the instance holding it is
|
||||
// named beside an author, or alone where the author is hidden.
|
||||
// Licences ask for the source to be named: where no author can be
|
||||
// named, the caption names the instance holding the picture.
|
||||
via: instanceOf(item),
|
||||
license: licenseLabel(props.license),
|
||||
width: Number.isFinite(width) && width > 0 ? width : null,
|
||||
|
||||
@@ -927,19 +927,89 @@ test('lines keep the decoded (longest-first) order under a budget of points', as
|
||||
assert.ok(COVERAGE_TUNING.maxPoints > 0);
|
||||
});
|
||||
|
||||
test('a coverage tile decoded a moment ago is not fetched or decoded again', async (t) => {
|
||||
test('a coverage tile decoded a moment ago is not fetched again; switched off, the tiles are let go', async (t) => {
|
||||
const env = coverageSetup(t, { sequences: [line('a')] });
|
||||
let asked = 0;
|
||||
const asked = [];
|
||||
const getTile = env.source.getTile;
|
||||
env.source.getTile = (tile, options) => {
|
||||
asked++;
|
||||
asked.push(`${tile.z}/${tile.x}/${tile.y}`);
|
||||
return getTile(tile, options);
|
||||
};
|
||||
env.instance.activate(env.viewer);
|
||||
assert.ok(await until(() => env.instance.coverageStats().count === 1));
|
||||
const first = asked;
|
||||
const z14 = asked.length;
|
||||
// Up a zoom band and back down: the z14 tile comes from memory.
|
||||
env.viewer.view.height = 3_000;
|
||||
env.instance.refreshCoverage();
|
||||
assert.ok(await until(() => env.instance.coverageStats().zoom === 13));
|
||||
assert.ok(await until(() => !env.instance.coverageStats().loading));
|
||||
const withZ13 = asked.length;
|
||||
env.viewer.view.height = 900;
|
||||
env.instance.refreshCoverage();
|
||||
assert.ok(await until(() => env.instance.coverageStats().zoom === 14));
|
||||
assert.ok(await until(() => env.instance.coverageStats().count === 1));
|
||||
assert.equal(asked.length, withZ13, 'nothing fetched again');
|
||||
assert.ok(z14 > 0);
|
||||
// Off and on: the memory went back, so the tile is fetched again.
|
||||
env.instance.deactivate();
|
||||
env.instance.activate(env.viewer);
|
||||
assert.ok(await until(() => env.instance.coverageStats().count === 1));
|
||||
assert.equal(asked, first);
|
||||
assert.ok(asked.length > withZ13);
|
||||
});
|
||||
|
||||
test('a re-centre while the cones still load does not inherit the aborted load’s tiles', async (t) => {
|
||||
const items = sequence('long', 400);
|
||||
const tiles = pictureTiles(items);
|
||||
const env = await mounted({ items, tiles });
|
||||
const cones = await withCones(t, env);
|
||||
let hold = null;
|
||||
env.source.getTile = async (tile, { signal } = {}) => {
|
||||
env.source.calls.tiles.push(`${tile.z}/${tile.x}/${tile.y}`);
|
||||
if (hold) await hold.promise;
|
||||
signal?.throwIfAborted();
|
||||
return tiles(tile);
|
||||
};
|
||||
await env.instance.viewer.open('long-0');
|
||||
const tileOf = (item) => {
|
||||
const [lon, lat] = item.geometry.coordinates;
|
||||
return pictureTilesAround({ lon, lat })[0];
|
||||
};
|
||||
const first = new Set(
|
||||
pictureTilesAround({
|
||||
lon: items[0].geometry.coordinates[0],
|
||||
lat: items[0].geometry.coordinates[1],
|
||||
}).map((tile) => `${tile.x}/${tile.y}`),
|
||||
);
|
||||
const out = items.findIndex((item) => {
|
||||
const tile = tileOf(item);
|
||||
return !first.has(`${tile.x}/${tile.y}`);
|
||||
});
|
||||
hold = {};
|
||||
hold.promise = new Promise((resolve) => (hold.release = resolve));
|
||||
const loading = env.instance.selectSequence('long');
|
||||
await new Promise((resolve) => setTimeout(resolve, 5));
|
||||
// The far picture opens while the first load is held: the cones re-centre.
|
||||
await env.instance.viewer.open(`long-${out}`);
|
||||
await new Promise((resolve) => setTimeout(resolve, 5));
|
||||
const release = hold.release;
|
||||
hold = null;
|
||||
release();
|
||||
await loading;
|
||||
assert.ok(await until(() => !env.instance.sequenceStats().loading));
|
||||
// Every picture in the tiles the second load covers has its cone.
|
||||
const [lon, lat] = items[out].geometry.coordinates;
|
||||
const second = new Set(
|
||||
pictureTilesAround({ lon, lat }).map((tile) => `${tile.x}/${tile.y}`),
|
||||
);
|
||||
const ids = new Set(cones.ids());
|
||||
const covered = items.filter((item) => {
|
||||
const tile = tileOf(item);
|
||||
return second.has(`${tile.x}/${tile.y}`);
|
||||
});
|
||||
assert.ok(covered.length > 0);
|
||||
assert.equal(
|
||||
covered.filter((item) => ids.has(item.id)).length,
|
||||
covered.length,
|
||||
'every picture in the re-centred tiles has its cone (the shared ones too)',
|
||||
);
|
||||
});
|
||||
Reference in new issue
Block a user