mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 00:32:21 +00:00
Draw tropical cyclones through the renderer's draw port
The cyclone layer no longer imports Cesium. Its advisories are three draw sets per rendering (points, lines, cones) taken from drawOf(viewer): the centers and forecast points are clamped dots culled past the horizon, the tracks and cone outlines are draped lines, and the cones are clamped polygons that keep their holes. Flights go through cameraOf, and the focus sphere comes from a port of BoundingSphere.fromPoints in src/geo/sphere.js. Clicks read the new ClickEvent.drawHit: the dispatcher's pick as the contract's Hit when it is a draw-set item. The Cesium port's query uses the same conversion, now in render/cesium/drawHit.js. pickStorm takes that hit and accepts only current items of the layer's own sets. Every advisory commit redraws the points, so an empty advisory clears them; an unchanged selection draws nothing. Far-side tracks and cones are left to the globe's depth instead of a per-frame occluder. Both cyclone files leave the Cesium allow-list.
This commit is contained in:
1 parent
bb3106991e
commit
bd5a688144
14 files changed
+818
-783
No files matched your search
@@ -0,0 +1,83 @@
|
||||
/**
|
||||
* @module geo/sphere
|
||||
* @description Bounding spheres of ECEF points, by the default renderer's
|
||||
* own method (`BoundingSphere.fromPoints`): Ritter's sphere and the box's
|
||||
* circumsphere, whichever is smaller. Same arithmetic in the same order, so
|
||||
* a camera framed on one goes where it went before.
|
||||
*/
|
||||
|
||||
const copy = (p) => ({ x: p.x, y: p.y, z: p.z });
|
||||
const squared = (a, b) =>
|
||||
(a.x - b.x) * (a.x - b.x) +
|
||||
(a.y - b.y) * (a.y - b.y) +
|
||||
(a.z - b.z) * (a.z - b.z);
|
||||
|
||||
/**
|
||||
* @param {ReadonlyArray<{x: number, y: number, z: number}>} points
|
||||
* @returns {{center: {x: number, y: number, z: number}, radius: number}}
|
||||
* Centre at the origin with radius 0 for no points.
|
||||
*/
|
||||
export function sphereFromPoints(points) {
|
||||
if (!points?.length) return { center: { x: 0, y: 0, z: 0 }, radius: 0 };
|
||||
const first = points[0];
|
||||
let xMin = copy(first);
|
||||
let yMin = copy(first);
|
||||
let zMin = copy(first);
|
||||
let xMax = copy(first);
|
||||
let yMax = copy(first);
|
||||
let zMax = copy(first);
|
||||
for (let i = 1; i < points.length; i++) {
|
||||
const p = points[i];
|
||||
if (p.x < xMin.x) xMin = copy(p);
|
||||
if (p.x > xMax.x) xMax = copy(p);
|
||||
if (p.y < yMin.y) yMin = copy(p);
|
||||
if (p.y > yMax.y) yMax = copy(p);
|
||||
if (p.z < zMin.z) zMin = copy(p);
|
||||
if (p.z > zMax.z) zMax = copy(p);
|
||||
}
|
||||
const xSpan = squared(xMax, xMin);
|
||||
const ySpan = squared(yMax, yMin);
|
||||
const zSpan = squared(zMax, zMin);
|
||||
let diameter1 = xMin;
|
||||
let diameter2 = xMax;
|
||||
let maxSpan = xSpan;
|
||||
if (ySpan > maxSpan) {
|
||||
maxSpan = ySpan;
|
||||
diameter1 = yMin;
|
||||
diameter2 = yMax;
|
||||
}
|
||||
if (zSpan > maxSpan) {
|
||||
diameter1 = zMin;
|
||||
diameter2 = zMax;
|
||||
}
|
||||
const ritter = {
|
||||
x: (diameter1.x + diameter2.x) * 0.5,
|
||||
y: (diameter1.y + diameter2.y) * 0.5,
|
||||
z: (diameter1.z + diameter2.z) * 0.5,
|
||||
};
|
||||
let radiusSquared = squared(diameter2, ritter);
|
||||
let ritterRadius = Math.sqrt(radiusSquared);
|
||||
const naive = {
|
||||
x: (xMin.x + xMax.x) * 0.5,
|
||||
y: (yMin.y + yMax.y) * 0.5,
|
||||
z: (zMin.z + zMax.z) * 0.5,
|
||||
};
|
||||
let naiveRadius = 0;
|
||||
for (const p of points) {
|
||||
const r = Math.sqrt(squared(p, naive));
|
||||
if (r > naiveRadius) naiveRadius = r;
|
||||
const toPointSquared = squared(p, ritter);
|
||||
if (toPointSquared > radiusSquared) {
|
||||
const toPoint = Math.sqrt(toPointSquared);
|
||||
ritterRadius = (ritterRadius + toPoint) * 0.5;
|
||||
radiusSquared = ritterRadius * ritterRadius;
|
||||
const oldToNew = toPoint - ritterRadius;
|
||||
ritter.x = (ritterRadius * ritter.x + oldToNew * p.x) / toPoint;
|
||||
ritter.y = (ritterRadius * ritter.y + oldToNew * p.y) / toPoint;
|
||||
ritter.z = (ritterRadius * ritter.z + oldToNew * p.z) / toPoint;
|
||||
}
|
||||
}
|
||||
return ritterRadius < naiveRadius
|
||||
? { center: ritter, radius: ritterRadius }
|
||||
: { center: naive, radius: naiveRadius };
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import * as Cesium from 'cesium';
|
||||
import test from 'node:test';
|
||||
import { fromDegrees } from './ellipsoid.js';
|
||||
import { sphereFromPoints } from './sphere.js';
|
||||
|
||||
test('a sphere from points is the default renderer’s, to the bit', () => {
|
||||
let seed = 7;
|
||||
const random = () => (seed = (seed * 16807) % 2147483647) / 2147483647;
|
||||
const cases = [
|
||||
[],
|
||||
[fromDegrees(10, 20)],
|
||||
[fromDegrees(-125.8, 15.5), fromDegrees(-130, 18), fromDegrees(-135, 21)],
|
||||
// Across the antimeridian, and a long track.
|
||||
Array.from({ length: 40 }, (_, i) => fromDegrees(170 + i, -10 + i / 2)),
|
||||
Array.from({ length: 200 }, () =>
|
||||
fromDegrees(random() * 360 - 180, random() * 180 - 90, random() * 1e5),
|
||||
),
|
||||
];
|
||||
for (const points of cases) {
|
||||
const ours = sphereFromPoints(points);
|
||||
const theirs = Cesium.BoundingSphere.fromPoints(
|
||||
points.map((p) => new Cesium.Cartesian3(p.x, p.y, p.z)),
|
||||
);
|
||||
assert.deepEqual(
|
||||
[ours.center.x, ours.center.y, ours.center.z, ours.radius],
|
||||
[theirs.center.x, theirs.center.y, theirs.center.z, theirs.radius],
|
||||
);
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user