Match Cesium's fromDegrees exactly and keep toEcef in the stub

fromRadians divides by gamma as Cesium does, so geodetic to ECEF is now
bit for bit Cesium's, and the test checks it exactly. Its tests also
cover three height bands, points inside the Earth and NaN input. toEcef
reads the renderer contract's Position, so it moves to the stub's maths.
The ellipsoid docs pair each conversion with Cesium's.
This commit is contained in:
Sameh Khamis committed 2026-11-05 14:28:10 -08:00
1 parent 52d82b453c
commit e32988ae5e
4 files changed
+64 -12

No files matched your search

+12 -9
View File
@@ -4,10 +4,20 @@
* (ECEF) conversions, surface normals and projection onto the surface. The
* formulas follow the default renderer's step for step, so they agree with
* it to floating-point noise.
*
* Into ECEF, positions are arguments (`fromDegrees(lon, lat, height)`,
* `fromRadians` likewise); out of it, objects (`toLonLatH` gives
* `{lon, lat, height}` in degrees, `toCartographicRadians` the same in
* radians). Cesium's `Cartographic.fromDegrees(lon, lat, h)` is plain
* `{lon: toRadians(lon), lat: toRadians(lat), height: h}`; for its ECEF
* point, use `fromDegrees`.
*
* NaN in gives NaN fields out, never a throw (Cesium's debug build throws).
* The Earth's centre, and points so near it that their squares round to
* zero, answer null, as Cesium answers undefined.
*/
import {
add,
clone,
dot,
magnitude,
normalize,
@@ -58,7 +68,7 @@ export function fromRadians(lon, lat, height = 0) {
const r = WGS84.radiiSquared;
let k = vec(r.x * n.x, r.y * n.y, r.z * n.z);
const gamma = Math.sqrt(dot(n, k));
k = scale(k, 1 / gamma);
k = vec(k.x / gamma, k.y / gamma, k.z / gamma);
return add(k, scale(n, height));
}
@@ -66,13 +76,6 @@ export function fromRadians(lon, lat, height = 0) {
export const fromDegrees = (lon, lat, height = 0) =>
fromRadians(toRadians(lon), toRadians(lat), height);
/** A position in either contract form, as ECEF. */
export function toEcef(position) {
if ('lon' in position && 'lat' in position)
return fromDegrees(position.lon, position.lat, position.height ?? 0);
return clone(position);
}
/** The point on the ellipsoid along the geodetic normal, or null at the centre. */
export function scaleToGeodeticSurface(p) {
const { x: positionX, y: positionY, z: positionZ } = p;