mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
Cut duplicated and dead code across the engines, the layers and the QA scripts
- src/geo drops the ported debug argument checks and the tests that bitExact already covers; package boundaries accept a directory entry, so src/geo/ is listed once per group. - Cesium no longer carries movers and lines nobody draws with: they are optional engine capabilities. The fake engine and the Cesium camera use the shared cameraMath; unused contract tables, clock.ticked, the 'finest' surface detail and Navara click statistics are gone. - ALPR keeps one overlay core and one presentation model for both engines, bikeshare one station bookkeeping, the Navara ground effects one definition helper; image atlases, view centres, mover banks and colours are shared. - The legacy switch route, the clock offset and rate controls and other unused exports are removed. - The acceptance runs the Navara draw, geo import and scope checks; scenarios use the harness switch and page helpers; the main chunk check keeps the size budget only and runs once in CI.
This commit is contained in:
1 parent
c502404e1d
commit
7abf74518f
272 files changed
+4828
-10213
No files matched your search
@@ -1,12 +1,15 @@
|
||||
// Seeded, deterministic bit-for-bit comparison of src/geo against Cesium.
|
||||
// Seeded, deterministic bit-for-bit comparison of src/geo against Cesium's
|
||||
// release build (Build/Cesium, debug checks stripped, as production ships it).
|
||||
// Every number is compared with Object.is (so -0 and NaN count), a throw on one
|
||||
// side must be a throw on the other, and `result` aliasing is exercised the
|
||||
// same way on both sides.
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import * as Cesium from 'cesium';
|
||||
import { createRequire } from 'node:module';
|
||||
import * as geo from './index.js';
|
||||
|
||||
const Cesium = createRequire(import.meta.url)('cesium/Build/Cesium/index.cjs');
|
||||
|
||||
const {
|
||||
cartesian3: c3,
|
||||
cartographic,
|
||||
@@ -108,7 +111,7 @@ const cesium = (v) => new C3(v.x, v.y, v.z);
|
||||
|
||||
test('vector operations, including -0 inputs and aliased results, equal Cesium bit for bit', () => {
|
||||
const { scalar, vector } = inputs(1);
|
||||
// Directionless vectors first: normalize must throw on both sides.
|
||||
// Directionless vectors first: normalize returns NaN on both sides.
|
||||
const DEGENERATE = [
|
||||
{ x: 0, y: 0, z: 0 },
|
||||
{ x: -0, y: 0, z: -0 },
|
||||
@@ -397,12 +400,7 @@ test('matrices and quaternions, including aliased results and every fromRotation
|
||||
][i % 4];
|
||||
const angle =
|
||||
i % 8 < 4 ? Math.PI - 0.5 * random() : (random() - 0.5) * 2 * Math.PI;
|
||||
let m;
|
||||
try {
|
||||
m = rotation(axis, angle);
|
||||
} catch {
|
||||
continue; // a zero axis: Cesium throws, nothing to compare
|
||||
}
|
||||
const m = rotation(axis, angle);
|
||||
const trace = m[0] + m[4] + m[8];
|
||||
branches.add(
|
||||
trace > 0
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
// Ported from CesiumJS 1.138 (Apache-2.0) — BoundingSphere.js subset.
|
||||
// Exact mission framing: Ritter/box fit and the union of two spheres.
|
||||
import * as Cartesian3 from './cartesian3.js';
|
||||
import { Check } from './check.js';
|
||||
import { DEBUG } from './debug.js';
|
||||
const defined = (value) => value !== null && value !== undefined;
|
||||
export function create(center = Cartesian3.ZERO, radius = 0) {
|
||||
return { center: Cartesian3.clone(center), radius };
|
||||
@@ -184,11 +182,6 @@ export function fromPoints(positions, result) {
|
||||
return result;
|
||||
}
|
||||
export function union(left, right, result) {
|
||||
if (DEBUG) {
|
||||
Check.typeOf.object('left', left);
|
||||
Check.typeOf.object('right', right);
|
||||
}
|
||||
|
||||
if (!defined(result)) {
|
||||
result = create();
|
||||
}
|
||||
|
||||
+1
-11
@@ -1,17 +1,12 @@
|
||||
// Ported from CesiumJS 1.138 (Apache-2.0) — Cartesian2.js
|
||||
//
|
||||
// 2D vectors (screen coordinates) as plain-data {x, y} objects. With DEBUG on
|
||||
// (development and tests; see debug.js) invalid arguments throw the same
|
||||
// DeveloperError as Cesium's debug checks.
|
||||
// 2D vectors (screen coordinates) as plain-data {x, y} objects.
|
||||
//
|
||||
// Geo values are not Object.prototype objects, so src/app/stateChannel.js
|
||||
// copyState and src/director/documentFields.js jsonTree reject them: copy
|
||||
// the fields into a literal before putting one into product state or a
|
||||
// scene document.
|
||||
|
||||
import { DEBUG } from './debug.js';
|
||||
import { Check } from './check.js';
|
||||
|
||||
// Values are instances of a module-private constructor rather than object
|
||||
// literals: every `{x, y}` literal in the process shares one V8 hidden
|
||||
// class, and code elsewhere that builds such literals would make geo's hot
|
||||
@@ -38,11 +33,6 @@ export function clone(cartesian, result) {
|
||||
|
||||
/** The distance between two points. */
|
||||
export function distance(left, right) {
|
||||
if (DEBUG) {
|
||||
Check.typeOf.object('left', left);
|
||||
Check.typeOf.object('right', right);
|
||||
}
|
||||
|
||||
const x = left.x - right.x;
|
||||
const y = left.y - right.y;
|
||||
return Math.sqrt(x * x + y * y);
|
||||
|
||||
+3
-144
@@ -3,19 +3,14 @@
|
||||
// 3D vectors as plain-data {x, y, z} objects. Arithmetic takes a required `result`
|
||||
// (as Cesium does) that may be one of the inputs; creators take an optional
|
||||
// one. The operation order matches Cesium so the outputs are bit-identical.
|
||||
// With DEBUG on (development and tests; see debug.js) invalid arguments throw
|
||||
// the same DeveloperError as Cesium's debug checks, and `normalize` throws on a
|
||||
// zero or non-finite vector; production builds skip the checks and return NaN
|
||||
// components there, as release Cesium does.
|
||||
// As in release Cesium, arguments are not checked and `normalize` returns NaN
|
||||
// components for a zero or non-finite vector.
|
||||
//
|
||||
// Geo values are not Object.prototype objects, so src/app/stateChannel.js
|
||||
// copyState and src/director/documentFields.js jsonTree reject them: copy
|
||||
// the fields into a literal before putting one into product state or a
|
||||
// scene document.
|
||||
|
||||
import { DEBUG } from './debug.js';
|
||||
import { Check } from './check.js';
|
||||
import { DeveloperError } from './developerError.js';
|
||||
import { equalsEpsilon as scalarEqualsEpsilon, toRadians } from './math.js';
|
||||
|
||||
// Values are instances of a module-private constructor rather than object
|
||||
@@ -59,10 +54,6 @@ export const UNIT_Y = Object.freeze(create(0.0, 1.0, 0.0));
|
||||
export const UNIT_Z = Object.freeze(create(0.0, 0.0, 1.0));
|
||||
|
||||
export function magnitudeSquared(cartesian) {
|
||||
if (DEBUG) {
|
||||
Check.typeOf.object('cartesian', cartesian);
|
||||
}
|
||||
|
||||
return (
|
||||
cartesian.x * cartesian.x +
|
||||
cartesian.y * cartesian.y +
|
||||
@@ -77,60 +68,29 @@ export function magnitude(cartesian) {
|
||||
const distanceScratch = create();
|
||||
|
||||
export function distance(left, right) {
|
||||
if (DEBUG) {
|
||||
Check.typeOf.object('left', left);
|
||||
Check.typeOf.object('right', right);
|
||||
}
|
||||
|
||||
subtract(left, right, distanceScratch);
|
||||
return magnitude(distanceScratch);
|
||||
}
|
||||
|
||||
export function distanceSquared(left, right) {
|
||||
if (DEBUG) {
|
||||
Check.typeOf.object('left', left);
|
||||
Check.typeOf.object('right', right);
|
||||
}
|
||||
|
||||
subtract(left, right, distanceScratch);
|
||||
return magnitudeSquared(distanceScratch);
|
||||
}
|
||||
|
||||
/** The unit vector; with DEBUG on, throws when the vector has no direction (zero or non-finite). */
|
||||
/** The unit vector; NaN components when the vector has no direction (zero or non-finite). */
|
||||
export function normalize(cartesian, result) {
|
||||
if (DEBUG) {
|
||||
Check.typeOf.object('cartesian', cartesian);
|
||||
Check.typeOf.object('result', result);
|
||||
}
|
||||
|
||||
const length = magnitude(cartesian);
|
||||
result.x = cartesian.x / length;
|
||||
result.y = cartesian.y / length;
|
||||
result.z = cartesian.z / length;
|
||||
if (DEBUG) {
|
||||
if (isNaN(result.x) || isNaN(result.y) || isNaN(result.z)) {
|
||||
throw new DeveloperError('normalized result is not a number');
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
export function dot(left, right) {
|
||||
if (DEBUG) {
|
||||
Check.typeOf.object('left', left);
|
||||
Check.typeOf.object('right', right);
|
||||
}
|
||||
|
||||
return left.x * right.x + left.y * right.y + left.z * right.z;
|
||||
}
|
||||
|
||||
export function multiplyComponents(left, right, result) {
|
||||
if (DEBUG) {
|
||||
Check.typeOf.object('left', left);
|
||||
Check.typeOf.object('right', right);
|
||||
Check.typeOf.object('result', result);
|
||||
}
|
||||
|
||||
result.x = left.x * right.x;
|
||||
result.y = left.y * right.y;
|
||||
result.z = left.z * right.z;
|
||||
@@ -138,12 +98,6 @@ export function multiplyComponents(left, right, result) {
|
||||
}
|
||||
|
||||
export function add(left, right, result) {
|
||||
if (DEBUG) {
|
||||
Check.typeOf.object('left', left);
|
||||
Check.typeOf.object('right', right);
|
||||
Check.typeOf.object('result', result);
|
||||
}
|
||||
|
||||
result.x = left.x + right.x;
|
||||
result.y = left.y + right.y;
|
||||
result.z = left.z + right.z;
|
||||
@@ -151,12 +105,6 @@ export function add(left, right, result) {
|
||||
}
|
||||
|
||||
export function subtract(left, right, result) {
|
||||
if (DEBUG) {
|
||||
Check.typeOf.object('left', left);
|
||||
Check.typeOf.object('right', right);
|
||||
Check.typeOf.object('result', result);
|
||||
}
|
||||
|
||||
result.x = left.x - right.x;
|
||||
result.y = left.y - right.y;
|
||||
result.z = left.z - right.z;
|
||||
@@ -164,12 +112,6 @@ export function subtract(left, right, result) {
|
||||
}
|
||||
|
||||
export function multiplyByScalar(cartesian, scalar, result) {
|
||||
if (DEBUG) {
|
||||
Check.typeOf.object('cartesian', cartesian);
|
||||
Check.typeOf.number('scalar', scalar);
|
||||
Check.typeOf.object('result', result);
|
||||
}
|
||||
|
||||
result.x = cartesian.x * scalar;
|
||||
result.y = cartesian.y * scalar;
|
||||
result.z = cartesian.z * scalar;
|
||||
@@ -177,12 +119,6 @@ export function multiplyByScalar(cartesian, scalar, result) {
|
||||
}
|
||||
|
||||
export function divideByScalar(cartesian, scalar, result) {
|
||||
if (DEBUG) {
|
||||
Check.typeOf.object('cartesian', cartesian);
|
||||
Check.typeOf.number('scalar', scalar);
|
||||
Check.typeOf.object('result', result);
|
||||
}
|
||||
|
||||
result.x = cartesian.x / scalar;
|
||||
result.y = cartesian.y / scalar;
|
||||
result.z = cartesian.z / scalar;
|
||||
@@ -190,11 +126,6 @@ export function divideByScalar(cartesian, scalar, result) {
|
||||
}
|
||||
|
||||
export function negate(cartesian, result) {
|
||||
if (DEBUG) {
|
||||
Check.typeOf.object('cartesian', cartesian);
|
||||
Check.typeOf.object('result', result);
|
||||
}
|
||||
|
||||
result.x = -cartesian.x;
|
||||
result.y = -cartesian.y;
|
||||
result.z = -cartesian.z;
|
||||
@@ -204,25 +135,12 @@ export function negate(cartesian, result) {
|
||||
const lerpScratch = create();
|
||||
|
||||
export function lerp(start, end, t, result) {
|
||||
if (DEBUG) {
|
||||
Check.typeOf.object('start', start);
|
||||
Check.typeOf.object('end', end);
|
||||
Check.typeOf.number('t', t);
|
||||
Check.typeOf.object('result', result);
|
||||
}
|
||||
|
||||
multiplyByScalar(end, t, lerpScratch);
|
||||
result = multiplyByScalar(start, 1.0 - t, result);
|
||||
return add(lerpScratch, result, result);
|
||||
}
|
||||
|
||||
export function cross(left, right, result) {
|
||||
if (DEBUG) {
|
||||
Check.typeOf.object('left', left);
|
||||
Check.typeOf.object('right', right);
|
||||
Check.typeOf.object('result', result);
|
||||
}
|
||||
|
||||
const leftX = left.x;
|
||||
const leftY = left.y;
|
||||
const leftZ = left.z;
|
||||
@@ -241,12 +159,6 @@ export function cross(left, right, result) {
|
||||
}
|
||||
|
||||
export function midpoint(left, right, result) {
|
||||
if (DEBUG) {
|
||||
Check.typeOf.object('left', left);
|
||||
Check.typeOf.object('right', right);
|
||||
Check.typeOf.object('result', result);
|
||||
}
|
||||
|
||||
result.x = (left.x + right.x) * 0.5;
|
||||
result.y = (left.y + right.y) * 0.5;
|
||||
result.z = (left.z + right.z) * 0.5;
|
||||
@@ -292,11 +204,6 @@ let scratchK = create();
|
||||
|
||||
/** The Earth-fixed position of a geodetic one in radians on the ellipsoid (WGS84 by default). */
|
||||
export function fromRadians(longitude, latitude, height, ellipsoid, result) {
|
||||
if (DEBUG) {
|
||||
Check.typeOf.number('longitude', longitude);
|
||||
Check.typeOf.number('latitude', latitude);
|
||||
}
|
||||
|
||||
height = height ?? 0.0;
|
||||
const radiiSquared =
|
||||
ellipsoid == null ? WGS84_RADII_SQUARED : ellipsoid.radiiSquared;
|
||||
@@ -318,11 +225,6 @@ export function fromRadians(longitude, latitude, height, ellipsoid, result) {
|
||||
|
||||
/** The Earth-fixed position of a geodetic one in degrees on the ellipsoid (WGS84 by default). */
|
||||
export function fromDegrees(longitude, latitude, height, ellipsoid, result) {
|
||||
if (DEBUG) {
|
||||
Check.typeOf.number('longitude', longitude);
|
||||
Check.typeOf.number('latitude', latitude);
|
||||
}
|
||||
|
||||
longitude = toRadians(longitude);
|
||||
latitude = toRadians(latitude);
|
||||
return fromRadians(longitude, latitude, height, ellipsoid, result);
|
||||
@@ -330,15 +232,6 @@ export function fromDegrees(longitude, latitude, height, ellipsoid, result) {
|
||||
|
||||
/** Positions from a flat [lon, lat, lon, lat, …] list in degrees, at height 0. */
|
||||
export function fromDegreesArray(coordinates, ellipsoid, result) {
|
||||
if (DEBUG) {
|
||||
Check.defined('coordinates', coordinates);
|
||||
if (coordinates.length < 2 || coordinates.length % 2 !== 0) {
|
||||
throw new DeveloperError(
|
||||
'the number of coordinates must be a multiple of 2 and at least 2',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const length = coordinates.length;
|
||||
if (result == null) {
|
||||
result = new Array(length / 2);
|
||||
@@ -358,43 +251,9 @@ export function fromDegreesArray(coordinates, ellipsoid, result) {
|
||||
return result;
|
||||
}
|
||||
|
||||
/** Positions from a flat [lon, lat, height, …] list in degrees and metres. */
|
||||
export function fromDegreesArrayHeights(coordinates, ellipsoid, result) {
|
||||
if (DEBUG) {
|
||||
Check.defined('coordinates', coordinates);
|
||||
if (coordinates.length < 3 || coordinates.length % 3 !== 0) {
|
||||
throw new DeveloperError(
|
||||
'the number of coordinates must be a multiple of 3 and at least 3',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const length = coordinates.length;
|
||||
if (result == null) {
|
||||
result = new Array(length / 3);
|
||||
} else {
|
||||
result.length = length / 3;
|
||||
}
|
||||
for (let i = 0; i < length; i += 3) {
|
||||
const index = i / 3;
|
||||
result[index] = fromDegrees(
|
||||
coordinates[i],
|
||||
coordinates[i + 1],
|
||||
coordinates[i + 2],
|
||||
ellipsoid,
|
||||
result[index],
|
||||
);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
const angleBetweenScratch = create();
|
||||
const angleBetweenScratch2 = create();
|
||||
export function angleBetween(left, right) {
|
||||
if (DEBUG) {
|
||||
Check.typeOf.object('left', left);
|
||||
Check.typeOf.object('right', right);
|
||||
}
|
||||
normalize(left, angleBetweenScratch);
|
||||
normalize(right, angleBetweenScratch2);
|
||||
const cosine = dot(angleBetweenScratch, angleBetweenScratch2);
|
||||
|
||||
@@ -21,78 +21,16 @@ const same = (ours, theirs, label) =>
|
||||
label,
|
||||
);
|
||||
|
||||
test('binary vector ops equal Cesium bit for bit', () => {
|
||||
for (const a of SAMPLES)
|
||||
for (const b of SAMPLES) {
|
||||
for (const op of ['add', 'subtract', 'cross', 'multiplyComponents']) {
|
||||
same(
|
||||
c3[op](asPlain(a), asPlain(b), c3.create()),
|
||||
C[op](asCesium(a), asCesium(b), new C()),
|
||||
`${op}`,
|
||||
);
|
||||
}
|
||||
assert.equal(
|
||||
c3.dot(asPlain(a), asPlain(b)),
|
||||
C.dot(asCesium(a), asCesium(b)),
|
||||
);
|
||||
assert.equal(
|
||||
c3.distance(asPlain(a), asPlain(b)),
|
||||
C.distance(asCesium(a), asCesium(b)),
|
||||
);
|
||||
assert.equal(
|
||||
c3.distanceSquared(asPlain(a), asPlain(b)),
|
||||
C.distanceSquared(asCesium(a), asCesium(b)),
|
||||
);
|
||||
same(
|
||||
c3.lerp(asPlain(a), asPlain(b), 0.3, c3.create()),
|
||||
C.lerp(asCesium(a), asCesium(b), 0.3, new C()),
|
||||
'lerp',
|
||||
);
|
||||
same(
|
||||
c3.midpoint(asPlain(a), asPlain(b), c3.create()),
|
||||
C.midpoint(asCesium(a), asCesium(b), new C()),
|
||||
'midpoint',
|
||||
);
|
||||
assert.equal(
|
||||
c3.equalsEpsilon(asPlain(a), asPlain(b), 1e-7),
|
||||
C.equalsEpsilon(asCesium(a), asCesium(b), 1e-7),
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('unary ops and scalars equal Cesium', () => {
|
||||
test('magnitudeSquared equals Cesium', () => {
|
||||
for (const a of SAMPLES) {
|
||||
assert.equal(c3.magnitude(asPlain(a)), C.magnitude(asCesium(a)));
|
||||
assert.equal(
|
||||
c3.magnitudeSquared(asPlain(a)),
|
||||
C.magnitudeSquared(asCesium(a)),
|
||||
);
|
||||
same(
|
||||
c3.negate(asPlain(a), c3.create()),
|
||||
C.negate(asCesium(a), new C()),
|
||||
'negate',
|
||||
);
|
||||
same(
|
||||
c3.multiplyByScalar(asPlain(a), 2.5, c3.create()),
|
||||
C.multiplyByScalar(asCesium(a), 2.5, new C()),
|
||||
'mul',
|
||||
);
|
||||
same(
|
||||
c3.divideByScalar(asPlain(a), 4, c3.create()),
|
||||
C.divideByScalar(asCesium(a), 4, new C()),
|
||||
'div',
|
||||
);
|
||||
if (C.magnitude(asCesium(a)) !== 0) {
|
||||
same(
|
||||
c3.normalize(asPlain(a), c3.create()),
|
||||
C.normalize(asCesium(a), new C()),
|
||||
'normalize',
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test('geodetic constructors equal Cesium', () => {
|
||||
test('fromRadians and fromDegreesArray equal Cesium', () => {
|
||||
for (const [lon, lat, h] of [
|
||||
[0, 0, 0],
|
||||
[-73.9857, 40.7484, 381],
|
||||
@@ -100,11 +38,6 @@ test('geodetic constructors equal Cesium', () => {
|
||||
[180, -90, 1e4],
|
||||
[12.5, 89.999999, 1],
|
||||
]) {
|
||||
same(
|
||||
c3.fromDegrees(lon, lat, h),
|
||||
C.fromDegrees(lon, lat, h),
|
||||
`fromDegrees ${lon},${lat}`,
|
||||
);
|
||||
const lr = [Cesium.Math.toRadians(lon), Cesium.Math.toRadians(lat), h];
|
||||
same(c3.fromRadians(...lr), C.fromRadians(...lr), 'fromRadians');
|
||||
}
|
||||
@@ -112,10 +45,6 @@ test('geodetic constructors equal Cesium', () => {
|
||||
c3.fromDegreesArray(flat).forEach((p, i) =>
|
||||
same(p, C.fromDegreesArray(flat)[i], `array ${i}`),
|
||||
);
|
||||
const heights = [-74, 40.7, 10, -73.9, 40.8, 20];
|
||||
c3.fromDegreesArrayHeights(heights).forEach((p, i) =>
|
||||
same(p, C.fromDegreesArrayHeights(heights)[i], `heights ${i}`),
|
||||
);
|
||||
});
|
||||
|
||||
test('result aliasing works like Cesium and creators reuse result', () => {
|
||||
@@ -138,20 +67,3 @@ test('plain results are accepted by Cesium functions (duck typing)', () => {
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('normalize throws on a zero or NaN vector, as Cesium does when run from source', () => {
|
||||
for (const [x, y, z] of [
|
||||
[0, 0, 0],
|
||||
[-0, 0, -0],
|
||||
[Number.NaN, 1, 2],
|
||||
]) {
|
||||
assert.throws(
|
||||
() => C.normalize(new C(x, y, z), new C()),
|
||||
/normalized result is not a number/,
|
||||
);
|
||||
assert.throws(
|
||||
() => c3.normalize({ x, y, z }, c3.create()),
|
||||
/normalized result is not a number/,
|
||||
);
|
||||
}
|
||||
});
|
||||
+1
-19
@@ -1,17 +1,13 @@
|
||||
// Ported from CesiumJS 1.138 (Apache-2.0) — Cartographic.js
|
||||
//
|
||||
// Geodetic positions as plain-data {longitude, latitude, height} objects (radians and
|
||||
// metres). Every function takes an optional `result` and returns it. With
|
||||
// DEBUG on (development and tests; see debug.js) invalid arguments throw the
|
||||
// same DeveloperError as Cesium's debug checks.
|
||||
// metres). Every function takes an optional `result` and returns it.
|
||||
//
|
||||
// Geo values are not Object.prototype objects, so src/app/stateChannel.js
|
||||
// copyState and src/director/documentFields.js jsonTree reject them: copy
|
||||
// the fields into a literal before putting one into product state or a
|
||||
// scene document.
|
||||
|
||||
import { DEBUG } from './debug.js';
|
||||
import { Check } from './check.js';
|
||||
import { toRadians } from './math.js';
|
||||
import * as cartesian3 from './cartesian3.js';
|
||||
import { scaleToGeodeticSurface } from './scaleToGeodeticSurface.js';
|
||||
@@ -51,11 +47,6 @@ const WGS84_CENTER_TOLERANCE_SQUARED = 0.1;
|
||||
|
||||
/** A geodetic position from radians. */
|
||||
export function fromRadians(longitude, latitude, height, result) {
|
||||
if (DEBUG) {
|
||||
Check.typeOf.number('longitude', longitude);
|
||||
Check.typeOf.number('latitude', latitude);
|
||||
}
|
||||
|
||||
height = height ?? 0.0;
|
||||
if (result == null) return create(longitude, latitude, height);
|
||||
result.longitude = longitude;
|
||||
@@ -66,11 +57,6 @@ export function fromRadians(longitude, latitude, height, result) {
|
||||
|
||||
/** A geodetic position from degrees; the result is in radians. */
|
||||
export function fromDegrees(longitude, latitude, height, result) {
|
||||
if (DEBUG) {
|
||||
Check.typeOf.number('longitude', longitude);
|
||||
Check.typeOf.number('latitude', latitude);
|
||||
}
|
||||
|
||||
longitude = toRadians(longitude);
|
||||
latitude = toRadians(latitude);
|
||||
return fromRadians(longitude, latitude, height, result);
|
||||
@@ -133,10 +119,6 @@ export function fromCartesian(cartesian, ellipsoid, result) {
|
||||
* where Cesium uses Ellipsoid.default; gev never changes it).
|
||||
*/
|
||||
export function toCartesian(cartographic, ellipsoid, result) {
|
||||
if (DEBUG) {
|
||||
Check.defined('cartographic', cartographic);
|
||||
}
|
||||
|
||||
return cartesian3.fromRadians(
|
||||
cartographic.longitude,
|
||||
cartographic.latitude,
|
||||
|
||||
@@ -4,12 +4,6 @@ import assert from 'node:assert/strict';
|
||||
import * as Cesium from 'cesium';
|
||||
import * as cartographic from './cartographic.js';
|
||||
|
||||
const close = (a, b, tol, label) =>
|
||||
assert.ok(
|
||||
Math.abs(a - b) <= tol * Math.max(1, Math.abs(b)),
|
||||
`${label}: ${a} vs ${b}`,
|
||||
);
|
||||
|
||||
test('fromDegrees and fromRadians equal Cesium', () => {
|
||||
for (const [lon, lat, h] of [
|
||||
[0, 0, 0],
|
||||
@@ -30,29 +24,6 @@ test('fromDegrees and fromRadians equal Cesium', () => {
|
||||
}
|
||||
});
|
||||
|
||||
test('fromCartesian and toCartesian equal Cesium, including the centre case', () => {
|
||||
for (const [x, y, z] of [
|
||||
[1334762.2, -4654869.1, 4137287.9],
|
||||
[6378137, 0, 0],
|
||||
[0.01, 0, 0],
|
||||
]) {
|
||||
const ours = cartographic.fromCartesian({ x, y, z });
|
||||
const theirs = Cesium.Cartographic.fromCartesian(
|
||||
new Cesium.Cartesian3(x, y, z),
|
||||
);
|
||||
if (theirs === undefined) {
|
||||
assert.equal(ours, undefined);
|
||||
continue;
|
||||
}
|
||||
close(ours.longitude, theirs.longitude, 1e-12, 'lon');
|
||||
close(ours.latitude, theirs.latitude, 1e-12, 'lat');
|
||||
close(ours.height, theirs.height, 1e-9, 'h');
|
||||
const back = cartographic.toCartesian(ours);
|
||||
const cBack = Cesium.Cartographic.toCartesian(theirs);
|
||||
for (const k of ['x', 'y', 'z']) close(back[k], cBack[k], 1e-12, k);
|
||||
}
|
||||
});
|
||||
|
||||
test('result objects are reused', () => {
|
||||
const out = cartographic.create();
|
||||
assert.equal(cartographic.fromDegrees(1, 2, 3, out), out);
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
// Ported from CesiumJS 1.138 (Apache-2.0) — Check.js
|
||||
//
|
||||
// Cesium's argument checks with the same conditions and message text. Only the
|
||||
// checks src/geo needs are ported. Callers run them inside `if (DEBUG)` blocks
|
||||
// (see debug.js), as Cesium runs them inside its debug pragmas, so production
|
||||
// builds drop the calls and this module with them.
|
||||
|
||||
import { DeveloperError } from './developerError.js';
|
||||
|
||||
const undefinedMessage = (name) =>
|
||||
`${name} is required, actual value was undefined`;
|
||||
const typeMessage = (actual, expected, name) =>
|
||||
`Expected ${name} to be typeof ${expected}, actual typeof was ${actual}`;
|
||||
|
||||
/** Throws unless `test` is neither undefined nor null. */
|
||||
function defined(name, test) {
|
||||
if (test === undefined || test === null) {
|
||||
throw new DeveloperError(undefinedMessage(name));
|
||||
}
|
||||
}
|
||||
|
||||
/** Throws unless `typeof test` is 'number' (NaN passes, as in Cesium). */
|
||||
function number(name, test) {
|
||||
if (typeof test !== 'number') {
|
||||
throw new DeveloperError(typeMessage(typeof test, 'number', name));
|
||||
}
|
||||
}
|
||||
|
||||
// Attached in a function marked pure, not by top-level assignments, so that a
|
||||
// production build, where no caller runs a check, drops this module entirely.
|
||||
function withBounds(check) {
|
||||
check.lessThanOrEquals = function (name, test, limit) {
|
||||
check(name, test);
|
||||
if (test > limit) {
|
||||
throw new DeveloperError(
|
||||
`Expected ${name} to be less than or equal to ${limit}, actual value was ${test}`,
|
||||
);
|
||||
}
|
||||
};
|
||||
check.greaterThanOrEquals = function (name, test, limit) {
|
||||
check(name, test);
|
||||
if (test < limit) {
|
||||
throw new DeveloperError(
|
||||
`Expected ${name} to be greater than or equal to ${limit}, actual value was ${test}`,
|
||||
);
|
||||
}
|
||||
};
|
||||
return check;
|
||||
}
|
||||
|
||||
/** Throws unless `typeof test` is 'object' (null passes, as in Cesium). */
|
||||
function object(name, test) {
|
||||
if (typeof test !== 'object') {
|
||||
throw new DeveloperError(typeMessage(typeof test, 'object', name));
|
||||
}
|
||||
}
|
||||
|
||||
export const Check = /* @__PURE__ */ Object.freeze({
|
||||
defined,
|
||||
typeOf: Object.freeze({ number: /* @__PURE__ */ withBounds(number), object }),
|
||||
});
|
||||
@@ -1,486 +0,0 @@
|
||||
// Argument-check parity with Cesium. gev runs Cesium from source, where its
|
||||
// debug checks are live, so for any input both sides must throw an error with
|
||||
// the same name and message, or neither may throw. The inputs are seeded and
|
||||
// deterministic: each case builds its arguments twice from the same seed, once
|
||||
// for geo and once for Cesium, so no object is shared between the two sides.
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import * as Cesium from 'cesium';
|
||||
import * as geo from './index.js';
|
||||
import { DeveloperError } from './developerError.js';
|
||||
|
||||
const TRIALS = 150;
|
||||
|
||||
function generator(seed) {
|
||||
return () => {
|
||||
seed = (seed + 0x6d2b79f5) | 0;
|
||||
let t = Math.imul(seed ^ (seed >>> 15), 1 | seed);
|
||||
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
|
||||
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
||||
};
|
||||
}
|
||||
|
||||
// Invalid values every argument may receive. NaN is a number to Check.typeOf.number
|
||||
// and null an object to Check.typeOf.object, so both reach the arithmetic.
|
||||
const INVALID = [undefined, null, Number.NaN, 'abc', 5, true, {}];
|
||||
|
||||
const vectorValues = { x: 1.5, y: -2, z: 3 };
|
||||
const VALID = {
|
||||
num: (side, random) => [0, -0, 0.7, -2.5, 1e6][Math.floor(random() * 5)],
|
||||
index3: (side, random) => Math.floor(random() * 5) - 1,
|
||||
index4: (side, random) => Math.floor(random() * 6) - 1,
|
||||
nonNegative: (side, random) => [0, 3, 6378137, -1][Math.floor(random() * 4)],
|
||||
vec: (side) =>
|
||||
side === 'geo' ? { ...vectorValues } : new Cesium.Cartesian3(1.5, -2, 3),
|
||||
zeroVec: (side) =>
|
||||
side === 'geo' ? { x: 0, y: 0, z: 0 } : new Cesium.Cartesian3(),
|
||||
vec4: (side) =>
|
||||
side === 'geo' ? { x: 0, y: 0, z: 0, w: 0 } : new Cesium.Cartesian4(),
|
||||
carto: (side) =>
|
||||
side === 'geo'
|
||||
? { longitude: 0.3, latitude: -0.2, height: 10 }
|
||||
: new Cesium.Cartographic(0.3, -0.2, 10),
|
||||
partialCarto: (side) =>
|
||||
side === 'geo'
|
||||
? { longitude: 0.3, latitude: -0.2 }
|
||||
: { longitude: 0.3, latitude: -0.2 },
|
||||
quat: (side) =>
|
||||
side === 'geo'
|
||||
? { x: 0.1, y: 0.2, z: 0.3, w: 0.9 }
|
||||
: new Cesium.Quaternion(0.1, 0.2, 0.3, 0.9),
|
||||
mat3: (side) =>
|
||||
side === 'geo'
|
||||
? geo.matrix3.fromRotationZ(0.4)
|
||||
: Cesium.Matrix3.fromRotationZ(0.4, new Cesium.Matrix3()),
|
||||
mat4: (side) =>
|
||||
side === 'geo'
|
||||
? geo.transforms.eastNorthUpToFixedFrame({ x: 6378137, y: 1, z: 2 })
|
||||
: Cesium.Transforms.eastNorthUpToFixedFrame(
|
||||
new Cesium.Cartesian3(6378137, 1, 2),
|
||||
),
|
||||
hpr: (side) =>
|
||||
side === 'geo'
|
||||
? { heading: 0.3, pitch: -0.2, roll: 0.1 }
|
||||
: new Cesium.HeadingPitchRoll(0.3, -0.2, 0.1),
|
||||
partialHpr: () => ({ heading: 0.3 }),
|
||||
ellipsoid: (side) =>
|
||||
side === 'geo' ? geo.ellipsoid.WGS84 : Cesium.Ellipsoid.WGS84,
|
||||
coords2: (side, random) =>
|
||||
[[1, 2], [1, 2, 3], [], [1, 2, 3, 4]][Math.floor(random() * 4)],
|
||||
coords3: (side, random) =>
|
||||
[[1, 2, 3], [1, 2], [], [1, 2, 3, 4, 5, 6], [1, 2, 'h']][
|
||||
Math.floor(random() * 5)
|
||||
],
|
||||
nanVec: (side) =>
|
||||
side === 'geo'
|
||||
? { x: 1, y: Number.NaN, z: 2 }
|
||||
: new Cesium.Cartesian3(1, Number.NaN, 2),
|
||||
partialVec: () => ({ x: 1, y: 2 }),
|
||||
stringHeight: () => '5',
|
||||
};
|
||||
|
||||
/** One argument: usually a valid value of its kind, sometimes an invalid one. */
|
||||
function argument(kinds, side, random) {
|
||||
if (random() < 0.4) return INVALID[Math.floor(random() * INVALID.length)];
|
||||
const kind = kinds[Math.floor(random() * kinds.length)];
|
||||
return VALID[kind](side, random);
|
||||
}
|
||||
|
||||
const W = Cesium.Ellipsoid.WGS84;
|
||||
const C3 = Cesium.Cartesian3;
|
||||
const V = ['vec', 'zeroVec', 'nanVec', 'partialVec'];
|
||||
const N = ['num'];
|
||||
const R = ['vec'];
|
||||
|
||||
// [name, geo function, Cesium function, argument kinds per position]
|
||||
const CASES = [
|
||||
['math.toRadians', geo.math.toRadians, Cesium.Math.toRadians, [N]],
|
||||
['math.toDegrees', geo.math.toDegrees, Cesium.Math.toDegrees, [N]],
|
||||
['math.clamp', geo.math.clamp, Cesium.Math.clamp, [N, N, N]],
|
||||
['math.lerp', geo.math.lerp, Cesium.Math.lerp, [N, N, N]],
|
||||
['math.mod', geo.math.mod, Cesium.Math.mod, [N, ['num', 'nonNegative']]],
|
||||
['math.zeroToTwoPi', geo.math.zeroToTwoPi, Cesium.Math.zeroToTwoPi, [N]],
|
||||
[
|
||||
'math.negativePiToPi',
|
||||
geo.math.negativePiToPi,
|
||||
Cesium.Math.negativePiToPi,
|
||||
[N],
|
||||
],
|
||||
[
|
||||
'math.equalsEpsilon',
|
||||
geo.math.equalsEpsilon,
|
||||
Cesium.Math.equalsEpsilon,
|
||||
[N, N, N, N],
|
||||
],
|
||||
|
||||
['cartesian2.clone', geo.cartesian2.clone, Cesium.Cartesian2.clone, [R, R]],
|
||||
[
|
||||
'cartesian2.distance',
|
||||
geo.cartesian2.distance,
|
||||
Cesium.Cartesian2.distance,
|
||||
[R, R],
|
||||
],
|
||||
|
||||
['cartesian3.clone', geo.cartesian3.clone, C3.clone, [V, R]],
|
||||
[
|
||||
'cartesian3.fromElements',
|
||||
geo.cartesian3.fromElements,
|
||||
C3.fromElements,
|
||||
[N, N, N, R],
|
||||
],
|
||||
['cartesian3.magnitude', geo.cartesian3.magnitude, C3.magnitude, [V]],
|
||||
[
|
||||
'cartesian3.magnitudeSquared',
|
||||
geo.cartesian3.magnitudeSquared,
|
||||
C3.magnitudeSquared,
|
||||
[V],
|
||||
],
|
||||
['cartesian3.distance', geo.cartesian3.distance, C3.distance, [V, V]],
|
||||
[
|
||||
'cartesian3.distanceSquared',
|
||||
geo.cartesian3.distanceSquared,
|
||||
C3.distanceSquared,
|
||||
[V, V],
|
||||
],
|
||||
['cartesian3.normalize', geo.cartesian3.normalize, C3.normalize, [V, R]],
|
||||
['cartesian3.dot', geo.cartesian3.dot, C3.dot, [V, V]],
|
||||
[
|
||||
'cartesian3.multiplyComponents',
|
||||
geo.cartesian3.multiplyComponents,
|
||||
C3.multiplyComponents,
|
||||
[V, V, R],
|
||||
],
|
||||
['cartesian3.add', geo.cartesian3.add, C3.add, [V, V, R]],
|
||||
['cartesian3.subtract', geo.cartesian3.subtract, C3.subtract, [V, V, R]],
|
||||
[
|
||||
'cartesian3.multiplyByScalar',
|
||||
geo.cartesian3.multiplyByScalar,
|
||||
C3.multiplyByScalar,
|
||||
[V, N, R],
|
||||
],
|
||||
[
|
||||
'cartesian3.divideByScalar',
|
||||
geo.cartesian3.divideByScalar,
|
||||
C3.divideByScalar,
|
||||
[V, N, R],
|
||||
],
|
||||
['cartesian3.negate', geo.cartesian3.negate, C3.negate, [V, R]],
|
||||
['cartesian3.lerp', geo.cartesian3.lerp, C3.lerp, [V, V, N, R]],
|
||||
['cartesian3.cross', geo.cartesian3.cross, C3.cross, [V, V, R]],
|
||||
['cartesian3.midpoint', geo.cartesian3.midpoint, C3.midpoint, [V, V, R]],
|
||||
['cartesian3.equals', geo.cartesian3.equals, C3.equals, [V, V]],
|
||||
[
|
||||
'cartesian3.equalsEpsilon',
|
||||
geo.cartesian3.equalsEpsilon,
|
||||
C3.equalsEpsilon,
|
||||
[V, V, N, N],
|
||||
],
|
||||
[
|
||||
'cartesian3.fromRadians',
|
||||
geo.cartesian3.fromRadians,
|
||||
C3.fromRadians,
|
||||
[N, N, ['num', 'stringHeight'], ['ellipsoid'], R],
|
||||
],
|
||||
[
|
||||
'cartesian3.fromDegrees',
|
||||
geo.cartesian3.fromDegrees,
|
||||
C3.fromDegrees,
|
||||
[N, N, ['num', 'stringHeight'], ['ellipsoid'], R],
|
||||
],
|
||||
[
|
||||
'cartesian3.fromDegreesArray',
|
||||
geo.cartesian3.fromDegreesArray,
|
||||
C3.fromDegreesArray,
|
||||
[['coords2'], ['ellipsoid']],
|
||||
],
|
||||
[
|
||||
'cartesian3.fromDegreesArrayHeights',
|
||||
geo.cartesian3.fromDegreesArrayHeights,
|
||||
C3.fromDegreesArrayHeights,
|
||||
[['coords3'], ['ellipsoid']],
|
||||
],
|
||||
|
||||
[
|
||||
'cartographic.fromRadians',
|
||||
geo.cartographic.fromRadians,
|
||||
Cesium.Cartographic.fromRadians,
|
||||
[N, N, N, ['carto']],
|
||||
],
|
||||
[
|
||||
'cartographic.fromDegrees',
|
||||
geo.cartographic.fromDegrees,
|
||||
Cesium.Cartographic.fromDegrees,
|
||||
[N, N, N, ['carto']],
|
||||
],
|
||||
[
|
||||
'cartographic.fromCartesian',
|
||||
geo.cartographic.fromCartesian,
|
||||
Cesium.Cartographic.fromCartesian,
|
||||
[V, ['ellipsoid'], ['carto']],
|
||||
],
|
||||
[
|
||||
'cartographic.toCartesian',
|
||||
geo.cartographic.toCartesian,
|
||||
Cesium.Cartographic.toCartesian,
|
||||
[['carto', 'partialCarto'], ['ellipsoid'], R],
|
||||
],
|
||||
[
|
||||
'cartographic.clone',
|
||||
geo.cartographic.clone,
|
||||
Cesium.Cartographic.clone,
|
||||
[['carto'], ['carto']],
|
||||
],
|
||||
|
||||
[
|
||||
'ellipsoid.create',
|
||||
geo.ellipsoid.create,
|
||||
(x, y, z) => new Cesium.Ellipsoid(x, y, z),
|
||||
[['nonNegative'], ['nonNegative'], ['nonNegative']],
|
||||
],
|
||||
[
|
||||
'WGS84.geodeticSurfaceNormal',
|
||||
geo.ellipsoid.WGS84.geodeticSurfaceNormal,
|
||||
(c, r) => W.geodeticSurfaceNormal(c, r),
|
||||
[V, R],
|
||||
],
|
||||
[
|
||||
'WGS84.geodeticSurfaceNormalCartographic',
|
||||
geo.ellipsoid.WGS84.geodeticSurfaceNormalCartographic,
|
||||
(c, r) => W.geodeticSurfaceNormalCartographic(c, r),
|
||||
[['carto', 'partialCarto'], R],
|
||||
],
|
||||
[
|
||||
'WGS84.scaleToGeodeticSurface',
|
||||
geo.ellipsoid.WGS84.scaleToGeodeticSurface,
|
||||
(c, r) => W.scaleToGeodeticSurface(c, r),
|
||||
[V, R],
|
||||
],
|
||||
[
|
||||
'WGS84.cartographicToCartesian',
|
||||
geo.ellipsoid.WGS84.cartographicToCartesian,
|
||||
(c, r) => W.cartographicToCartesian(c, r),
|
||||
[['carto', 'partialCarto'], R],
|
||||
],
|
||||
[
|
||||
'WGS84.cartesianToCartographic',
|
||||
geo.ellipsoid.WGS84.cartesianToCartographic,
|
||||
(c, r) => W.cartesianToCartographic(c, r),
|
||||
[V, ['carto']],
|
||||
],
|
||||
|
||||
[
|
||||
'matrix3.fromQuaternion',
|
||||
geo.matrix3.fromQuaternion,
|
||||
Cesium.Matrix3.fromQuaternion,
|
||||
[['quat'], ['mat3']],
|
||||
],
|
||||
[
|
||||
'matrix3.fromRotationZ',
|
||||
geo.matrix3.fromRotationZ,
|
||||
Cesium.Matrix3.fromRotationZ,
|
||||
[N, ['mat3']],
|
||||
],
|
||||
[
|
||||
'matrix3.multiplyByVector',
|
||||
geo.matrix3.multiplyByVector,
|
||||
Cesium.Matrix3.multiplyByVector,
|
||||
[['mat3'], V, R],
|
||||
],
|
||||
[
|
||||
'matrix3.getColumn',
|
||||
geo.matrix3.getColumn,
|
||||
Cesium.Matrix3.getColumn,
|
||||
[['mat3'], ['index3'], R],
|
||||
],
|
||||
|
||||
[
|
||||
'matrix4.clone',
|
||||
geo.matrix4.clone,
|
||||
Cesium.Matrix4.clone,
|
||||
[['mat4'], ['mat4']],
|
||||
],
|
||||
[
|
||||
'matrix4.equals',
|
||||
geo.matrix4.equals,
|
||||
Cesium.Matrix4.equals,
|
||||
[['mat4'], ['mat4']],
|
||||
],
|
||||
[
|
||||
'matrix4.multiply',
|
||||
geo.matrix4.multiply,
|
||||
Cesium.Matrix4.multiply,
|
||||
[['mat4'], ['mat4'], ['mat4']],
|
||||
],
|
||||
[
|
||||
'matrix4.multiplyTransformation',
|
||||
geo.matrix4.multiplyTransformation,
|
||||
Cesium.Matrix4.multiplyTransformation,
|
||||
[['mat4'], ['mat4'], ['mat4']],
|
||||
],
|
||||
[
|
||||
'matrix4.multiplyByPoint',
|
||||
geo.matrix4.multiplyByPoint,
|
||||
Cesium.Matrix4.multiplyByPoint,
|
||||
[['mat4'], V, R],
|
||||
],
|
||||
[
|
||||
'matrix4.multiplyByPointAsVector',
|
||||
geo.matrix4.multiplyByPointAsVector,
|
||||
Cesium.Matrix4.multiplyByPointAsVector,
|
||||
[['mat4'], V, R],
|
||||
],
|
||||
[
|
||||
'matrix4.getTranslation',
|
||||
geo.matrix4.getTranslation,
|
||||
Cesium.Matrix4.getTranslation,
|
||||
[['mat4'], R],
|
||||
],
|
||||
[
|
||||
'matrix4.getMatrix3',
|
||||
geo.matrix4.getMatrix3,
|
||||
Cesium.Matrix4.getMatrix3,
|
||||
[['mat4'], ['mat3']],
|
||||
],
|
||||
[
|
||||
'matrix4.getColumn',
|
||||
geo.matrix4.getColumn,
|
||||
Cesium.Matrix4.getColumn,
|
||||
[['mat4'], ['index4'], ['vec4']],
|
||||
],
|
||||
[
|
||||
'matrix4.inverseTransformation',
|
||||
geo.matrix4.inverseTransformation,
|
||||
Cesium.Matrix4.inverseTransformation,
|
||||
[['mat4'], ['mat4']],
|
||||
],
|
||||
[
|
||||
'matrix4.fromRotationTranslation',
|
||||
geo.matrix4.fromRotationTranslation,
|
||||
Cesium.Matrix4.fromRotationTranslation,
|
||||
[['mat3'], R, ['mat4']],
|
||||
],
|
||||
[
|
||||
'matrix4.fromUniformScale',
|
||||
geo.matrix4.fromUniformScale,
|
||||
Cesium.Matrix4.fromUniformScale,
|
||||
[N, ['mat4']],
|
||||
],
|
||||
|
||||
[
|
||||
'quaternion.fromAxisAngle',
|
||||
geo.quaternion.fromAxisAngle,
|
||||
Cesium.Quaternion.fromAxisAngle,
|
||||
[V, N, ['quat']],
|
||||
],
|
||||
[
|
||||
'quaternion.fromRotationMatrix',
|
||||
geo.quaternion.fromRotationMatrix,
|
||||
Cesium.Quaternion.fromRotationMatrix,
|
||||
[['mat3'], ['quat']],
|
||||
],
|
||||
|
||||
[
|
||||
'transforms.eastNorthUpToFixedFrame',
|
||||
geo.transforms.eastNorthUpToFixedFrame,
|
||||
Cesium.Transforms.eastNorthUpToFixedFrame,
|
||||
[V, ['ellipsoid'], ['mat4']],
|
||||
],
|
||||
[
|
||||
'transforms.headingPitchRollToFixedFrame',
|
||||
geo.transforms.headingPitchRollToFixedFrame,
|
||||
Cesium.Transforms.headingPitchRollToFixedFrame,
|
||||
[V, ['hpr', 'partialHpr'], ['ellipsoid'], [], ['mat4']],
|
||||
],
|
||||
];
|
||||
|
||||
function outcome(fn, args) {
|
||||
try {
|
||||
fn(...args);
|
||||
return 'returned';
|
||||
} catch (error) {
|
||||
return `${error?.name}: ${error?.message}`;
|
||||
}
|
||||
}
|
||||
|
||||
test('every ported function throws exactly where Cesium does, with the same name and message', () => {
|
||||
let thrown = 0;
|
||||
let checked = 0;
|
||||
const mismatches = [];
|
||||
CASES.forEach(([name, ours, theirs, kinds], caseIndex) => {
|
||||
for (let trial = 0; trial < TRIALS; trial++) {
|
||||
const seed = caseIndex * 100003 + trial;
|
||||
// Trial 0 passes no arguments at all; the rest draw from the pools.
|
||||
const build = (side) => {
|
||||
if (trial === 0) return [];
|
||||
const random = generator(seed);
|
||||
return kinds.map((k) =>
|
||||
k.length ? argument(k, side, random) : undefined,
|
||||
);
|
||||
};
|
||||
const a = outcome(ours, build('geo'));
|
||||
const b = outcome(theirs, build('cesium'));
|
||||
if (a !== b)
|
||||
mismatches.push(`${name} (seed ${seed}): geo ${a} | Cesium ${b}`);
|
||||
checked++;
|
||||
if (b !== 'returned') thrown++;
|
||||
}
|
||||
});
|
||||
assert.deepEqual(mismatches, []);
|
||||
// The pools must actually reach the checks.
|
||||
assert.ok(thrown > checked / 4, `only ${thrown} of ${checked} cases threw`);
|
||||
});
|
||||
|
||||
test('the checks throw a DeveloperError with Cesium message text', () => {
|
||||
const cases = [
|
||||
[() => geo.math.toRadians(undefined), 'degrees is required.'],
|
||||
[() => geo.math.mod(5, 0), 'divisor cannot be 0.'],
|
||||
[
|
||||
() => geo.math.clamp('1', 0, 1),
|
||||
'Expected value to be typeof number, actual typeof was string',
|
||||
],
|
||||
[
|
||||
() => geo.cartesian3.fromDegrees(undefined, 1),
|
||||
'Expected longitude to be typeof number, actual typeof was undefined',
|
||||
],
|
||||
[
|
||||
() => geo.cartesian3.add({ x: 0, y: 0, z: 0 }, { x: 0, y: 0, z: 0 }),
|
||||
'Expected result to be typeof object, actual typeof was undefined',
|
||||
],
|
||||
[
|
||||
() => geo.cartesian3.fromDegreesArray([1]),
|
||||
'the number of coordinates must be a multiple of 2 and at least 2',
|
||||
],
|
||||
[
|
||||
() => geo.cartesian3.fromDegreesArray(),
|
||||
'coordinates is required, actual value was undefined',
|
||||
],
|
||||
[
|
||||
() => geo.ellipsoid.create(-1, 1, 1),
|
||||
'Expected x to be greater than or equal to 0, actual value was -1',
|
||||
],
|
||||
[
|
||||
() => geo.matrix3.getColumn(geo.matrix3.create(), 3, {}),
|
||||
'Expected index to be less than or equal to 2, actual value was 3',
|
||||
],
|
||||
[
|
||||
() =>
|
||||
geo.transforms.eastNorthUpToFixedFrame({ x: 1, y: Number.NaN, z: 0 }),
|
||||
'origin has a NaN component',
|
||||
],
|
||||
[
|
||||
() => geo.cartographic.fromCartesian({ x: 1, y: 2, z: 3 }, {}),
|
||||
'oneOverRadii is required.',
|
||||
],
|
||||
];
|
||||
for (const [fn, message] of cases) {
|
||||
assert.throws(fn, (error) => {
|
||||
assert.ok(error instanceof DeveloperError);
|
||||
assert.equal(error.name, 'DeveloperError');
|
||||
assert.equal(error.message, message);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
// NaN is typeof number, so Check.typeOf.number lets it through (as in Cesium).
|
||||
assert.ok(Number.isNaN(geo.math.clamp(Number.NaN, 0, 1)));
|
||||
assert.ok(Number.isNaN(Cesium.Math.clamp(Number.NaN, 0, 1)));
|
||||
});
|
||||
@@ -1,12 +0,0 @@
|
||||
// Whether src/geo runs Cesium's debug argument checks.
|
||||
//
|
||||
// Cesium wraps its argument checks in `//>>includeStart('debug')` pragmas: they
|
||||
// are live in its Source modules (Node tests, the Vite dev server) and stripped
|
||||
// from Build/Cesium, which vite-plugin-cesium copies into production builds.
|
||||
// src/geo does the same: every Check call and every debug throw sits in an
|
||||
// `if (DEBUG)` block. DEBUG is true in Node (no import.meta.env) and in Vite
|
||||
// dev; `vite build` folds it to false and the minifier drops the blocks, so a
|
||||
// production build returns what release Cesium returns (NaN, not a throw, for
|
||||
// a degenerate input).
|
||||
|
||||
export const DEBUG = import.meta.env?.PROD !== true;
|
||||
@@ -1,13 +0,0 @@
|
||||
// Ported from CesiumJS 1.138 (Apache-2.0) — DeveloperError.js
|
||||
//
|
||||
// The error Cesium throws for invalid arguments. Its debug argument checks are
|
||||
// live in Cesium's Source modules (Node tests, the Vite dev server) and
|
||||
// stripped from production builds; src/geo throws the same name and message
|
||||
// wherever Cesium does while DEBUG is on (see debug.js).
|
||||
|
||||
export class DeveloperError extends Error {
|
||||
constructor(message) {
|
||||
super(message);
|
||||
this.name = 'DeveloperError';
|
||||
}
|
||||
}
|
||||
+1
-22
@@ -3,14 +3,9 @@
|
||||
// A quadratic surface x²/a² + y²/b² + z²/c² = 1 as a plain, frozen object.
|
||||
// Every method takes an optional `result` and returns it (a new object when it
|
||||
// is absent); `result` may be the input. The algorithms and the operation order
|
||||
// match Cesium so the outputs are bit-identical. With DEBUG on (development
|
||||
// and tests; see debug.js) invalid arguments throw the same DeveloperError as
|
||||
// Cesium's debug checks.
|
||||
// match Cesium so the outputs are bit-identical.
|
||||
|
||||
import { DEBUG } from './debug.js';
|
||||
import { Check } from './check.js';
|
||||
import { create as createCartographic } from './cartographic.js';
|
||||
import { DeveloperError } from './developerError.js';
|
||||
import { EPSILON14 } from './math.js';
|
||||
import { scaleToGeodeticSurface } from './scaleToGeodeticSurface.js';
|
||||
import {
|
||||
@@ -39,11 +34,6 @@ export function create(x, y, z) {
|
||||
x = x ?? 0.0;
|
||||
y = y ?? 0.0;
|
||||
z = z ?? 0.0;
|
||||
if (DEBUG) {
|
||||
Check.typeOf.number.greaterThanOrEquals('x', x, 0.0);
|
||||
Check.typeOf.number.greaterThanOrEquals('y', y, 0.0);
|
||||
Check.typeOf.number.greaterThanOrEquals('z', z, 0.0);
|
||||
}
|
||||
|
||||
const radii = Object.freeze(vec(x, y, z));
|
||||
const radiiSquared = Object.freeze(vec(x * x, y * y, z * z));
|
||||
@@ -68,10 +58,6 @@ export function create(x, y, z) {
|
||||
|
||||
/** The normal to the ellipsoid surface at a geodetic position. */
|
||||
function geodeticSurfaceNormalCartographic(cartographic, result) {
|
||||
if (DEBUG) {
|
||||
Check.typeOf.object('cartographic', cartographic);
|
||||
}
|
||||
|
||||
const longitude = cartographic.longitude;
|
||||
const latitude = cartographic.latitude;
|
||||
const cosLatitude = Math.cos(latitude);
|
||||
@@ -89,13 +75,6 @@ export function create(x, y, z) {
|
||||
|
||||
/** The normal to the ellipsoid surface at a position, or `undefined` at the centre. */
|
||||
function geodeticSurfaceNormal(cartesian, result) {
|
||||
if (DEBUG) {
|
||||
Check.typeOf.object('cartesian', cartesian);
|
||||
if (isNaN(cartesian.x) || isNaN(cartesian.y) || isNaN(cartesian.z)) {
|
||||
throw new DeveloperError('cartesian has a NaN component');
|
||||
}
|
||||
}
|
||||
|
||||
if (equalsEpsilon(cartesian, ZERO, EPSILON14)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -12,18 +12,6 @@ const close = (a, b, tol, label) =>
|
||||
const closeVec = (a, b, tol, label) => {
|
||||
for (const k of ['x', 'y', 'z']) close(a[k], b[k], tol, `${label}.${k}`);
|
||||
};
|
||||
const POINTS = [
|
||||
[6378137, 0, 0],
|
||||
[0, 6378137, 0],
|
||||
[0, 0, 6356752.314245],
|
||||
[1334762.2, -4654869.1, 4137287.9],
|
||||
[-2694045, -4293642, 3857878],
|
||||
[1e3, 1e3, 1e3],
|
||||
[0.01, 0.01, 0.01],
|
||||
[7e6, -2e6, 1e6],
|
||||
[4510000, 4510000, 1],
|
||||
[1, 1, 6400000],
|
||||
];
|
||||
|
||||
test('WGS84 constants equal Cesium', () => {
|
||||
const c = Cesium.Ellipsoid.WGS84;
|
||||
@@ -40,39 +28,6 @@ test('WGS84 constants equal Cesium', () => {
|
||||
assert.equal(WGS84.maximumRadius, c.maximumRadius);
|
||||
});
|
||||
|
||||
test('surface normals, scaling and conversions equal Cesium', () => {
|
||||
const c = Cesium.Ellipsoid.WGS84;
|
||||
for (const [x, y, z] of POINTS) {
|
||||
const p = { x, y, z };
|
||||
const cp = new Cesium.Cartesian3(x, y, z);
|
||||
closeVec(
|
||||
WGS84.geodeticSurfaceNormal(p),
|
||||
c.geodeticSurfaceNormal(cp),
|
||||
1e-12,
|
||||
'normal',
|
||||
);
|
||||
const ours = WGS84.scaleToGeodeticSurface(p);
|
||||
const theirs = c.scaleToGeodeticSurface(cp);
|
||||
if (theirs === undefined) assert.equal(ours, undefined);
|
||||
else closeVec(ours, theirs, 1e-12, 'scale');
|
||||
const carto = WGS84.cartesianToCartographic(p);
|
||||
const cCarto = c.cartesianToCartographic(cp);
|
||||
if (cCarto === undefined) {
|
||||
assert.equal(carto, undefined);
|
||||
} else {
|
||||
close(carto.longitude, cCarto.longitude, 1e-12, 'lon');
|
||||
close(carto.latitude, cCarto.latitude, 1e-12, 'lat');
|
||||
close(carto.height, cCarto.height, 1e-9, 'height');
|
||||
closeVec(
|
||||
WGS84.cartographicToCartesian(carto),
|
||||
c.cartographicToCartesian(cCarto),
|
||||
1e-12,
|
||||
'roundtrip',
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test('result parameters are filled in place and may alias the input', () => {
|
||||
const p = { x: 1334762.2, y: -4654869.1, z: 4137287.9 };
|
||||
const out = { x: 0, y: 0, z: 0 };
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
// Ported from CesiumJS 1.138 (Apache-2.0) — EllipsoidGeodesic.js.
|
||||
// Vincenty inverse and surface interpolation, preserving operation order.
|
||||
import * as Cartesian3 from './cartesian3.js';
|
||||
import * as Cartographic from './cartographic.js';
|
||||
import * as Ellipsoid from './ellipsoid.js';
|
||||
import * as CesiumMath from './math.js';
|
||||
import { Check } from './check.js';
|
||||
import { DEBUG } from './debug.js';
|
||||
const defined = (value) => value !== null && value !== undefined;
|
||||
function setConstants(ellipsoidGeodesic) {
|
||||
const uSquared = ellipsoidGeodesic._uSquared;
|
||||
@@ -230,29 +227,7 @@ function vincentyInverseFormula(
|
||||
ellipsoidGeodesic._uSquared = uSquared;
|
||||
}
|
||||
|
||||
const scratchCart1 = Cartesian3.create();
|
||||
const scratchCart2 = Cartesian3.create();
|
||||
function computeProperties(ellipsoidGeodesic, start, end, ellipsoid) {
|
||||
const firstCartesian = Cartesian3.normalize(
|
||||
ellipsoid.cartographicToCartesian(start, scratchCart2),
|
||||
scratchCart1,
|
||||
);
|
||||
const lastCartesian = Cartesian3.normalize(
|
||||
ellipsoid.cartographicToCartesian(end, scratchCart2),
|
||||
scratchCart2,
|
||||
);
|
||||
|
||||
if (DEBUG) {
|
||||
Check.typeOf.number.greaterThanOrEquals(
|
||||
'value',
|
||||
Math.abs(
|
||||
Math.abs(Cartesian3.angleBetween(firstCartesian, lastCartesian)) -
|
||||
Math.PI,
|
||||
),
|
||||
0.0125,
|
||||
);
|
||||
}
|
||||
|
||||
vincentyInverseFormula(
|
||||
ellipsoidGeodesic,
|
||||
ellipsoid.maximumRadius,
|
||||
@@ -322,10 +297,6 @@ Object.defineProperties(EllipsoidGeodesic.prototype, {
|
||||
*/
|
||||
surfaceDistance: {
|
||||
get: function () {
|
||||
if (DEBUG) {
|
||||
Check.defined('distance', this._distance);
|
||||
}
|
||||
|
||||
return this._distance;
|
||||
},
|
||||
},
|
||||
@@ -362,10 +333,6 @@ Object.defineProperties(EllipsoidGeodesic.prototype, {
|
||||
*/
|
||||
startHeading: {
|
||||
get: function () {
|
||||
if (DEBUG) {
|
||||
Check.defined('distance', this._distance);
|
||||
}
|
||||
|
||||
return this._startHeading;
|
||||
},
|
||||
},
|
||||
@@ -378,10 +345,6 @@ Object.defineProperties(EllipsoidGeodesic.prototype, {
|
||||
*/
|
||||
endHeading: {
|
||||
get: function () {
|
||||
if (DEBUG) {
|
||||
Check.defined('distance', this._distance);
|
||||
}
|
||||
|
||||
return this._endHeading;
|
||||
},
|
||||
},
|
||||
@@ -394,11 +357,6 @@ Object.defineProperties(EllipsoidGeodesic.prototype, {
|
||||
* @param {Cartographic} end The final planetodetic point on the path.
|
||||
*/
|
||||
EllipsoidGeodesic.prototype.setEndPoints = function (start, end) {
|
||||
if (DEBUG) {
|
||||
Check.defined('start', start);
|
||||
Check.defined('end', end);
|
||||
}
|
||||
|
||||
computeProperties(this, start, end, this._ellipsoid);
|
||||
};
|
||||
|
||||
@@ -425,17 +383,11 @@ EllipsoidGeodesic.prototype.interpolateUsingFraction = function (
|
||||
* @param {number} distance The distance from the initial point to the point of interest along the geodesic
|
||||
* @param {Cartographic} [result] The object in which to store the result.
|
||||
* @returns {Cartographic} The location of the point along the geodesic.
|
||||
*
|
||||
* @exception {DeveloperError} start and end must be set before calling function interpolateUsingSurfaceDistance
|
||||
*/
|
||||
EllipsoidGeodesic.prototype.interpolateUsingSurfaceDistance = function (
|
||||
distance,
|
||||
result,
|
||||
) {
|
||||
if (DEBUG) {
|
||||
Check.defined('distance', this._distance);
|
||||
}
|
||||
|
||||
const constants = this._constants;
|
||||
|
||||
const s = constants.distanceRatio + distance / constants.b;
|
||||
|
||||
@@ -66,17 +66,3 @@ test('endpoint reset, result reuse, custom sphere and dateline/polar paths retai
|
||||
);
|
||||
}
|
||||
});
|
||||
test('unset and near-antipodal geodesics reject the same debug inputs', () => {
|
||||
assert.throws(() => geo.ellipsoidGeodesic.create().surfaceDistance, {
|
||||
name: 'DeveloperError',
|
||||
});
|
||||
const a = geo.cartographic.fromDegrees(0, 0),
|
||||
b = geo.cartographic.fromDegrees(180, 0);
|
||||
assert.throws(() => geo.ellipsoidGeodesic.create(a, b), {
|
||||
name: 'DeveloperError',
|
||||
});
|
||||
assert.throws(
|
||||
() => geo.ellipsoidGeodesic.create().setEndPoints(undefined, b),
|
||||
{ name: 'DeveloperError' },
|
||||
);
|
||||
});
|
||||
+1
-54
@@ -1,15 +1,8 @@
|
||||
// Ported from CesiumJS 1.138 (Apache-2.0) — Math.js
|
||||
//
|
||||
// Engine-neutral angle maths. Formulas and constants match Cesium.Math bit for
|
||||
// bit. With DEBUG on (development and tests; see debug.js) invalid arguments
|
||||
// throw the same DeveloperError as Cesium's debug checks; production builds
|
||||
// skip the checks, as release Cesium does.
|
||||
// bit.
|
||||
|
||||
import { DEBUG } from './debug.js';
|
||||
import { Check } from './check.js';
|
||||
import { DeveloperError } from './developerError.js';
|
||||
|
||||
export const EPSILON7 = 0.0000001;
|
||||
export const EPSILON10 = 0.0000000001;
|
||||
export const EPSILON12 = 0.000000000001;
|
||||
export const EPSILON14 = 0.00000000000001;
|
||||
@@ -20,32 +13,16 @@ export const DEGREES_PER_RADIAN = 180.0 / Math.PI;
|
||||
|
||||
/** Converts degrees to radians. */
|
||||
export function toRadians(degrees) {
|
||||
if (DEBUG) {
|
||||
if (degrees == null) {
|
||||
throw new DeveloperError('degrees is required.');
|
||||
}
|
||||
}
|
||||
return degrees * RADIANS_PER_DEGREE;
|
||||
}
|
||||
|
||||
/** Converts radians to degrees. */
|
||||
export function toDegrees(radians) {
|
||||
if (DEBUG) {
|
||||
if (radians == null) {
|
||||
throw new DeveloperError('radians is required.');
|
||||
}
|
||||
}
|
||||
return radians * DEGREES_PER_RADIAN;
|
||||
}
|
||||
|
||||
/** Constrains a value to lie between two values. */
|
||||
export function clamp(value, min, max) {
|
||||
if (DEBUG) {
|
||||
Check.typeOf.number('value', value);
|
||||
Check.typeOf.number('min', min);
|
||||
Check.typeOf.number('max', max);
|
||||
}
|
||||
|
||||
return value < min ? min : value > max ? max : value;
|
||||
}
|
||||
|
||||
@@ -56,17 +33,6 @@ export function lerp(p, q, time) {
|
||||
|
||||
/** The modulo operation that also works for negative dividends. */
|
||||
export function mod(m, n) {
|
||||
if (DEBUG) {
|
||||
if (m == null) {
|
||||
throw new DeveloperError('m is required.');
|
||||
}
|
||||
if (n == null) {
|
||||
throw new DeveloperError('n is required.');
|
||||
}
|
||||
if (n === 0.0) {
|
||||
throw new DeveloperError('divisor cannot be 0.');
|
||||
}
|
||||
}
|
||||
if (Math.sign(m) === Math.sign(n) && Math.abs(m) < Math.abs(n)) {
|
||||
// Early exit if the input does not need to be modded. This avoids
|
||||
// unnecessary math which could introduce floating point error.
|
||||
@@ -77,11 +43,6 @@ export function mod(m, n) {
|
||||
|
||||
/** Produces an angle in the range 0 <= angle <= 2Pi equivalent to the provided angle. */
|
||||
export function zeroToTwoPi(angle) {
|
||||
if (DEBUG) {
|
||||
if (angle == null) {
|
||||
throw new DeveloperError('angle is required.');
|
||||
}
|
||||
}
|
||||
if (angle >= 0 && angle <= TWO_PI) {
|
||||
// Early exit if the input is already inside the range. This avoids
|
||||
// unnecessary math which could introduce floating point error.
|
||||
@@ -96,11 +57,6 @@ export function zeroToTwoPi(angle) {
|
||||
|
||||
/** Produces an angle in the range -Pi <= angle <= Pi equivalent to the provided angle. */
|
||||
export function negativePiToPi(angle) {
|
||||
if (DEBUG) {
|
||||
if (angle == null) {
|
||||
throw new DeveloperError('angle is required.');
|
||||
}
|
||||
}
|
||||
if (angle >= -Math.PI && angle <= Math.PI) {
|
||||
// Early exit if the input is already inside the range. This avoids
|
||||
// unnecessary math which could introduce floating point error.
|
||||
@@ -114,15 +70,6 @@ export function negativePiToPi(angle) {
|
||||
* (the absolute one defaults to the relative one).
|
||||
*/
|
||||
export function equalsEpsilon(left, right, relativeEpsilon, absoluteEpsilon) {
|
||||
if (DEBUG) {
|
||||
if (left == null) {
|
||||
throw new DeveloperError('left is required.');
|
||||
}
|
||||
if (right == null) {
|
||||
throw new DeveloperError('right is required.');
|
||||
}
|
||||
}
|
||||
|
||||
relativeEpsilon = relativeEpsilon ?? 0.0;
|
||||
absoluteEpsilon = absoluteEpsilon ?? relativeEpsilon;
|
||||
const absDiff = Math.abs(left - right);
|
||||
|
||||
@@ -31,7 +31,6 @@ test('constants equal Cesium.Math', () => {
|
||||
for (const name of [
|
||||
'PI_OVER_TWO',
|
||||
'TWO_PI',
|
||||
'EPSILON7',
|
||||
'EPSILON10',
|
||||
'EPSILON12',
|
||||
'EPSILON14',
|
||||
|
||||
+2
-73
@@ -4,13 +4,10 @@ import assert from 'node:assert/strict';
|
||||
import * as Cesium from 'cesium';
|
||||
import * as m3 from './matrix3.js';
|
||||
import * as m4 from './matrix4.js';
|
||||
import * as quat from './quaternion.js';
|
||||
|
||||
const arr = (m, n) => Array.from({ length: n }, (_, i) => m[i]);
|
||||
const sameArr = (ours, theirs, n, label) =>
|
||||
assert.deepEqual(arr(ours, n), arr(theirs, n), label);
|
||||
const close = (a, b, tol, label) =>
|
||||
assert.ok(Math.abs(a - b) <= tol, `${label}: ${a} vs ${b}`);
|
||||
|
||||
const T = Cesium.Matrix4.fromTranslationQuaternionRotationScale(
|
||||
new Cesium.Cartesian3(10, -20, 30),
|
||||
@@ -29,41 +26,7 @@ const U = Cesium.Matrix4.fromRotationTranslation(
|
||||
);
|
||||
const plain4 = (m) => arr(m, 16);
|
||||
|
||||
test('matrix4 products, points and inverses equal Cesium', () => {
|
||||
sameArr(
|
||||
m4.multiply(plain4(T), plain4(U), m4.create()),
|
||||
Cesium.Matrix4.multiply(T, U, new Cesium.Matrix4()),
|
||||
16,
|
||||
'multiply',
|
||||
);
|
||||
sameArr(
|
||||
m4.multiplyTransformation(plain4(T), plain4(U), m4.create()),
|
||||
Cesium.Matrix4.multiplyTransformation(T, U, new Cesium.Matrix4()),
|
||||
16,
|
||||
'multiplyTransformation',
|
||||
);
|
||||
const p = new Cesium.Cartesian3(1.5, -2, 3);
|
||||
const ours = m4.multiplyByPoint(
|
||||
plain4(T),
|
||||
{ x: 1.5, y: -2, z: 3 },
|
||||
{ x: 0, y: 0, z: 0 },
|
||||
);
|
||||
const theirs = Cesium.Matrix4.multiplyByPoint(T, p, new Cesium.Cartesian3());
|
||||
assert.deepEqual({ ...ours }, { x: theirs.x, y: theirs.y, z: theirs.z });
|
||||
const v = m4.multiplyByPointAsVector(
|
||||
plain4(T),
|
||||
{ x: 1.5, y: -2, z: 3 },
|
||||
{ x: 0, y: 0, z: 0 },
|
||||
);
|
||||
const cv = Cesium.Matrix4.multiplyByPointAsVector(
|
||||
T,
|
||||
p,
|
||||
new Cesium.Cartesian3(),
|
||||
);
|
||||
assert.deepEqual({ ...v }, { x: cv.x, y: cv.y, z: cv.z });
|
||||
const inv = m4.inverseTransformation(plain4(T), m4.create());
|
||||
const cinv = Cesium.Matrix4.inverseTransformation(T, new Cesium.Matrix4());
|
||||
for (let i = 0; i < 16; i++) close(inv[i], cinv[i], 1e-12, `inv ${i}`);
|
||||
test('matrix4 getters, equals and IDENTITY equal Cesium', () => {
|
||||
const t = m4.getTranslation(plain4(T), { x: 0, y: 0, z: 0 });
|
||||
assert.deepEqual({ ...t }, { x: 10, y: -20, z: 30 });
|
||||
sameArr(
|
||||
@@ -74,49 +37,15 @@ test('matrix4 products, points and inverses equal Cesium', () => {
|
||||
);
|
||||
assert.ok(m4.equals(m4.clone(plain4(T)), plain4(T)));
|
||||
assert.ok(Object.isFrozen(m4.IDENTITY));
|
||||
sameArr(
|
||||
m4.fromUniformScale(2.5, m4.create()),
|
||||
Cesium.Matrix4.fromUniformScale(2.5, new Cesium.Matrix4()),
|
||||
16,
|
||||
'scale',
|
||||
);
|
||||
});
|
||||
|
||||
test('matrix3, quaternion and rotation-translation equal Cesium', () => {
|
||||
test('matrix3 and rotation-translation equal Cesium', () => {
|
||||
sameArr(
|
||||
m3.fromRotationZ(1.1, m3.create()),
|
||||
Cesium.Matrix3.fromRotationZ(1.1, new Cesium.Matrix3()),
|
||||
9,
|
||||
'rotZ',
|
||||
);
|
||||
const axis = {
|
||||
x: 0.2672612419124244,
|
||||
y: 0.5345224838248488,
|
||||
z: 0.8017837257372732,
|
||||
};
|
||||
const q = quat.fromAxisAngle(axis, 0.7, quat.create());
|
||||
const cq = Cesium.Quaternion.fromAxisAngle(
|
||||
new Cesium.Cartesian3(axis.x, axis.y, axis.z),
|
||||
0.7,
|
||||
new Cesium.Quaternion(),
|
||||
);
|
||||
assert.deepEqual({ ...q }, { x: cq.x, y: cq.y, z: cq.z, w: cq.w });
|
||||
sameArr(
|
||||
m3.fromQuaternion(q, m3.create()),
|
||||
Cesium.Matrix3.fromQuaternion(cq, new Cesium.Matrix3()),
|
||||
9,
|
||||
'fromQuaternion',
|
||||
);
|
||||
const back = quat.fromRotationMatrix(
|
||||
m3.fromQuaternion(q, m3.create()),
|
||||
quat.create(),
|
||||
);
|
||||
const cback = Cesium.Quaternion.fromRotationMatrix(
|
||||
Cesium.Matrix3.fromQuaternion(cq, new Cesium.Matrix3()),
|
||||
new Cesium.Quaternion(),
|
||||
);
|
||||
for (const k of ['x', 'y', 'z', 'w'])
|
||||
close(back[k], cback[k], 1e-15, `q.${k}`);
|
||||
const mv = m3.multiplyByVector(
|
||||
m3.fromRotationZ(1.1, m3.create()),
|
||||
{ x: 1, y: 2, z: 3 },
|
||||
|
||||
+1
-27
@@ -2,12 +2,7 @@
|
||||
//
|
||||
// 3x3 matrices as plain arrays of 9 numbers in Cesium's column-major index
|
||||
// order (m[column * 3 + row]), so Cesium accepts them wherever it reads
|
||||
// m[0]..m[8]. Only the subset gev uses is ported. With DEBUG on (development
|
||||
// and tests; see debug.js) invalid arguments throw the same DeveloperError as
|
||||
// Cesium's debug checks.
|
||||
|
||||
import { DEBUG } from './debug.js';
|
||||
import { Check } from './check.js';
|
||||
// m[0]..m[8]. Only the subset gev uses is ported.
|
||||
|
||||
/** A matrix of zeros (Cesium's `new Matrix3()`). */
|
||||
export function create() {
|
||||
@@ -16,10 +11,6 @@ export function create() {
|
||||
|
||||
/** The rotation matrix of a unit quaternion. */
|
||||
export function fromQuaternion(quaternion, result) {
|
||||
if (DEBUG) {
|
||||
Check.typeOf.object('quaternion', quaternion);
|
||||
}
|
||||
|
||||
const x2 = quaternion.x * quaternion.x;
|
||||
const xy = quaternion.x * quaternion.y;
|
||||
const xz = quaternion.x * quaternion.z;
|
||||
@@ -58,10 +49,6 @@ export function fromQuaternion(quaternion, result) {
|
||||
|
||||
/** A rotation by `angle` radians around the z-axis. */
|
||||
export function fromRotationZ(angle, result) {
|
||||
if (DEBUG) {
|
||||
Check.typeOf.number('angle', angle);
|
||||
}
|
||||
|
||||
const cosAngle = Math.cos(angle);
|
||||
const sinAngle = Math.sin(angle);
|
||||
|
||||
@@ -80,12 +67,6 @@ export function fromRotationZ(angle, result) {
|
||||
|
||||
/** The product of a matrix and a column vector; `result` is required. */
|
||||
export function multiplyByVector(matrix, cartesian, result) {
|
||||
if (DEBUG) {
|
||||
Check.typeOf.object('matrix', matrix);
|
||||
Check.typeOf.object('cartesian', cartesian);
|
||||
Check.typeOf.object('result', result);
|
||||
}
|
||||
|
||||
const vX = cartesian.x;
|
||||
const vY = cartesian.y;
|
||||
const vZ = cartesian.z;
|
||||
@@ -102,13 +83,6 @@ export function multiplyByVector(matrix, cartesian, result) {
|
||||
|
||||
/** The column at `index` (0..2) as {x, y, z}; `result` is required. */
|
||||
export function getColumn(matrix, index, result) {
|
||||
if (DEBUG) {
|
||||
Check.typeOf.object('matrix', matrix);
|
||||
Check.typeOf.number.greaterThanOrEquals('index', index, 0);
|
||||
Check.typeOf.number.lessThanOrEquals('index', index, 2);
|
||||
Check.typeOf.object('result', result);
|
||||
}
|
||||
|
||||
const startIndex = index * 3;
|
||||
const x = matrix[startIndex];
|
||||
const y = matrix[startIndex + 1];
|
||||
|
||||
+1
-81
@@ -4,12 +4,8 @@
|
||||
// order (m[column * 4 + row]), so Cesium accepts them wherever it reads
|
||||
// m[0]..m[15] (e.g. the Model.modelMatrix setter clones by index). Products
|
||||
// and getters take a required `result` that may be an input; constructors
|
||||
// take an optional one. Only the subset gev uses is ported. With DEBUG on
|
||||
// (development and tests; see debug.js) invalid arguments throw the same
|
||||
// DeveloperError as Cesium's debug checks.
|
||||
// take an optional one. Only the subset gev uses is ported.
|
||||
|
||||
import { DEBUG } from './debug.js';
|
||||
import { Check } from './check.js';
|
||||
import { ZERO } from './cartesian3.js';
|
||||
|
||||
/** A matrix of zeros (Cesium's `new Matrix4()`). */
|
||||
@@ -65,12 +61,6 @@ export function equals(left, right) {
|
||||
|
||||
/** The product of two matrices. */
|
||||
export function multiply(left, right, result) {
|
||||
if (DEBUG) {
|
||||
Check.typeOf.object('left', left);
|
||||
Check.typeOf.object('right', right);
|
||||
Check.typeOf.object('result', result);
|
||||
}
|
||||
|
||||
const left0 = left[0];
|
||||
const left1 = left[1];
|
||||
const left2 = left[2];
|
||||
@@ -162,12 +152,6 @@ export function multiply(left, right, result) {
|
||||
|
||||
/** The product of two affine transformations (bottom rows assumed [0, 0, 0, 1]). */
|
||||
export function multiplyTransformation(left, right, result) {
|
||||
if (DEBUG) {
|
||||
Check.typeOf.object('left', left);
|
||||
Check.typeOf.object('right', right);
|
||||
Check.typeOf.object('result', result);
|
||||
}
|
||||
|
||||
const left0 = left[0];
|
||||
const left1 = left[1];
|
||||
const left2 = left[2];
|
||||
@@ -234,12 +218,6 @@ export function multiplyTransformation(left, right, result) {
|
||||
|
||||
/** Transforms a point (w = 1). */
|
||||
export function multiplyByPoint(matrix, cartesian, result) {
|
||||
if (DEBUG) {
|
||||
Check.typeOf.object('matrix', matrix);
|
||||
Check.typeOf.object('cartesian', cartesian);
|
||||
Check.typeOf.object('result', result);
|
||||
}
|
||||
|
||||
const vX = cartesian.x;
|
||||
const vY = cartesian.y;
|
||||
const vZ = cartesian.z;
|
||||
@@ -256,12 +234,6 @@ export function multiplyByPoint(matrix, cartesian, result) {
|
||||
|
||||
/** Transforms a direction (w = 0), ignoring the translation. */
|
||||
export function multiplyByPointAsVector(matrix, cartesian, result) {
|
||||
if (DEBUG) {
|
||||
Check.typeOf.object('matrix', matrix);
|
||||
Check.typeOf.object('cartesian', cartesian);
|
||||
Check.typeOf.object('result', result);
|
||||
}
|
||||
|
||||
const vX = cartesian.x;
|
||||
const vY = cartesian.y;
|
||||
const vZ = cartesian.z;
|
||||
@@ -278,11 +250,6 @@ export function multiplyByPointAsVector(matrix, cartesian, result) {
|
||||
|
||||
/** The translation part as {x, y, z}. */
|
||||
export function getTranslation(matrix, result) {
|
||||
if (DEBUG) {
|
||||
Check.typeOf.object('matrix', matrix);
|
||||
Check.typeOf.object('result', result);
|
||||
}
|
||||
|
||||
result.x = matrix[12];
|
||||
result.y = matrix[13];
|
||||
result.z = matrix[14];
|
||||
@@ -291,11 +258,6 @@ export function getTranslation(matrix, result) {
|
||||
|
||||
/** The upper-left 3x3 part. */
|
||||
export function getMatrix3(matrix, result) {
|
||||
if (DEBUG) {
|
||||
Check.typeOf.object('matrix', matrix);
|
||||
Check.typeOf.object('result', result);
|
||||
}
|
||||
|
||||
result[0] = matrix[0];
|
||||
result[1] = matrix[1];
|
||||
result[2] = matrix[2];
|
||||
@@ -310,13 +272,6 @@ export function getMatrix3(matrix, result) {
|
||||
|
||||
/** The column at `index` (0..3) as {x, y, z, w}. */
|
||||
export function getColumn(matrix, index, result) {
|
||||
if (DEBUG) {
|
||||
Check.typeOf.object('matrix', matrix);
|
||||
Check.typeOf.number.greaterThanOrEquals('index', index, 0);
|
||||
Check.typeOf.number.lessThanOrEquals('index', index, 3);
|
||||
Check.typeOf.object('result', result);
|
||||
}
|
||||
|
||||
const startIndex = index * 4;
|
||||
const x = matrix[startIndex];
|
||||
const y = matrix[startIndex + 1];
|
||||
@@ -332,11 +287,6 @@ export function getColumn(matrix, index, result) {
|
||||
|
||||
/** The inverse of a rotation-plus-translation matrix (no scale or shear). */
|
||||
export function inverseTransformation(matrix, result) {
|
||||
if (DEBUG) {
|
||||
Check.typeOf.object('matrix', matrix);
|
||||
Check.typeOf.object('result', result);
|
||||
}
|
||||
|
||||
// This function is an optimized version of the below 4 lines.
|
||||
// const rT = Matrix3.transpose(Matrix4.getMatrix3(matrix));
|
||||
// const rTN = Matrix3.negate(rT);
|
||||
@@ -382,10 +332,6 @@ export function inverseTransformation(matrix, result) {
|
||||
|
||||
/** A transformation from a 3x3 rotation and a translation (zero when absent). */
|
||||
export function fromRotationTranslation(rotation, translation, result) {
|
||||
if (DEBUG) {
|
||||
Check.typeOf.object('rotation', rotation);
|
||||
}
|
||||
|
||||
translation = translation ?? ZERO;
|
||||
if (result == null) result = create();
|
||||
result[0] = rotation[0];
|
||||
@@ -406,29 +352,3 @@ export function fromRotationTranslation(rotation, translation, result) {
|
||||
result[15] = 1.0;
|
||||
return result;
|
||||
}
|
||||
|
||||
/** A uniform scale. */
|
||||
export function fromUniformScale(scale, result) {
|
||||
if (DEBUG) {
|
||||
Check.typeOf.number('scale', scale);
|
||||
}
|
||||
|
||||
if (result == null) result = create();
|
||||
result[0] = scale;
|
||||
result[1] = 0.0;
|
||||
result[2] = 0.0;
|
||||
result[3] = 0.0;
|
||||
result[4] = 0.0;
|
||||
result[5] = scale;
|
||||
result[6] = 0.0;
|
||||
result[7] = 0.0;
|
||||
result[8] = 0.0;
|
||||
result[9] = 0.0;
|
||||
result[10] = scale;
|
||||
result[11] = 0.0;
|
||||
result[12] = 0.0;
|
||||
result[13] = 0.0;
|
||||
result[14] = 0.0;
|
||||
result[15] = 1.0;
|
||||
return result;
|
||||
}
|
||||
+1
-14
@@ -1,16 +1,12 @@
|
||||
// Ported from CesiumJS 1.138 (Apache-2.0) — Quaternion.js
|
||||
//
|
||||
// Rotations as plain-data {x, y, z, w} objects. Only the subset gev uses is ported.
|
||||
// With DEBUG on (development and tests; see debug.js) invalid arguments throw
|
||||
// the same DeveloperError as Cesium's debug checks.
|
||||
//
|
||||
// Geo values are not Object.prototype objects, so src/app/stateChannel.js
|
||||
// copyState and src/director/documentFields.js jsonTree reject them: copy
|
||||
// the fields into a literal before putting one into product state or a
|
||||
// scene document.
|
||||
|
||||
import { DEBUG } from './debug.js';
|
||||
import { Check } from './check.js';
|
||||
import { normalize, create as createCartesian3 } from './cartesian3.js';
|
||||
|
||||
// Values are instances of a module-private constructor rather than object
|
||||
@@ -32,13 +28,8 @@ export function create(x, y, z, w) {
|
||||
|
||||
let fromAxisAngleScratch = createCartesian3();
|
||||
|
||||
/** The rotation by `angle` radians around `axis` (normalised here; with DEBUG on, a zero axis throws). */
|
||||
/** The rotation by `angle` radians around `axis` (normalised here; a zero axis gives NaN). */
|
||||
export function fromAxisAngle(axis, angle, result) {
|
||||
if (DEBUG) {
|
||||
Check.typeOf.object('axis', axis);
|
||||
Check.typeOf.number('angle', angle);
|
||||
}
|
||||
|
||||
const halfAngle = angle / 2.0;
|
||||
const s = Math.sin(halfAngle);
|
||||
fromAxisAngleScratch = normalize(axis, fromAxisAngleScratch);
|
||||
@@ -63,10 +54,6 @@ const elementIndex = (column, row) => column * 3 + row;
|
||||
|
||||
/** The rotation of a 3x3 rotation matrix. */
|
||||
export function fromRotationMatrix(matrix, result) {
|
||||
if (DEBUG) {
|
||||
Check.typeOf.object('matrix', matrix);
|
||||
}
|
||||
|
||||
let root;
|
||||
let x;
|
||||
let y;
|
||||
|
||||
@@ -1,36 +1,15 @@
|
||||
// Release parity: with DEBUG off, src/geo returns what release Cesium returns.
|
||||
// Release parity: src/geo returns what release Cesium returns.
|
||||
//
|
||||
// Production builds fold geo's DEBUG to false (see debug.js) and ship Cesium's
|
||||
// Build/Cesium, whose debug checks are stripped. So for a degenerate input that
|
||||
// throws in development (a zero vector to normalize, a NaN origin, a divisor
|
||||
// of 0, an index out of range) both must now return the same values, NaN for
|
||||
// NaN and -0 for -0, or fail with the same error. This file loads a copy of
|
||||
// src/geo whose debug.js says `DEBUG = false`, and the stripped Cesium build.
|
||||
import { test, after } from 'node:test';
|
||||
// Production builds ship Cesium's Build/Cesium, whose debug checks are
|
||||
// stripped, and src/geo has no debug checks either. So for a degenerate input
|
||||
// (a zero vector to normalize, a NaN origin, a divisor of 0, an index out of
|
||||
// range) both must return the same values, NaN for NaN and -0 for -0, or fail
|
||||
// with the same error.
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { createRequire } from 'node:module';
|
||||
import {
|
||||
cpSync,
|
||||
mkdtempSync,
|
||||
readdirSync,
|
||||
rmSync,
|
||||
writeFileSync,
|
||||
} from 'node:fs';
|
||||
import { tmpdir } from 'node:os';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath, pathToFileURL } from 'node:url';
|
||||
import * as geo from './index.js';
|
||||
|
||||
const here = path.dirname(fileURLToPath(import.meta.url));
|
||||
const copy = mkdtempSync(path.join(tmpdir(), 'geo-release-'));
|
||||
for (const name of readdirSync(here)) {
|
||||
if (name.endsWith('.js'))
|
||||
cpSync(path.join(here, name), path.join(copy, name));
|
||||
}
|
||||
writeFileSync(path.join(copy, 'debug.js'), 'export const DEBUG = false;\n');
|
||||
after(() => rmSync(copy, { recursive: true, force: true }));
|
||||
|
||||
const geo = await import(pathToFileURL(path.join(copy, 'index.js')).href);
|
||||
const { DEBUG } = await import(pathToFileURL(path.join(copy, 'debug.js')).href);
|
||||
const Cesium = createRequire(import.meta.url)('cesium/Build/Cesium/index.cjs');
|
||||
|
||||
const W = Cesium.Ellipsoid.WGS84;
|
||||
@@ -185,18 +164,6 @@ const CASES = [
|
||||
C3.fromDegreesArray,
|
||||
[list(1, 2, 3)],
|
||||
],
|
||||
[
|
||||
'cartesian3.fromDegreesArrayHeights(4)',
|
||||
geo.cartesian3.fromDegreesArrayHeights,
|
||||
C3.fromDegreesArrayHeights,
|
||||
[list(1, 2, 3, 4)],
|
||||
],
|
||||
[
|
||||
'cartesian3.fromDegreesArrayHeights(str)',
|
||||
geo.cartesian3.fromDegreesArrayHeights,
|
||||
C3.fromDegreesArrayHeights,
|
||||
[list(1, 2, 'h')],
|
||||
],
|
||||
|
||||
[
|
||||
'cartographic.fromRadians(NaN)',
|
||||
@@ -314,12 +281,6 @@ const CASES = [
|
||||
Cesium.Matrix4.multiplyByPoint,
|
||||
[nanMat4, NAN, R],
|
||||
],
|
||||
[
|
||||
'matrix4.fromUniformScale(str)',
|
||||
geo.matrix4.fromUniformScale,
|
||||
Cesium.Matrix4.fromUniformScale,
|
||||
[value('2'), mat4],
|
||||
],
|
||||
|
||||
[
|
||||
'quaternion.fromAxisAngle(zero)',
|
||||
@@ -403,11 +364,6 @@ function outcome(fn, args) {
|
||||
}
|
||||
}
|
||||
|
||||
test('the copy under test has its debug checks off', () => {
|
||||
assert.equal(DEBUG, false);
|
||||
assert.ok(!('normalized result is not a number' in Cesium));
|
||||
});
|
||||
|
||||
for (const [name, geoFn, cesiumFn, builders] of CASES) {
|
||||
test(`release ${name} matches Build/Cesium`, () => {
|
||||
const g = outcome(
|
||||
@@ -432,7 +388,7 @@ for (const [name, geoFn, cesiumFn, builders] of CASES) {
|
||||
});
|
||||
}
|
||||
|
||||
test('release geo returns NaN where development geo throws', () => {
|
||||
test('geo returns NaN for degenerate inputs, as release Cesium does', () => {
|
||||
const r = geo.cartesian3.normalize(
|
||||
geo.cartesian3.create(),
|
||||
geo.cartesian3.create(),
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
// Internal to src/geo (not re-exported by index.js): used by ellipsoid.js and,
|
||||
// as in Cesium, directly by cartographic.fromCartesian.
|
||||
|
||||
import { DEBUG } from './debug.js';
|
||||
import { DeveloperError } from './developerError.js';
|
||||
import { EPSILON12 } from './math.js';
|
||||
import {
|
||||
clone,
|
||||
@@ -28,21 +26,6 @@ export function scaleToGeodeticSurface(
|
||||
centerToleranceSquared,
|
||||
result,
|
||||
) {
|
||||
if (DEBUG) {
|
||||
if (cartesian == null) {
|
||||
throw new DeveloperError('cartesian is required.');
|
||||
}
|
||||
if (oneOverRadii == null) {
|
||||
throw new DeveloperError('oneOverRadii is required.');
|
||||
}
|
||||
if (oneOverRadiiSquared == null) {
|
||||
throw new DeveloperError('oneOverRadiiSquared is required.');
|
||||
}
|
||||
if (centerToleranceSquared == null) {
|
||||
throw new DeveloperError('centerToleranceSquared is required.');
|
||||
}
|
||||
}
|
||||
|
||||
const positionX = cartesian.x;
|
||||
const positionY = cartesian.y;
|
||||
const positionZ = cartesian.z;
|
||||
|
||||
@@ -3,12 +3,7 @@
|
||||
// Local east-north-up frames and heading-pitch-roll orientations as 4x4
|
||||
// column-major matrices (see matrix4.js). Outputs match Cesium bit for bit,
|
||||
// including the degenerate frames at the Earth's centre and at the poles.
|
||||
// With DEBUG on (development and tests; see debug.js) invalid arguments throw
|
||||
// the same DeveloperError as Cesium's debug checks.
|
||||
|
||||
import { DEBUG } from './debug.js';
|
||||
import { Check } from './check.js';
|
||||
import { DeveloperError } from './developerError.js';
|
||||
import {
|
||||
EPSILON14,
|
||||
TWO_PI,
|
||||
@@ -52,15 +47,6 @@ function unpack(array, result) {
|
||||
* `Transforms.localFrameToFixedFrameGenerator('east', 'north')`).
|
||||
*/
|
||||
export function eastNorthUpToFixedFrame(origin, ellipsoid, result) {
|
||||
if (DEBUG) {
|
||||
if (origin == null) {
|
||||
throw new DeveloperError('origin is required.');
|
||||
}
|
||||
if (isNaN(origin.x) || isNaN(origin.y) || isNaN(origin.z)) {
|
||||
throw new DeveloperError('origin has a NaN component');
|
||||
}
|
||||
}
|
||||
|
||||
if (result == null) result = createMatrix4();
|
||||
|
||||
const east = scratchEast;
|
||||
@@ -228,12 +214,6 @@ export function headingPitchRollToFixedFrame(
|
||||
fixedFrameTransform,
|
||||
result,
|
||||
) {
|
||||
// The private helpers below skip Cesium's checks on their internal
|
||||
// arguments (scratch objects and constants), which can never fail.
|
||||
if (DEBUG) {
|
||||
Check.typeOf.object('HeadingPitchRoll', headingPitchRoll);
|
||||
}
|
||||
|
||||
fixedFrameTransform = fixedFrameTransform ?? eastNorthUpToFixedFrame;
|
||||
const hprQuaternion = quaternionFromHeadingPitchRoll(
|
||||
headingPitchRoll,
|
||||
|
||||
@@ -4,63 +4,6 @@ import assert from 'node:assert/strict';
|
||||
import * as Cesium from 'cesium';
|
||||
import * as transforms from './transforms.js';
|
||||
|
||||
const close = (a, b, tol, label) =>
|
||||
assert.ok(Math.abs(a - b) <= tol, `${label}: ${a} vs ${b}`);
|
||||
const ORIGINS = [
|
||||
[-73.9857, 40.7484, 381],
|
||||
[0, 0, 0],
|
||||
[179.9, -45, 10],
|
||||
[10, 89.9999999, 0],
|
||||
[10, -90, 0],
|
||||
[0, 90, 0],
|
||||
];
|
||||
|
||||
test('eastNorthUpToFixedFrame equals Cesium, including the poles', () => {
|
||||
for (const [lon, lat, h] of ORIGINS) {
|
||||
const origin = Cesium.Cartesian3.fromDegrees(lon, lat, h);
|
||||
const ours = transforms.eastNorthUpToFixedFrame({
|
||||
x: origin.x,
|
||||
y: origin.y,
|
||||
z: origin.z,
|
||||
});
|
||||
const theirs = Cesium.Transforms.eastNorthUpToFixedFrame(origin);
|
||||
for (let i = 0; i < 16; i++)
|
||||
close(
|
||||
ours[i],
|
||||
theirs[i],
|
||||
1e-9 * Math.max(1, Math.abs(theirs[i])),
|
||||
`${lon},${lat} [${i}]`,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('headingPitchRollToFixedFrame equals Cesium', () => {
|
||||
for (const [lon, lat, h] of ORIGINS.slice(0, 3)) {
|
||||
const origin = Cesium.Cartesian3.fromDegrees(lon, lat, h);
|
||||
for (const [hd, p, r] of [
|
||||
[0, 0, 0],
|
||||
[0.7, -0.2, 0.1],
|
||||
[-2.5, 1.2, -0.4],
|
||||
]) {
|
||||
const ours = transforms.headingPitchRollToFixedFrame(
|
||||
{ x: origin.x, y: origin.y, z: origin.z },
|
||||
{ heading: hd, pitch: p, roll: r },
|
||||
);
|
||||
const theirs = Cesium.Transforms.headingPitchRollToFixedFrame(
|
||||
origin,
|
||||
new Cesium.HeadingPitchRoll(hd, p, r),
|
||||
);
|
||||
for (let i = 0; i < 16; i++)
|
||||
close(
|
||||
ours[i],
|
||||
theirs[i],
|
||||
1e-9 * Math.max(1, Math.abs(theirs[i])),
|
||||
`hpr [${i}]`,
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test('headingPitchRollToFixedFrame keeps Cesium argument order (result is the fifth argument)', () => {
|
||||
const origin = Cesium.Cartesian3.fromDegrees(-73.9857, 40.7484, 381);
|
||||
const hpr = new Cesium.HeadingPitchRoll(0.7, -0.2, 0.1);
|
||||
|
||||
Reference in new issue
Block a user