mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
Every Cesium read that a Navara page made was surveyed with the strict acceptance (GEV_QA_CESIUM_TRAP=record). Math on those paths now uses src/geo: screen annotations, weather and wind center readings, cyclone picks, scene data pack polygons and images (new navaraGeometry.js), the awareness subject, the orbit offset of camera verbs, voice frame_overhead, the agent world packet and Directions colours and ground picks. The celestial ring's Sun and Moon come from a bit-identical port of Cesium's Simon1994 model, JulianDate and TEME rotation (src/geo/simon1994.js, julianDate.js, transforms.js); a Cesium globe still applies its ICRF rotation once loaded. Traffic, Street Level, the Nepal event and locator and geo import build on Cesium's math or entity model on either globe; their enable (or the import) now loads the SDK first through src/app/loadCesium.js, synchronously when it is already there. A production page guards the global so a missed read is reported and starts the load. No module reads Cesium while it loads (scripts/check-cesium-load-time.mjs, run by npm test). Cesium.js is still loaded by index.html here.
82 lines
2.8 KiB
JavaScript
82 lines
2.8 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
import * as geo from '../../geo/index.js';
|
|
import { polygonShape, rectangleShape } from './navaraGeometry.js';
|
|
|
|
const vertex = (shape, index) => {
|
|
const v = shape.attributes.position.values;
|
|
return geo.cartographic.fromCartesian(
|
|
geo.cartesian3.create(v[index * 3], v[index * 3 + 1], v[index * 3 + 2]),
|
|
);
|
|
};
|
|
const area = (shape) => {
|
|
// Sum of triangle areas in square metres.
|
|
const v = shape.attributes.position.values,
|
|
i = shape.indices;
|
|
const p = (k) => geo.cartesian3.create(v[k * 3], v[k * 3 + 1], v[k * 3 + 2]);
|
|
let sum = 0;
|
|
for (let t = 0; t < i.length; t += 3) {
|
|
const a = p(i[t]),
|
|
ab = geo.cartesian3.subtract(p(i[t + 1]), a, geo.cartesian3.create()),
|
|
ac = geo.cartesian3.subtract(p(i[t + 2]), a, geo.cartesian3.create());
|
|
sum +=
|
|
geo.cartesian3.magnitude(
|
|
geo.cartesian3.cross(ab, ac, geo.cartesian3.create()),
|
|
) / 2;
|
|
}
|
|
return sum;
|
|
};
|
|
|
|
test('a pack polygon fills its outline less its holes, each vertex at its own height', () => {
|
|
const square = [
|
|
[-97.75, 30.25, 10],
|
|
[-97.74, 30.25, 10],
|
|
[-97.74, 30.26, 10],
|
|
[-97.75, 30.26, 10],
|
|
[-97.75, 30.25, 10],
|
|
];
|
|
const hole = [
|
|
[-97.747, 30.253, 10],
|
|
[-97.743, 30.253, 10],
|
|
[-97.743, 30.257, 10],
|
|
[-97.747, 30.257, 10],
|
|
];
|
|
const full = polygonShape([square]);
|
|
const holed = polygonShape([square, hole]);
|
|
assert.equal(full.indices.length, 6, 'the closing vertex is not repeated');
|
|
assert.ok(
|
|
Math.abs(area(holed) / area(full) - (1 - 0.16)) < 0.01,
|
|
`the hole is left out: ${area(holed) / area(full)}`,
|
|
);
|
|
for (let k = 0; k < holed.attributes.position.values.length / 3; k++)
|
|
assert.ok(Math.abs(vertex(holed, k).height - 10) < 1e-6);
|
|
assert.equal(polygonShape([[square[0], square[1]]]), null);
|
|
});
|
|
|
|
test('a long pack edge is split so no step spans more than a degree', () => {
|
|
const shape = polygonShape([
|
|
[
|
|
[0, 0],
|
|
[3, 0],
|
|
[3, 1],
|
|
[0, 1],
|
|
],
|
|
]);
|
|
assert.equal(shape.attributes.position.values.length / 3, 8);
|
|
});
|
|
|
|
test('a pack image rectangle maps its texture from the south-west corner', () => {
|
|
const shape = rectangleShape([-97.8, 30.2, -97.7, 30.3], 25);
|
|
const st = shape.attributes.st.values;
|
|
assert.deepEqual([...st.slice(0, 2)], [0, 0]);
|
|
assert.deepEqual([...st.slice(-2)], [1, 1]);
|
|
const first = vertex(shape, 0),
|
|
last = vertex(shape, st.length / 2 - 1);
|
|
assert.ok(Math.abs(geo.math.toDegrees(first.longitude) + 97.8) < 1e-9);
|
|
assert.ok(Math.abs(geo.math.toDegrees(last.latitude) - 30.3) < 1e-9);
|
|
assert.ok(Math.abs(first.height - 25) < 1e-6);
|
|
assert.equal(shape.indices.length, 6);
|
|
const wide = rectangleShape([10, 0, 13.5, 1]);
|
|
assert.equal(wide.indices.length, 4 * 1 * 6, 'cells of at most a degree');
|
|
});
|