fix(street-level): Panoramax IC8 review — line geometry budget, caches, attribution, tests

From a five-lens IC8 review (correctness, security, tests with mutation
testing, performance, UX):
- P0: over Paris at 12–60 km the unsimplified z10–z12 lines sent ~2M
  points to Cesium's ground-polyline builder (gigabytes of geometry; the
  tab hung). decode.js now simplifies lines (Douglas–Peucker, 4 tile
  units: 6–10% of the points), and lineCoverage gains an opt-in point
  budget (`maxPoints`, 10,000 a tile for Panoramax).
- Decoded coverage tiles are kept (KartaView's tile cache moves to the
  shared tileCache.js); a sequence's z15 picture lists are kept and load
  on their own connection; cones know their tiles from the start of a
  load, so a picture opening meanwhile re-centres them and ‹ › no longer
  restarts the load.
- The HD panorama loads only for the expanded viewer (a docked one on a
  dense screen asked for 3 MB originals) and is aborted when another
  photo opens; picture files over 48 MB or 16,384 px are refused; a
  bitmap no renderer took after a context loss is closed.
- A nearest lookup survives one of its two searches failing; only a
  timeout is retried; offline reads as unreachable; Retry-After is
  capped at five minutes; the search box stays on the map at ±180°;
  cones near both edges of a narrow (high-latitude) tile read both.
- Every producer is credited (app and photographer); with none to name,
  the caption says "via <instance>" rather than crediting the host.
- Esc anywhere in the docked viewer (toolbar, caption) clears the
  sequence before the panel takes it. A filter that hides every density
  dot says so; wording aligned ("coverage", "photo").
- Tests for every surviving mutant (Esc consumed, keepOrder and dot-size
  wiring, licence in the core, limiter aborts, radius floor, bbox corner,
  first-producer-only, byte and size caps), a limiter test, and a gate
  fixture that answers box searches and leaves out pictures facing away;
  the gate now clicks over the other sequence's pictures, so only the
  line click's own-sequence lookup can pass.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Said TurkseverandClaude Opus 5.5 committed 2026-10-14 15:24:13 +01:00
1 parent 5526666894
commit cf502429a3
29 files changed
+1153 -216

No files matched your search

@@ -1,7 +1,49 @@
import { PbfReader } from 'pbf';
import { VectorTile } from '@mapbox/vector-tile';
import { tileLocalToLonLat } from '../../tileMath.js';
import { OVERVIEW_BINS_PER_AXIS, panoramaxTimeMs } from './policy.js';
import {
OVERVIEW_BINS_PER_AXIS,
SIMPLIFY_TOLERANCE_UNITS,
panoramaxTimeMs,
} from './policy.js';
/**
* Douglas–Peucker in tile units: the points of `line` ({x, y}) that keep
* it within `tolerance` of the original, first and last always kept.
* Iterative, so a long track cannot overflow the stack.
*/
export function simplifyLine(line, tolerance) {
if (line.length < 3 || !(tolerance > 0)) return line;
const keep = new Uint8Array(line.length);
keep[0] = 1;
keep[line.length - 1] = 1;
const spans = [[0, line.length - 1]];
while (spans.length) {
const [from, to] = spans.pop();
const a = line[from];
const b = line[to];
const dx = b.x - a.x;
const dy = b.y - a.y;
const span = Math.hypot(dx, 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);
if (d > farthest) {
farthest = d;
far = i;
}
}
if (far === -1) continue;
keep[far] = 1;
spans.push([from, far], [far, to]);
}
return line.filter((_, i) => keep[i]);
}
/** Epoch ms of a sequence's day ('2025-08-11'), or 0 when undated. */
function dayMs(value) {
@@ -36,6 +78,8 @@ export function decodeCoverageTile(bytes, address) {
const props = feature.properties || {};
const parts = [];
let length = 0;
const tolerance =
(SIMPLIFY_TOLERANCE_UNITS * sequences.extent) / 4096;
for (const line of feature.loadGeometry()) {
if (line.length < 2) continue;
for (let k = 1; k < line.length; k++)
@@ -43,8 +87,10 @@ export function decodeCoverageTile(bytes, address) {
line[k].x - line[k - 1].x,
line[k].y - line[k - 1].y,
);
// Simplified before anything else: GPS tracks carry a point every
// few metres, and each becomes ~8 ground-line vertices on the GPU.
parts.push(
line.map((point) =>
simplifyLine(line, tolerance).map((point) =>
tileLocalToLonLat(point.x, point.y, sequences.extent, x, y, z),
),
);