mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +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
@@ -1,5 +1,5 @@
|
||||
import { twoline2satrec } from 'satellite.js';
|
||||
import { fromDegrees } from '../../geo/ellipsoid.js';
|
||||
import { fromDegrees, fromDegreesInto } from '../../geo/ellipsoid.js';
|
||||
import { noradIdFromSatnum, tleLineLaunchYear } from '../../sources/tle.js';
|
||||
import {
|
||||
DENSE_REFRESH_FRAMES,
|
||||
@@ -9,6 +9,8 @@ import {
|
||||
} from './policy.js';
|
||||
|
||||
export function createCatalog({ state: layerState, services, parts, source }) {
|
||||
// _movePoint copies the position, so one scratch point serves every move.
|
||||
const scratch = { x: 0, y: 0, z: 0 };
|
||||
function _abortActiveUpdates() {
|
||||
for (const controller of layerState._activeUpdateControllers)
|
||||
controller.abort();
|
||||
@@ -44,7 +46,7 @@ export function createCatalog({ state: layerState, services, parts, source }) {
|
||||
if (pos) {
|
||||
parts.rendering._movePoint(
|
||||
noradId,
|
||||
fromDegrees(pos.longitude, pos.latitude, pos.altitude),
|
||||
fromDegreesInto(pos.longitude, pos.latitude, pos.altitude, scratch),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,11 +93,18 @@ test('only the rendering part drives Cesium', () => {
|
||||
/\.scene\b/,
|
||||
/\bscene\./,
|
||||
/\.primitive\b/,
|
||||
// The dots and rings are the rendering part's: ids only elsewhere.
|
||||
/_pointCollection\./,
|
||||
/_points\.(get|values|entries|forEach)\b/,
|
||||
/of (layerState|state)\._points\)/,
|
||||
/_orbitPaths\.(get|values|entries|forEach)\b/,
|
||||
// The dots, rings and tracked entity are the rendering part's. Elsewhere
|
||||
// the handles are only stored, cleared, tested or passed on whole, and
|
||||
// the maps answer by id: no member of a handle is read, with or without
|
||||
// optional chaining, and no handle is taken into a local name.
|
||||
/\b_(pointCollection|trackedEntity)\s*(\?\.|\.|\[)/,
|
||||
/\b_(points|orbitPaths)\s*(\?\.|\.|\[)\s*(?!(has|keys|size|clear|set|delete)\b)/,
|
||||
/of\s+[\w.?]*\b_(points|orbitPaths)\s*\)/,
|
||||
/(\.\.\.|Array\.from\()\s*[\w.?]*\b_(points|orbitPaths)\b(?!\s*\??\.)/,
|
||||
/(^|[;{}(\s])\w+\s*=\s*\(*\s*[\w.?]*\b_(pointCollection|trackedEntity|points|orbitPaths)\s*(;|,|\)|\?\?|\|\||&&)/,
|
||||
/\}\s*=\s*\(*\s*[\w.?]*\b_(pointCollection|trackedEntity|points|orbitPaths)\b/,
|
||||
/[\w)\]]\s*(\?\.)?\[\s*['"`]_(pointCollection|trackedEntity|points|orbitPaths)\b/,
|
||||
/\{[^}]*\b_(pointCollection|trackedEntity|points|orbitPaths)\b[^}]*\}\s*=[^=]/,
|
||||
];
|
||||
for (const name of offList) {
|
||||
const source = readFileSync(
|
||||
@@ -107,6 +114,51 @@ test('only the rendering part drives Cesium', () => {
|
||||
for (const pattern of forbidden)
|
||||
assert.doesNotMatch(source, pattern, `${name}.js: ${pattern}`);
|
||||
}
|
||||
// The patterns themselves still catch what they are for.
|
||||
const caught = [
|
||||
'layerState._trackedEntity.position.setValue(p)',
|
||||
'layerState._pointCollection?.removeAll()',
|
||||
'state._trackedEntity?.["position"]',
|
||||
'layerState._points.get(id).show = false',
|
||||
'layerState._orbitPaths?.values()',
|
||||
'for (const p of layerState._points) {}',
|
||||
'const pc = layerState._pointCollection;',
|
||||
'const { _trackedEntity: e } = layerState;',
|
||||
'const e = layerState?._trackedEntity;',
|
||||
'for (const p of layerState?._points) {}',
|
||||
'[...layerState._points]',
|
||||
'Array.from(layerState._orbitPaths)',
|
||||
'e = layerState._trackedEntity;',
|
||||
'let e; e = layerState._trackedEntity;',
|
||||
'const { position } = layerState._trackedEntity;',
|
||||
'const e = layerState._trackedEntity ?? null;',
|
||||
'const e = (layerState._trackedEntity);',
|
||||
'const { get } = layerState._points;',
|
||||
'layerState["_trackedEntity"].position',
|
||||
];
|
||||
for (const line of caught)
|
||||
assert.ok(
|
||||
forbidden.some((pattern) => pattern.test(line)),
|
||||
`not caught: ${line}`,
|
||||
);
|
||||
const allowed = [
|
||||
'layerState._points.has(id)',
|
||||
'layerState._points.size',
|
||||
'layerState._trackedEntity = null;',
|
||||
'parts.rendering._removeTrackedEntity(layerState._trackedEntity);',
|
||||
'layerState._trackedEntityChangedRemove();',
|
||||
'const had = layerState._points.has(id);',
|
||||
'const t = layerState._trackedEntity\n ? a\n : b;',
|
||||
'const ids = ["_points", "_orbitPaths"];',
|
||||
'const n = layerState._orbitPaths.size;',
|
||||
'[...layerState._points.keys()]',
|
||||
'layerState._trackedEntity = parts.rendering._addTrackedEntity({',
|
||||
];
|
||||
for (const line of allowed)
|
||||
assert.ok(
|
||||
!forbidden.some((pattern) => pattern.test(line)),
|
||||
`wrongly caught: ${line}`,
|
||||
);
|
||||
});
|
||||
|
||||
test('the rendering part draws the dots and rings in Cesium colours', () => {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { cameraOf } from '../../render/rendererOf.js';
|
||||
import { entityFollowTarget, stopFollowing } from '../../data/followed.js';
|
||||
import { satelliteClassLabel } from '../../data/satelliteClass.js';
|
||||
import { fromDegrees } from '../../geo/ellipsoid.js';
|
||||
import { clone, copyInto, scale } from '../../geo/vector.js';
|
||||
import { fromDegreesInto } from '../../geo/ellipsoid.js';
|
||||
import { clone, scale } from '../../geo/vector.js';
|
||||
import { t } from '../../i18n/index.js';
|
||||
import { formatQuantity, unitLabel } from '../../ui/unitLabels.js';
|
||||
import {
|
||||
@@ -155,8 +155,10 @@ export function createTracking({ state: layerState, services, parts, source }) {
|
||||
);
|
||||
if (!pos) return layerState._trackedFrameGeo; // propagation hiccup — keep last good sample
|
||||
layerState._trackedFrameGeo = pos;
|
||||
copyInto(
|
||||
fromDegrees(pos.longitude, pos.latitude, pos.altitude),
|
||||
fromDegreesInto(
|
||||
pos.longitude,
|
||||
pos.latitude,
|
||||
pos.altitude,
|
||||
layerState._trackedFrameCartesian,
|
||||
);
|
||||
layerState._trackedFrameNumber = frameNumber;
|
||||
|
||||
Reference in new issue
Block a user