mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Draw submarine cables through the renderer's draw and camera ports
Cable lines, landing pins, polygon fills, reference stems and reference points are now five draw sets per layer (submarine-cables:N:lines and so on) instead of GeoJSON data sources and entities. Clicks resolve through the draw hit; flights and the sweep's eye go through the camera port. The layer keeps the styling the GeoJSON loader gave it: cable colours, widths and alphas, simplestyle stroke, fill and marker properties, fills that keep the source's alpha, raised polygons at their heights, the default pin image, and features without a reference drawn but neither picked nor culled. Lines are densified along rhumb lines at the renderer's own granularity, so the draped geodesic arcs land on the same vertices the rhumb-line polylines did. Supporting pieces: - geo/rhumb, geo/horizon and geo/geodesic port the default renderer's rhumb line, ellipsoidal occluder and Vincenty inverse; the stub renderer now uses the shared horizon test and Vincenty inverse instead of its own copies. render/color gains cssColor, which reads CSS colours as the renderer does (hex, rgb, hsl; not named colours). - The Cesium draw port changes a line in place when only whether it shows changes (draped, on its ground primitive, waiting for it to be ready rather than restarting its build) or where an undraped line runs; anything else still rebuilds. Icon sets honour their blend. Ingestion, interaction, overlay, policy, rendering, state and surface no longer import Cesium and leave the allow-list. Pins are culled at the horizon each frame by the draw port instead of on the sweep, and marker-symbol glyphs are not drawn inside pins.
This commit is contained in:
1 parent
f24b66d80d
commit
e74c7c1f44
29 files changed
+2260
-2064
No files matched your search
+122
-15
@@ -148,6 +148,7 @@ export function createCesiumDraw({ scene, report }) {
|
||||
record.pickIds = [];
|
||||
record.placed = [];
|
||||
record.patchable = null;
|
||||
record.lineParts = null;
|
||||
build(record);
|
||||
setsVersion += 1;
|
||||
};
|
||||
@@ -162,7 +163,7 @@ export function createCesiumDraw({ scene, report }) {
|
||||
},
|
||||
upsert(list) {
|
||||
// Items that only change how they look are changed where they are.
|
||||
if (patchPoints(record, list)) {
|
||||
if (patchPoints(record, list) || patchLines(record, list)) {
|
||||
for (const item of list) items.set(item.id, item);
|
||||
setsVersion += 1;
|
||||
requestRender();
|
||||
@@ -190,12 +191,12 @@ export function createCesiumDraw({ scene, report }) {
|
||||
Object.assign(spec, options);
|
||||
// What clamped items clamp to, how points blend, and whether ground
|
||||
// primitives pick, are built into them. Models clamp nothing, only
|
||||
// points build in the blend, and only shapes and lines have ground
|
||||
// points and icons build in the blend, and only shapes and lines have ground
|
||||
// primitives: other kinds are not rebuilt for those (models would
|
||||
// load again).
|
||||
if (
|
||||
(kind !== 'models' && spec.clampTo !== clampTo) ||
|
||||
(kind === 'points' && spec.blend !== blend) ||
|
||||
((kind === 'points' || kind === 'icons') && spec.blend !== blend) ||
|
||||
((kind === 'shapes' || kind === 'lines') &&
|
||||
(spec.pickable !== false) !== pickable)
|
||||
)
|
||||
@@ -322,6 +323,7 @@ export function createCesiumDraw({ scene, report }) {
|
||||
for (const record of sets.values()) {
|
||||
const ground = record.pending;
|
||||
if (!ground || ground.some((p) => !p.isDestroyed() && !p.ready)) continue;
|
||||
showPending(record);
|
||||
for (const primitive of ground) primitive.show = true;
|
||||
record.pending = null;
|
||||
retire(record);
|
||||
@@ -381,7 +383,10 @@ export function createCesiumDraw({ scene, report }) {
|
||||
}
|
||||
|
||||
function buildIcons(record) {
|
||||
const host = new Cesium.BillboardCollection({ scene });
|
||||
const host = new Cesium.BillboardCollection({
|
||||
scene,
|
||||
blendOption: pointBlendOf(record.spec.blend),
|
||||
});
|
||||
record.atlases = new Set();
|
||||
for (const item of record.items.values()) {
|
||||
const image = iconImage(record, item.image);
|
||||
@@ -629,12 +634,23 @@ export function createCesiumDraw({ scene, report }) {
|
||||
function buildLines(record) {
|
||||
const host = new Cesium.PolylineCollection();
|
||||
const draped = new Map();
|
||||
// Each line as drawn, for upserts that change it in place.
|
||||
const parts = new Map();
|
||||
record.lineParts = parts;
|
||||
for (const item of record.items.values()) {
|
||||
if (item.mode === 'draped') {
|
||||
if (item.style.kind !== 'solid')
|
||||
throw new Error('the Cesium renderer drapes solid lines only');
|
||||
const clampTo = item.clampTo ?? record.spec.clampTo ?? 'both';
|
||||
if (!draped.has(clampTo)) draped.set(clampTo, []);
|
||||
const id = pickId(record, item);
|
||||
parts.set(item.id, {
|
||||
look: lineLook(item),
|
||||
positions: flatPositions(item.positions),
|
||||
clampTo,
|
||||
id,
|
||||
ground: null,
|
||||
});
|
||||
draped.get(clampTo).push(
|
||||
new Cesium.GeometryInstance({
|
||||
geometry: new Cesium.GroundPolylineGeometry({
|
||||
@@ -650,33 +666,124 @@ export function createCesiumDraw({ scene, report }) {
|
||||
item.show !== false,
|
||||
),
|
||||
},
|
||||
id: pickId(record, item),
|
||||
id,
|
||||
}),
|
||||
);
|
||||
continue;
|
||||
}
|
||||
host.add({
|
||||
const polyline = host.add({
|
||||
positions: linePositions(item),
|
||||
width: item.widthPx,
|
||||
material: lineMaterial(item.style),
|
||||
show: item.show !== false,
|
||||
id: pickId(record, item),
|
||||
});
|
||||
parts.set(item.id, { look: lineLook(item), polyline });
|
||||
}
|
||||
if (!draped.size) return replaceHost(record, host);
|
||||
// Draped lines drape as the entities' clamped polylines do.
|
||||
const ground = [...draped].map(
|
||||
([clampTo, geometryInstances]) =>
|
||||
new Cesium.GroundPolylinePrimitive({
|
||||
geometryInstances,
|
||||
appearance: new Cesium.PolylineColorAppearance(),
|
||||
classificationType: classificationOf(clampTo),
|
||||
allowPicking: record.spec.pickable !== false,
|
||||
}),
|
||||
);
|
||||
const byClamp = new Map();
|
||||
const ground = [...draped].map(([clampTo, geometryInstances]) => {
|
||||
const primitive = new Cesium.GroundPolylinePrimitive({
|
||||
geometryInstances,
|
||||
appearance: new Cesium.PolylineColorAppearance(),
|
||||
classificationType: classificationOf(clampTo),
|
||||
allowPicking: record.spec.pickable !== false,
|
||||
});
|
||||
byClamp.set(clampTo, primitive);
|
||||
return primitive;
|
||||
});
|
||||
for (const part of parts.values())
|
||||
if (part.clampTo) part.ground = byClamp.get(part.clampTo);
|
||||
replaceHost(record, collect(host, ground), ground, host);
|
||||
}
|
||||
|
||||
/**
|
||||
* How a line draws, but for where it runs and whether it shows: lines
|
||||
* that keep it can be changed in place.
|
||||
*/
|
||||
const lineLook = (item) =>
|
||||
JSON.stringify([
|
||||
item.mode,
|
||||
item.widthPx,
|
||||
item.clampTo,
|
||||
item.style,
|
||||
item.depthFailColor,
|
||||
item.segmentColors,
|
||||
item.segmentShow,
|
||||
item.revealFraction,
|
||||
item.frame,
|
||||
]);
|
||||
|
||||
/** A line's positions as one flat array of numbers, to compare. */
|
||||
function flatPositions(positions) {
|
||||
if (positions instanceof Float64Array) return Array.from(positions);
|
||||
const flat = [];
|
||||
for (const p of positions)
|
||||
if ('x' in p) flat.push(p.x, p.y, p.z);
|
||||
else flat.push(p.lon, p.lat, p.height ?? 0, NaN);
|
||||
return flat;
|
||||
}
|
||||
|
||||
const samePositions = (a, b) =>
|
||||
a.length === b.length && a.every((value, i) => Object.is(value, b[i]));
|
||||
|
||||
/**
|
||||
* Upsert lines in place, without a rebuild, when every item is drawn now
|
||||
* and looks the same: then only whether it shows, its `meta`, and where
|
||||
* a line not draped runs change. A draped line keeps its positions, and
|
||||
* its ground primitive must be ready. False, changing nothing, otherwise.
|
||||
*/
|
||||
function patchLines(record, list) {
|
||||
const parts = record.lineParts;
|
||||
if (record.kind !== 'lines' || !parts) return false;
|
||||
for (const item of list) {
|
||||
const was = parts.get(item.id);
|
||||
if (!was || was.look !== lineLook(item)) return false;
|
||||
if (
|
||||
was.ground &&
|
||||
(was.ground.isDestroyed() ||
|
||||
(!was.ground.ready && !record.pending?.includes(was.ground)) ||
|
||||
!samePositions(flatPositions(item.positions), was.positions))
|
||||
)
|
||||
return false;
|
||||
}
|
||||
for (const item of list) {
|
||||
const was = parts.get(item.id);
|
||||
const show = item.show !== false;
|
||||
if (was.polyline) {
|
||||
was.polyline.positions = linePositions(item);
|
||||
was.polyline.show = show;
|
||||
was.polyline.id.meta = item.meta;
|
||||
continue;
|
||||
}
|
||||
was.id.meta = item.meta;
|
||||
// A ground primitive still building takes its show once it is ready
|
||||
// (`swapReady`), so a show change never restarts the build.
|
||||
if (was.ground.ready) showPart(was, show);
|
||||
else was.pendingShow = show;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/** A draped line part's show, on its ready ground primitive. */
|
||||
function showPart(part, show) {
|
||||
const attributes = part.ground.getGeometryInstanceAttributes(part.id);
|
||||
attributes.show = Cesium.ShowGeometryInstanceAttribute.toValue(
|
||||
show,
|
||||
attributes.show,
|
||||
);
|
||||
}
|
||||
|
||||
/** The shows patched in while a set's ground primitives were building. */
|
||||
function showPending(record) {
|
||||
for (const part of record.lineParts?.values() ?? [])
|
||||
if (part.pendingShow !== undefined && !part.ground.isDestroyed()) {
|
||||
showPart(part, part.pendingShow);
|
||||
part.pendingShow = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
/** One host for a set's own collection and its ground primitives. */
|
||||
function collect(own, ground) {
|
||||
const host = new Cesium.PrimitiveCollection();
|
||||
|
||||
@@ -1097,3 +1097,133 @@ test('the context layer draws its rim as an outlined ellipse on a viewer of its
|
||||
rendering.disposeVisual();
|
||||
assert.equal(other.added.length, 0);
|
||||
});
|
||||
|
||||
/** Run `fn` with the image classes Cesium's materials test uniforms against. */
|
||||
function withImageClasses(fn) {
|
||||
const names = [
|
||||
'HTMLCanvasElement',
|
||||
'HTMLImageElement',
|
||||
'ImageBitmap',
|
||||
'OffscreenCanvas',
|
||||
];
|
||||
const real = names.map((name) => globalThis[name]);
|
||||
for (const name of names) globalThis[name] ??= class {};
|
||||
try {
|
||||
return fn();
|
||||
} finally {
|
||||
names.forEach((name, i) => (globalThis[name] = real[i]));
|
||||
}
|
||||
}
|
||||
|
||||
test('lines that change only whether they show, or where an undraped one runs, change in place', () =>
|
||||
withImageClasses(() => {
|
||||
const { scene, draw, frame } = drawOver();
|
||||
const set = draw.lines({ id: 'patched' });
|
||||
const draped = (id, show = true, meta) => ({
|
||||
id,
|
||||
positions: [
|
||||
{ lon: 0, lat: 0 },
|
||||
{ lon: 1, lat: 1 },
|
||||
],
|
||||
widthPx: 2.5,
|
||||
mode: 'draped',
|
||||
style: { kind: 'solid', color: '#7fe6ed' },
|
||||
show,
|
||||
meta,
|
||||
});
|
||||
const stem = (id, height, show = true) => ({
|
||||
id,
|
||||
positions: [
|
||||
Cesium.Cartesian3.fromDegrees(0, 0, 0),
|
||||
Cesium.Cartesian3.fromDegrees(0, 0, height),
|
||||
],
|
||||
widthPx: 2,
|
||||
mode: '3d',
|
||||
style: { kind: 'solid', color: [1, 1, 1, 0.5] },
|
||||
show,
|
||||
meta: height,
|
||||
});
|
||||
const attributes = new Map();
|
||||
const fakeAttributes = (ground) => {
|
||||
ground.getGeometryInstanceAttributes = (id) => {
|
||||
if (!attributes.has(id.id))
|
||||
attributes.set(id.id, { show: new Uint8Array([1]) });
|
||||
return attributes.get(id.id);
|
||||
};
|
||||
};
|
||||
set.set([draped('a'), draped('b'), stem('s', 100)]);
|
||||
const host = scene.added[0];
|
||||
const ground = host.get(1);
|
||||
fakeAttributes(ground);
|
||||
// Still building: the show waits for the ground, and the build goes on.
|
||||
set.upsert([draped('a', false)]);
|
||||
assert.equal(scene.added[0], host, 'not rebuilt while its ground builds');
|
||||
assert.equal(attributes.size, 0);
|
||||
Object.defineProperty(ground, 'ready', { value: true });
|
||||
frame();
|
||||
assert.deepEqual([...attributes.get('a').show], [0], 'shown once ready');
|
||||
set.upsert([draped('b', false)]);
|
||||
assert.equal(scene.added[0], host, 'changed in place once ready');
|
||||
assert.deepEqual([...attributes.get('b').show], [0]);
|
||||
set.upsert([draped('b', true, 'new')]);
|
||||
assert.deepEqual([...attributes.get('b').show], [1]);
|
||||
const [, idB] = ground.geometryInstances.map((instance) => instance.id);
|
||||
assert.equal(idB.meta, 'new', 'picks read the new meta');
|
||||
// An undraped line moves and hides in place, and keeps its new meta.
|
||||
const line = host.get(0).get(0);
|
||||
set.upsert([stem('s', 2500, false)]);
|
||||
assert.equal(scene.added[0], host);
|
||||
assert.equal(host.get(0).get(0), line);
|
||||
assert.equal(line.show, false);
|
||||
assert.equal(line.id.meta, 2500);
|
||||
assert.ok(
|
||||
Cesium.Cartesian3.equalsEpsilon(
|
||||
line.positions[1],
|
||||
Cesium.Cartesian3.fromDegrees(0, 0, 2500),
|
||||
1e-6,
|
||||
),
|
||||
);
|
||||
// One item that cannot change in place rebuilds them all, and patches
|
||||
// none of the others first.
|
||||
set.upsert([
|
||||
draped('a'),
|
||||
{
|
||||
...draped('b'),
|
||||
positions: [
|
||||
{ lon: 0, lat: 0 },
|
||||
{ lon: 2, lat: 2 },
|
||||
],
|
||||
},
|
||||
]);
|
||||
assert.deepEqual([...attributes.get('a').show], [0], 'not patched');
|
||||
assert.notEqual(scene.added.at(-1), host, 'a draped line that moves');
|
||||
const moved = scene.added.at(-1);
|
||||
set.upsert([{ ...stem('s', 2500), widthPx: 3 }]);
|
||||
assert.notEqual(scene.added.at(-1), moved, 'a line that looks different');
|
||||
// A ground primitive gone from under the set rebuilds too.
|
||||
const third = scene.added.at(-1);
|
||||
third.get(1).destroy();
|
||||
set.upsert([draped('a', false)]);
|
||||
assert.notEqual(scene.added.at(-1), third, 'its ground destroyed');
|
||||
set.dispose();
|
||||
}));
|
||||
|
||||
test('icons blend as their set says', () => {
|
||||
const { scene, draw } = drawOver();
|
||||
const set = draw.icons({ id: 'pins', blend: 'translucent' });
|
||||
set.set([
|
||||
{
|
||||
id: 'a',
|
||||
pos: { lon: 0, lat: 0 },
|
||||
image: 'pin.png',
|
||||
size: [6, 6],
|
||||
},
|
||||
]);
|
||||
assert.equal(scene.added[0].blendOption, Cesium.BlendOption.TRANSLUCENT);
|
||||
set.setOptions({ blend: undefined });
|
||||
assert.equal(
|
||||
scene.added[0].blendOption,
|
||||
Cesium.BlendOption.OPAQUE_AND_TRANSLUCENT,
|
||||
);
|
||||
set.dispose();
|
||||
});
|
||||
@@ -126,13 +126,6 @@
|
||||
"src/layers/streetLevel/selection.js",
|
||||
"src/layers/streetLevel/sequenceCones.js",
|
||||
"src/layers/streetLevel/view.js",
|
||||
"src/layers/submarineCables/ingestion.js",
|
||||
"src/layers/submarineCables/interaction.js",
|
||||
"src/layers/submarineCables/overlay.js",
|
||||
"src/layers/submarineCables/policy.js",
|
||||
"src/layers/submarineCables/rendering.js",
|
||||
"src/layers/submarineCables/state.js",
|
||||
"src/layers/submarineCables/surface.js",
|
||||
"src/layers/traffic/animation.js",
|
||||
"src/layers/traffic/flow.js",
|
||||
"src/layers/traffic/footprint.js",
|
||||
|
||||
@@ -13,3 +13,74 @@ export function hexColor(hex, alpha = 1) {
|
||||
alpha,
|
||||
];
|
||||
}
|
||||
|
||||
// The default renderer's own patterns, so a colour reads as it read there.
|
||||
const SHORT_HEX = /^#([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])?$/i;
|
||||
const LONG_HEX = /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})?$/i;
|
||||
const RGB =
|
||||
/^rgba?\s*\(\s*([0-9.]+%?)\s*[,\s]+\s*([0-9.]+%?)\s*[,\s]+\s*([0-9.]+%?)(?:\s*[,\s/]+\s*([0-9.]+))?\s*\)$/i;
|
||||
const HSL =
|
||||
/^hsla?\s*\(\s*([0-9.]+)\s*[,\s]+\s*([0-9.]+%)\s*[,\s]+\s*([0-9.]+%)(?:\s*[,\s/]+\s*([0-9.]+))?\s*\)$/i;
|
||||
|
||||
function hueToRgb(m1, m2, h) {
|
||||
if (h < 0) h += 1;
|
||||
if (h > 1) h -= 1;
|
||||
if (h * 6 < 1) return m1 + (m2 - m1) * 6 * h;
|
||||
if (h * 2 < 1) return m2;
|
||||
if (h * 3 < 2) return m1 + (m2 - m1) * (2 / 3 - h) * 6;
|
||||
return m1;
|
||||
}
|
||||
|
||||
const rgbChannel = (text) =>
|
||||
Number.parseFloat(text) / (text.endsWith('%') ? 100 : 255);
|
||||
|
||||
/**
|
||||
* A CSS colour (`#rgb`, `#rgba`, `#rrggbb`, `#rrggbbaa`, `rgb()`, `rgba()`,
|
||||
* `hsl()`, `hsla()`) as a renderer colour, read as the default renderer
|
||||
* reads it; null for anything else (named colours included).
|
||||
*/
|
||||
export function cssColor(text) {
|
||||
const css = String(text ?? '').trim();
|
||||
let m = SHORT_HEX.exec(css);
|
||||
if (m)
|
||||
return [
|
||||
Number.parseInt(m[1], 16) / 15,
|
||||
Number.parseInt(m[2], 16) / 15,
|
||||
Number.parseInt(m[3], 16) / 15,
|
||||
Number.parseInt(m[4] ?? 'f', 16) / 15,
|
||||
];
|
||||
m = LONG_HEX.exec(css);
|
||||
if (m)
|
||||
return [
|
||||
Number.parseInt(m[1], 16) / 255,
|
||||
Number.parseInt(m[2], 16) / 255,
|
||||
Number.parseInt(m[3], 16) / 255,
|
||||
Number.parseInt(m[4] ?? 'ff', 16) / 255,
|
||||
];
|
||||
m = RGB.exec(css);
|
||||
if (m)
|
||||
return [
|
||||
rgbChannel(m[1]),
|
||||
rgbChannel(m[2]),
|
||||
rgbChannel(m[3]),
|
||||
Number.parseFloat(m[4] ?? '1.0'),
|
||||
];
|
||||
m = HSL.exec(css);
|
||||
if (!m) return null;
|
||||
const hue = (Number.parseFloat(m[1]) / 360) % 1;
|
||||
const saturation = Number.parseFloat(m[2]) / 100;
|
||||
const lightness = Number.parseFloat(m[3]) / 100;
|
||||
const alpha = Number.parseFloat(m[4] ?? '1.0');
|
||||
if (saturation === 0) return [lightness, lightness, lightness, alpha];
|
||||
const m2 =
|
||||
lightness < 0.5
|
||||
? lightness * (1 + saturation)
|
||||
: lightness + saturation - lightness * saturation;
|
||||
const m1 = 2 * lightness - m2;
|
||||
return [
|
||||
hueToRgb(m1, m2, hue + 1 / 3),
|
||||
hueToRgb(m1, m2, hue),
|
||||
hueToRgb(m1, m2, hue - 1 / 3),
|
||||
alpha,
|
||||
];
|
||||
}
|
||||
@@ -6,3 +6,26 @@ test('hex colours become renderer colours at the given alpha', () => {
|
||||
assert.deepEqual(hexColor('#ff8000'), [1, 128 / 255, 0, 1]);
|
||||
assert.deepEqual(hexColor('#000000', 0.25), [0, 0, 0, 0.25]);
|
||||
});
|
||||
|
||||
test('CSS colours read as the default renderer reads them', async () => {
|
||||
const Cesium = await import('cesium');
|
||||
const { cssColor } = await import('./color.js');
|
||||
for (const css of [
|
||||
'#39d5ff',
|
||||
' #8fffd2 ',
|
||||
'#abc',
|
||||
'#abcd',
|
||||
'#11223344',
|
||||
'rgb(10, 20, 30)',
|
||||
'rgba(10,20,30,0.5)',
|
||||
'rgb(10% 20% 30% / 0.25)',
|
||||
'hsl(120, 50%, 25%)',
|
||||
'hsla(300, 100%, 75%, 0.4)',
|
||||
'hsl(30, 0%, 40%)',
|
||||
]) {
|
||||
const c = Cesium.Color.fromCssColorString(css);
|
||||
assert.deepEqual(cssColor(css), [c.red, c.green, c.blue, c.alpha], css);
|
||||
}
|
||||
assert.equal(cssColor('not a colour'), null);
|
||||
assert.equal(cssColor(undefined), null);
|
||||
});
|
||||
@@ -1,95 +1,17 @@
|
||||
/**
|
||||
* @module render/stub/geodesic
|
||||
* @description The point a fraction of the way along the WGS84 geodesic
|
||||
* between two places: Vincenty's inverse formula, then the series the
|
||||
* default renderer interpolates with, term for term, so a rectangle's
|
||||
* centre matches its to floating-point noise.
|
||||
* between two places: Vincenty's inverse formula (`geo/geodesic`), then
|
||||
* the series the default renderer interpolates with, term for term, so a
|
||||
* rectangle's centre matches its to floating-point noise.
|
||||
*/
|
||||
import { TWO_PI, WGS84 } from './math.js';
|
||||
import { deltaLambda, geodesicInverse as inverse } from '../../geo/geodesic.js';
|
||||
import { WGS84 } from './math.js';
|
||||
|
||||
const EPSILON12 = 1e-12;
|
||||
const A = WGS84.radii.x;
|
||||
const B = WGS84.radii.z;
|
||||
const F = (A - B) / A;
|
||||
|
||||
function deltaLambda(sineAlpha, cos2Alpha, sigma, sinSigma, cosSigma, cos2Sm) {
|
||||
const C = (F * cos2Alpha * (4 + F * (4 - 3 * cos2Alpha))) / 16;
|
||||
return (
|
||||
(1 - C) *
|
||||
F *
|
||||
sineAlpha *
|
||||
(sigma + C * sinSigma * (cos2Sm + C * cosSigma * (2 * cos2Sm * cos2Sm - 1)))
|
||||
);
|
||||
}
|
||||
|
||||
/** Distance, start heading and u² of the geodesic from (lon1, lat1) to (lon2, lat2), radians. */
|
||||
function inverse(lon1, lat1, lon2, lat2) {
|
||||
const l = lon2 - lon1;
|
||||
const u1 = Math.atan((1 - F) * Math.tan(lat1));
|
||||
const u2 = Math.atan((1 - F) * Math.tan(lat2));
|
||||
const cosU1 = Math.cos(u1);
|
||||
const sinU1 = Math.sin(u1);
|
||||
const cosU2 = Math.cos(u2);
|
||||
const sinU2 = Math.sin(u2);
|
||||
const cc = cosU1 * cosU2;
|
||||
const cs = cosU1 * sinU2;
|
||||
const ss = sinU1 * sinU2;
|
||||
const sc = sinU1 * cosU2;
|
||||
let lambda = l;
|
||||
let lambdaDot = TWO_PI;
|
||||
let cosLambda;
|
||||
let sinLambda;
|
||||
let sigma;
|
||||
let cosSigma;
|
||||
let sinSigma;
|
||||
let cos2Alpha;
|
||||
let cos2Sm;
|
||||
do {
|
||||
cosLambda = Math.cos(lambda);
|
||||
sinLambda = Math.sin(lambda);
|
||||
const temp = cs - sc * cosLambda;
|
||||
sinSigma = Math.sqrt(cosU2 * cosU2 * sinLambda * sinLambda + temp * temp);
|
||||
cosSigma = ss + cc * cosLambda;
|
||||
sigma = Math.atan2(sinSigma, cosSigma);
|
||||
let sineAlpha;
|
||||
if (sinSigma === 0) {
|
||||
sineAlpha = 0;
|
||||
cos2Alpha = 1;
|
||||
} else {
|
||||
sineAlpha = (cc * sinLambda) / sinSigma;
|
||||
cos2Alpha = 1 - sineAlpha * sineAlpha;
|
||||
}
|
||||
lambdaDot = lambda;
|
||||
cos2Sm = cosSigma - (2 * ss) / cos2Alpha;
|
||||
if (!isFinite(cos2Sm)) cos2Sm = 0;
|
||||
lambda =
|
||||
l + deltaLambda(sineAlpha, cos2Alpha, sigma, sinSigma, cosSigma, cos2Sm);
|
||||
} while (Math.abs(lambda - lambdaDot) > EPSILON12);
|
||||
const uSquared = (cos2Alpha * (A * A - B * B)) / (B * B);
|
||||
const bigA =
|
||||
1 +
|
||||
(uSquared * (4096 + uSquared * (uSquared * (320 - 175 * uSquared) - 768))) /
|
||||
16384;
|
||||
const bigB =
|
||||
(uSquared * (256 + uSquared * (uSquared * (74 - 47 * uSquared) - 128))) /
|
||||
1024;
|
||||
const cos2Sm2 = cos2Sm * cos2Sm;
|
||||
const deltaSigma =
|
||||
bigB *
|
||||
sinSigma *
|
||||
(cos2Sm +
|
||||
(bigB *
|
||||
(cosSigma * (2 * cos2Sm2 - 1) -
|
||||
(bigB * cos2Sm * (4 * sinSigma * sinSigma - 3) * (4 * cos2Sm2 - 3)) /
|
||||
6)) /
|
||||
4);
|
||||
return {
|
||||
distance: B * bigA * (sigma - deltaSigma),
|
||||
startHeading: Math.atan2(cosU2 * sinLambda, cs - sc * cosLambda),
|
||||
uSquared,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* The longitude and latitude (radians) `fraction` of the way along the
|
||||
* geodesic from (lon1, lat1) to (lon2, lat2).
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
* Nothing runs on its own: `testing.tick()` and `testing.advance()` drive the
|
||||
* loop on a virtual clock, one frame at a time, in the contract's order.
|
||||
*/
|
||||
import { horizonFrom } from '../../geo/horizon.js';
|
||||
import { createInputRouter } from '../input/router.js';
|
||||
import { CAPABILITIES, CONTRACT_VERSION } from '../contract/index.js';
|
||||
import { createStubCamera } from './camera.js';
|
||||
@@ -27,7 +28,6 @@ import {
|
||||
toDegrees,
|
||||
toEcef,
|
||||
vec,
|
||||
WGS84,
|
||||
} from './math.js';
|
||||
|
||||
const FRAME_MS = 1000 / 60;
|
||||
@@ -504,15 +504,7 @@ export function createStubRenderer(options = {}) {
|
||||
}
|
||||
|
||||
function isOccluded(position) {
|
||||
const e = eye();
|
||||
const r = WGS84.oneOverRadii;
|
||||
const cv = vec(e.position.x * r.x, e.position.y * r.y, e.position.z * r.z);
|
||||
const vh = dot(cv, cv) - 1;
|
||||
const t = vec(position.x * r.x, position.y * r.y, position.z * r.z);
|
||||
const vt = sub(t, cv);
|
||||
const vtDotVc = -dot(vt, cv);
|
||||
if (vh < 0) return vtDotVc > 0;
|
||||
return vtDotVc > vh && (vtDotVc * vtDotVc) / dot(vt, vt) > vh;
|
||||
return !horizonFrom(eye().position).isPointVisible(position);
|
||||
}
|
||||
|
||||
let scriptedPicks = null;
|
||||
|
||||
@@ -70,6 +70,7 @@ const DRAW_FROM_CALLER = new Set([
|
||||
'./layers/gnss',
|
||||
'./layers/perimeters',
|
||||
'./layers/awareness',
|
||||
'./layers/submarine-cables',
|
||||
]);
|
||||
|
||||
const pkg = JSON.parse(readFileSync(path.join(root, 'package.json'), 'utf8'));
|
||||
|
||||
Reference in new issue
Block a user