mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 00:32:21 +00:00
Move satellites per-frame positions in place and tighten the guard
Add fromDegreesInto to geo/ellipsoid: the same steps as fromDegrees in the same order, so the same bits, written into a given object. The dense catalog sweep and the tracked-frame sample use it instead of allocating a fresh point for every move. The off-Cesium guard now also catches member reads on the dot, ring and tracked-entity handles through optional chaining or brackets, handles taken into local names, destructured or spread, and checks its own patterns against examples of what they must and must not catch.
This commit is contained in:
1 parent
4fd1a850f1
commit
3abb05ec4b
5 files changed
+133
-11
No files matched your search
@@ -110,6 +110,43 @@ export function fromRadians(lon, lat, height = 0) {
|
||||
export const fromDegrees = (lon, lat, height = 0) =>
|
||||
fromRadians(toRadians(lon), toRadians(lat), height);
|
||||
|
||||
/**
|
||||
* `fromDegrees` written into `out` (any object with x, y, z) without
|
||||
* allocating, for per-frame paths. Same steps in the same order, so the
|
||||
* same bits.
|
||||
* @template {{x: number, y: number, z: number}} T
|
||||
* @param {number} lon
|
||||
* @param {number} lat
|
||||
* @param {number} height
|
||||
* @param {T} out
|
||||
* @returns {T}
|
||||
*/
|
||||
export function fromDegreesInto(lon, lat, height, out) {
|
||||
const lonR = toRadians(lon);
|
||||
const latR = toRadians(lat);
|
||||
const cosLat = Math.cos(latR);
|
||||
let nx = cosLat * Math.cos(lonR);
|
||||
let ny = cosLat * Math.sin(lonR);
|
||||
let nz = Math.sin(latR);
|
||||
const m = Math.sqrt(nx * nx + ny * ny + nz * nz);
|
||||
nx /= m;
|
||||
ny /= m;
|
||||
nz /= m;
|
||||
const r = WGS84.radiiSquared;
|
||||
let kx = r.x * nx;
|
||||
let ky = r.y * ny;
|
||||
let kz = r.z * nz;
|
||||
const gamma = Math.sqrt(nx * kx + ny * ky + nz * kz);
|
||||
kx /= gamma;
|
||||
ky /= gamma;
|
||||
kz /= gamma;
|
||||
const h = height ?? 0;
|
||||
out.x = kx + nx * h;
|
||||
out.y = ky + ny * h;
|
||||
out.z = kz + nz * h;
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* A position as ECEF (a new object): `{lon, lat, height?}` (degrees, metres
|
||||
* above the ellipsoid) or `{x, y, z}`, the render contract's `Position`.
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
eastNorthUp,
|
||||
ellipsoidOf,
|
||||
fromDegrees,
|
||||
fromDegreesInto,
|
||||
geodeticSurfaceNormal,
|
||||
lerpInto,
|
||||
offsetEllipsoid,
|
||||
@@ -79,6 +80,34 @@ test('geodetic to ECEF matches the default renderer', () => {
|
||||
}
|
||||
});
|
||||
|
||||
test('geodetic to ECEF in place gives the same bits, into the object given', () => {
|
||||
const out = { x: 0, y: 0, z: 0 };
|
||||
const cartesian = new Cesium.Cartesian3();
|
||||
for (const p of points()) {
|
||||
const at = `${p.lon},${p.lat},${p.height}`;
|
||||
assert.equal(fromDegreesInto(p.lon, p.lat, p.height, out), out, at);
|
||||
assert.deepEqual(
|
||||
{ ...out },
|
||||
{ ...fromDegrees(p.lon, p.lat, p.height) },
|
||||
at,
|
||||
);
|
||||
assert.equal(
|
||||
fromDegreesInto(p.lon, p.lat, p.height, cartesian),
|
||||
cartesian,
|
||||
at,
|
||||
);
|
||||
assert.ok(
|
||||
Cesium.Cartesian3.equals(
|
||||
cartesian,
|
||||
Cesium.Cartesian3.fromDegrees(p.lon, p.lat, p.height),
|
||||
),
|
||||
at,
|
||||
);
|
||||
}
|
||||
fromDegreesInto(10, 20, undefined, out);
|
||||
assert.deepEqual({ ...out }, { ...fromDegrees(10, 20) });
|
||||
});
|
||||
|
||||
test('ECEF to geodetic matches the default renderer', () => {
|
||||
for (const p of points()) {
|
||||
const ecef = Cesium.Cartesian3.fromDegrees(p.lon, p.lat, p.height);
|
||||
|
||||
Reference in new issue
Block a user