Wind streamlines over part of the globe on the Cesium renderer

A windStreamlines grid short of 360 degrees of longitude is no longer
refused: the paths seed inside its rectangle, equal-area, and stop at its
edges. The baker takes the rectangle as optional bounds; a grid round the
globe bakes as it did.
This commit is contained in:
Sameh Khamis committed 2026-11-11 17:14:56 -08:00
1 parent 1cc9c45418
commit 20138cb313
4 files changed
+79 -29

No files matched your search

+10 -7
View File
@@ -177,17 +177,20 @@ export function createWindStreamlines({
function buildCells() {
clear();
const started = performance.now();
// The paths are traced round the whole globe, the wind wrapping east and
// west: a grid that does not span it is refused, not drawn wrapped.
// A grid round the whole globe wraps the wind east and west; one over
// part of it seeds inside it, and its paths stop at its edges.
const grid = windGridOf(current);
const { west, east } = current.rectangle;
if ((east < west ? east + 360 : east) - west < 360 - 1e-9)
throw new RangeError(
'the Cesium renderer draws wind streamlines over the whole globe only',
);
const { west, south, north } = current.rectangle;
const east =
current.rectangle.east < west
? current.rectangle.east + 360
: current.rectangle.east;
const bounds =
east - west >= 360 - 1e-9 ? null : { west, south, east, north };
const paths = bakeWindStreamlines(grid, {
count: current.pathBudget,
steps: current.steps,
bounds,
});
// A grid no path runs through is refused, so its caller can draw it
// some other way.
+31 -8
View File
@@ -381,15 +381,13 @@ test('the Cesium fields draw wind streamlines under their id until disposed', ()
assert.equal(h.members.size, 0);
});
test('a grid short of the whole globe is refused, not drawn wrapped', () => {
test('a grid over part of the globe draws inside it, not wrapped', () => {
const h = harness();
for (const rectangle of [
{ west: -100, south: -90, east: 80, north: 90 },
// Four columns over 300°: its samples nearly span the globe; it does not.
{ west: -150, south: -90, east: 150, north: 90 },
])
assert.throws(() => h.make({ rectangle }), /whole globe only/);
assert.equal(h.members.size, 0);
const part = h.make({
rectangle: { west: -100, south: -40, east: 80, north: 60 },
});
assert.ok(h.members.size > 0, 'drawn');
part.dispose();
const across = h.make({
rectangle: { west: 0, south: -90, east: -0.000000000001, north: 90 },
});
@@ -397,6 +395,31 @@ test('a grid short of the whole globe is refused, not drawn wrapped', () => {
across.dispose();
});
test('paths over part of the globe seed and stay inside it', () => {
const bounds = { west: 170, south: -20, east: 230, north: 30 };
const field = {
nx: 7,
ny: 6,
lo1: 170,
la1: 30,
dx: 10,
dy: 10,
u: new Float32Array(42).fill(40),
v: new Float32Array(42).fill(5),
};
const paths = bakeWindStreamlines(field, { count: 400, bounds });
assert.ok(paths.length > 100, `${paths.length} paths`);
for (const path of paths)
for (const [lon, lat] of path.coordinates) {
assert.ok(lat >= bounds.south && lat <= bounds.north, `lat ${lat}`);
const east = (((lon - bounds.west) % 360) + 360) % 360;
assert.ok(east <= bounds.east - bounds.west, `lon ${lon}`);
}
// Without bounds, seeds fill the globe as they did.
const global = bakeWindStreamlines(grid(), { count: 50 });
assert.ok(global.some((p) => Math.abs(p.coordinates[0][1]) > 60));
});
test('a rebuild that fails draws nothing and is never told drawn', () => {
const reported = [];
const h = harness();