mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 00:32:21 +00:00
fix(rail): a train snapshot's path.line is a frozen copy of its line, not the layer's own path
The copy keeps the path's fields with its number arrays as frozen arrays, so pointAtS and projectOnPath read it as they read the path and nothing written to it reaches the layer. It is built once per line and shared by every snapshot on that line, so reading it on every frame costs nothing.
This commit is contained in:
1 parent
294ccc0ee8
commit
a17346be6f
2 files changed
+48
-3
No files matched your search
@@ -12,6 +12,7 @@ import {
|
||||
} from '../../testSupport/railLayerHarness.mjs';
|
||||
import { RAIL_SELECTED_OVERLAY_SOURCE_ID } from './policy.js';
|
||||
import { publicRailCatalog } from '../../data/railFeeds.js';
|
||||
import { pointAtS } from '../../data/railPaths.js';
|
||||
|
||||
const M_PER_DEG = 111_320;
|
||||
const LAT = 42.36;
|
||||
@@ -154,6 +155,26 @@ test('a snapshot read again while nothing changed is the one read before', async
|
||||
);
|
||||
});
|
||||
|
||||
test('a snapshot’s line is a frozen copy: writing to it leaves the layer’s line', async (t) => {
|
||||
const app = await onTheLine(t);
|
||||
app.parts().selection.selectTrain(T1);
|
||||
const { line, s } = app.layer.getSelectedTrain().path;
|
||||
const own = app.entry(T1).path.path;
|
||||
assert.notEqual(line, own, 'not the layer’s own');
|
||||
assert.ok(Object.isFrozen(line));
|
||||
for (const name of ['lat', 'lon', 'x', 'y', 's', 'box'])
|
||||
assert.ok(Object.isFrozen(line[name]), name);
|
||||
const lat = own.lat[1];
|
||||
assert.throws(() => {
|
||||
line.lat[1] = 0;
|
||||
}, TypeError);
|
||||
assert.equal(own.lat[1], lat, 'the layer’s line is as it was');
|
||||
assert.deepEqual(pointAtS(line, s), pointAtS(own, s), 'it reads the same');
|
||||
// Copied once per line: T2 runs on the same one.
|
||||
app.parts().selection.selectTrain(T2);
|
||||
assert.equal(app.layer.getSelectedTrain().path.line, line);
|
||||
});
|
||||
|
||||
test('a held train hides its marker and card and keeps the selection', async (t) => {
|
||||
const app = await onTheLine(t);
|
||||
assert.equal(app.layer.setCockpitSubject('rail:mbta-rail:nope'), false);
|
||||
|
||||
Reference in new issue
Block a user