From ca82e23d94277ba7dae8210827e0b951c7ee2e79 Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Wed, 11 Nov 2026 19:39:26 -0800 Subject: [PATCH] Conformance: clamped rims and walls are picked; the vector base covers string stops, no background and its restore draw.shapes.clamped picked only the outlined rectangle and the extruded ellipse; it now also picks the outline-only rectangle on its rim and the wall on its face, seen from the south. The stub picks both: a clamped outline along its ring as a draped line of its outline width, a wall where its panels cover the pixel. globe.base.vector also draws roads whose join and cap are legacy zoom functions of strings, checks that a style with no background shows the globe through rather than black, and ends by switching to a base without the vector style, which must draw none of it and drop its credit. --- src/render/conformance/checks/ports.js | 112 +++++++++++++++-- src/render/stub/index.js | 167 ++++++++++++++++++++++--- 2 files changed, 256 insertions(+), 23 deletions(-) diff --git a/src/render/conformance/checks/ports.js b/src/render/conformance/checks/ports.js index a036efabe..6f0f879fc 100644 --- a/src/render/conformance/checks/ports.js +++ b/src/render/conformance/checks/ports.js @@ -2258,7 +2258,7 @@ export function portChecks() { ), check( 'draw.shapes.clamped', - 'clamped shapes of every kind draw: outlined, outline only, extruded and walls, and the filled ones are picked', + 'clamped shapes of every kind draw and are picked: outlined, outline only (along its rim), extruded and walls', async (h, r) => { await overAustin(h, r, 3000); const shapes = r.draw.shapes({ id: 'conf:clamped-shapes' }); @@ -2322,10 +2322,7 @@ export function portChecks() { equal(shapes.size(), 4, 'every kind is taken'); await settled(r); await drawn(h, r); - for (const [id, lon, lat, height] of [ - ['outlined', AUSTIN.lon - 0.004, AUSTIN.lat + 0.002, 0], - ['tower', AUSTIN.lon - 0.004, AUSTIN.lat - 0.003, 300], - ]) { + const picked = (id, lon, lat, height) => { const s = r.query.project(h.toEcef({ lon, lat, height })); ok(s, `${id} projects`); ok( @@ -2336,7 +2333,24 @@ export function portChecks() { ), `${id} drawn and picked`, ); - } + }; + picked('outlined', AUSTIN.lon - 0.004, AUSTIN.lat + 0.002, 0); + picked('tower', AUSTIN.lon - 0.004, AUSTIN.lat - 0.003, 300); + // An outline-only shape is picked on its rim, its west edge here. + picked('rim', AUSTIN.lon + 0.004 - 0.0012, AUSTIN.lat + 0.002, 0); + // A wall, seen from the south a little above it, on its face. + r.camera.setView({ + destination: { + lon: AUSTIN.lon + 0.004, + lat: AUSTIN.lat - 0.007, + height: 120, + }, + orientation: { heading: 0, pitch: -0.2, roll: 0 }, + }); + await h.frame(r); + await settled(r); + await drawn(h, r); + picked('fence', AUSTIN.lon + 0.004, AUSTIN.lat - 0.003, 20); shapes.dispose(); }, ), @@ -4035,7 +4049,7 @@ export function portChecks() { ), check( 'globe.base.vector', - 'a vector base draws its style: the fills its filters keep, over its background; a style that fails to load changes nothing', + 'a vector base draws its style: the fills its filters keep, over its background; legacy string stops; transparent with no background; a style that fails to load changes nothing; a base without it draws none of it', async (h, r) => { await overAustin(h, r, 20000); // One tile for every tile: the whole of it sea, and a road. @@ -4048,10 +4062,25 @@ export function portChecks() { [-64, -64], ], ]; + // Roads 256 units (16 px of a 256 px tile) apart: lines 24 px wide + // cover the tile. + const roads = []; + for (let y = -256; y <= 4352; y += 256) + roads.push({ + type: 'LineString', + geometry: [ + [ + [-64, y], + [4160, y], + ], + ], + properties: { class: 'road' }, + }); const tile = encodeVectorTile({ water: [ { type: 'Polygon', geometry: whole, properties: { class: 'sea' } }, ], + roads, }); let binary = ''; for (const byte of tile) binary += String.fromCharCode(byte); @@ -4133,6 +4162,75 @@ export function portChecks() { `the base is as it was (${[red, green, blue].map(Math.round)})`, ); } + const credited = () => + r.credits.list().some((c) => /Test tiles/.test(c.text ?? '')); + const gaveCredit = credited(); + // A style with no background, whose roads join and cap by legacy + // zoom functions of strings (stepped, as the specification says, + // not interpolated): the roads are drawn, and where a layer draws + // nothing the globe shows through, never black. + const lines = (filter) => ({ + version: 8, + sources: style.sources, + layers: [ + { + id: 'roads', + type: 'line', + source: 'base', + 'source-layer': 'roads', + filter, + layout: { + 'line-join': { + stops: [ + [0, 'bevel'], + [22, 'round'], + ], + }, + 'line-cap': { + stops: [ + [0, 'butt'], + [22, 'square'], + ], + }, + }, + paint: { 'line-color': '#ff00ff', 'line-width': 24 }, + }, + ], + }); + const urlOf = (doc) => + `data:application/json,${encodeURIComponent(JSON.stringify(doc))}`; + await r.globe.setBase({ + vector: { styleUrl: urlOf(lines(['==', 'class', 'road'])) }, + }); + if (h.pixels !== false) { + const [red, green, blue] = await middle(); + ok( + red > 170 && blue > 170 && green < 90, + `roads with legacy string stops are drawn (${[red, green, blue].map(Math.round)})`, + ); + } + await r.globe.setBase({ + vector: { styleUrl: urlOf(lines(['==', 'class', 'none'])) }, + }); + if (h.pixels !== false) { + const mean = await middle(); + ok( + mean.reduce((a, b) => a + b, 0) > 40 && + !(mean[0] > 170 && mean[2] > 170), + `no background: the globe shows through, not black (${mean.map(Math.round)})`, + ); + } + // Back to a base without it: none of it drawn, its credit gone. + await r.globe.setBase({ vector: null, imagery: [] }); + equal(r.globe.imagery.list().length, 0, 'the base is restored'); + if (gaveCredit) ok(!credited(), 'its credit goes with it'); + if (h.pixels !== false) { + const [red, green, blue] = await middle(); + ok( + !(blue > 170 && green > 120) && !(red > 170 && blue > 170), + `the vector base is no longer drawn (${[red, green, blue].map(Math.round)})`, + ); + } }, { capability: 'vectorBase' }, ), diff --git a/src/render/stub/index.js b/src/render/stub/index.js index e2055ed26..a8853658d 100644 --- a/src/render/stub/index.js +++ b/src/render/stub/index.js @@ -874,6 +874,119 @@ export function createStubRenderer(options = {}) { return (along / g.semiMajor) ** 2 + (across / g.semiMinor) ** 2 <= 1; } + /** + * A draped rectangle's or ellipse's outline as a closed ring of positions + * on the ellipsoid (the rectangle turned as `inRectangle` turns it), or + * null for other geometries. + */ + function outlineRing(g) { + const points = []; + if (g?.kind === 'rectangle') { + const { rect, rotation = 0 } = g; + const span = rect.east - rect.west; + const width = span >= 360 ? 360 : ((span % 360) + 360) % 360; + const cLon = rect.west + width / 2; + const cLat = (rect.south + rect.north) / 2; + const hw = width / 2; + const hh = (rect.north - rect.south) / 2; + const cos = Math.cos(rotation); + const sin = Math.sin(rotation); + for (const [u, v] of [ + [-hw, -hh], + [hw, -hh], + [hw, hh], + [-hw, hh], + [-hw, -hh], + ]) + points.push({ + lon: cLon + cos * u - sin * v, + lat: cLat + sin * u + cos * v, + height: 0, + }); + return points; + } + if (g?.kind === 'ellipse') { + const centre = toCartographicRadians(toEcef(g.center)); + const metresPerRadian = 6378137; + const turn = g.rotation ?? 0; + for (let i = 0; i <= 64; i++) { + const theta = (i / 64) * Math.PI * 2; + const along = g.semiMajor * Math.cos(theta); + const across = g.semiMinor * Math.sin(theta); + // The inverse of `inEllipse`'s turn. + const north = along * Math.cos(turn) + across * Math.sin(turn); + const east = -along * Math.sin(turn) + across * Math.cos(turn); + points.push({ + lon: toDegrees( + centre.lon + east / (metresPerRadian * Math.cos(centre.lat)), + ), + lat: toDegrees(centre.lat + north / metresPerRadian), + height: 0, + }); + } + return points; + } + return null; + } + + /** + * Where a wall's face is under the pixel `(x, y)` (within the pick + * window, so one seen edge-on is still picked): the middle of the panel + * it is on, or null. A clamped wall stands on the stub's surface (height + * 0); its tops are its positions' heights (or `maximumHeights`). + */ + function wallHit(item, x, y, halfW, halfH) { + const { positions, minimumHeights, maximumHeights } = item.geometry; + const corner = (i, top) => + toEcef({ + lon: positions[i].lon, + lat: positions[i].lat, + height: top + ? (maximumHeights?.[i] ?? positions[i].height ?? 0) + : (minimumHeights?.[i] ?? 0), + }); + for (let i = 0; i + 1 < (positions?.length ?? 0); i++) { + const quad = [ + corner(i, false), + corner(i + 1, false), + corner(i + 1, true), + corner(i, true), + ]; + if (quad.every(isOccluded)) continue; + const screen = quad.map(project); + if (screen.some((p) => !p)) continue; + if (!inScreenQuad(screen, x, y, Math.max(halfW, halfH))) continue; + return scale( + quad.reduce((sum, p) => add(sum, p), vec(0, 0, 0)), + 1 / 4, + ); + } + return null; + } + + /** Whether `(x, y)` is in a screen quad, or within `slack` of its edges. */ + function inScreenQuad(quad, x, y, slack) { + let inside = false; + for (let i = 0, j = quad.length - 1; i < quad.length; j = i++) { + const a = quad[i]; + const b = quad[j]; + if ( + a.y > y !== b.y > y && + x < ((b.x - a.x) * (y - a.y)) / (b.y - a.y) + a.x + ) + inside = !inside; + const dx = b.x - a.x; + const dy = b.y - a.y; + const span = dx * dx + dy * dy; + const t = + span > 0 + ? Math.max(0, Math.min(1, ((x - a.x) * dx + (y - a.y) * dy) / span)) + : 0; + if (Math.hypot(a.x + dx * t - x, a.y + dy * t - y) <= slack) return true; + } + return inside; + } + /** * The pickable items under a pixel, nearest first. With a `depth`, only * the nearest `depth` things drawn there are looked through, unpickable @@ -910,31 +1023,53 @@ export function createStubRenderer(options = {}) { } if (set.kind === 'shapes') { // Draped rectangles and ellipses are picked where they cover the - // ellipsoid (rectangles turned as the default renderer turns them); - // other shapes are not picked. + // ellipsoid (rectangles turned as the default renderer turns them) + // and along their draped outline; walls where their face is; other + // shapes are not picked. const ground = rayEllipsoid(pickRay(x, y)); const at = ground && toCartographicRadians(ground); - if (!at) continue; - const lon = toDegrees(at.lon); - const lat = toDegrees(at.lat); + const lon = at && toDegrees(at.lon); + const lat = at && toDegrees(at.lat); for (const item of set.items.values()) { if (item.show === false) continue; - if (!item.fill || item.outlineOnly) continue; const g = item.geometry; + const hit = (position) => + hits.push({ + set: setId, + id: item.id, + meta: item.meta, + surface: false, + position, + depth: magnitude(sub(position, eye().position)), + blocked: blockedItem(item), + }); + const ring = + item.outline && item.height === 'clampGround' + ? outlineRing(g) + : null; + const onRing = + ring && + lineHit( + { positions: ring, widthPx: item.outlineWidth ?? 1 }, + x, + y, + Math.max(halfW, halfH), + ); + if (onRing) { + hit(onRing); + continue; + } + if (g?.kind === 'wall') { + const onWall = item.fill && wallHit(item, x, y, halfW, halfH); + if (onWall) hit(onWall); + continue; + } + if (!at || !item.fill || item.outlineOnly) continue; const covers = item.height === 'clampGround' && ((g?.kind === 'rectangle' && inRectangle(g, lon, lat)) || (g?.kind === 'ellipse' && inEllipse(g, lon, lat))); - if (!covers) continue; - hits.push({ - set: setId, - id: item.id, - meta: item.meta, - surface: false, - position: ground, - depth: magnitude(sub(ground, eye().position)), - blocked: blockedItem(item), - }); + if (covers) hit(ground); } continue; }