fix: v0.12.2 — ISS-003 route leg lines now follow the curved great-circle path (greatCircleArc, 25 sampled points via sim slerp) instead of a straight two-point chord; e2e asserts >2 coordinates in the routes source
This commit is contained in:
+37
-5
@@ -1,11 +1,13 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import type { StateSnapshot } from './game/state';
|
||||
import { planesGeoJson, routesGeoJson, type AirportCoord } from './mapData';
|
||||
import { planesGeoJson, routesGeoJson, greatCircleArc, ROUTE_ARC_SEGMENTS, type AirportCoord } from './mapData';
|
||||
import { haversineKm } from './geo';
|
||||
|
||||
const AIRPORTS = new Map<string, AirportCoord>([
|
||||
['EDDF', { lat: 50.03, lon: 8.56 }],
|
||||
['EDDV', { lat: 52.46, lon: 9.68 }],
|
||||
['EHAM', { lat: 52.31, lon: 4.76 }],
|
||||
['LEMD', { lat: 40.47, lon: -3.56 }], // Madrid — ~1400 km from EDDF for the long-route test
|
||||
]);
|
||||
|
||||
function snapshot(overrides: Partial<StateSnapshot> = {}): StateSnapshot {
|
||||
@@ -106,10 +108,10 @@ describe('routesGeoJson (v0.12.0 — one line per flying plane\'s current leg)',
|
||||
);
|
||||
expect(fc.features).toHaveLength(1);
|
||||
expect(fc.features[0].properties).toEqual({ planeId: 'p1' });
|
||||
expect(fc.features[0].geometry.coordinates).toEqual([
|
||||
[8.56, 50.03], // EDDF [lon, lat]
|
||||
[4.76, 52.31], // EHAM
|
||||
]);
|
||||
const coords = fc.features[0].geometry.coordinates;
|
||||
expect(coords.length).toBe(ROUTE_ARC_SEGMENTS + 1); // sampled great-circle arc, not a 2-point chord (v0.12.2)
|
||||
expect(coords[0]).toEqual([8.56, 50.03]); // EDDF [lon, lat] — exact endpoint
|
||||
expect(coords[coords.length - 1]).toEqual([4.76, 52.31]); // EHAM — exact endpoint
|
||||
});
|
||||
|
||||
it('skips a flying plane whose endpoint is missing from the airport dataset', () => {
|
||||
@@ -137,3 +139,33 @@ describe('routesGeoJson (v0.12.0 — one line per flying plane\'s current leg)',
|
||||
expect(fc.features.map((f) => f.properties.planeId).sort()).toEqual(['p1', 'p2']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('greatCircleArc (v0.12.2 — curved route traces)', () => {
|
||||
it('samples >2 points with the endpoints exactly at the airport coords', () => {
|
||||
const arc = greatCircleArc(AIRPORTS.get('EDDF')!, AIRPORTS.get('EHAM')!);
|
||||
expect(arc.length).toBe(ROUTE_ARC_SEGMENTS + 1); // 25 coordinates: 23 intermediate points
|
||||
expect(arc[0]).toEqual([8.56, 50.03]); // EDDF [lon, lat]
|
||||
expect(arc[arc.length - 1]).toEqual([4.76, 52.31]); // EHAM
|
||||
});
|
||||
|
||||
it('midpoint of a long route deviates from the straight chord (it is actually curved)', () => {
|
||||
const from = AIRPORTS.get('EDDF')!;
|
||||
const to = AIRPORTS.get('LEMD')!; // ~1400 km — sagitta ≈ 40 km off the chord
|
||||
const arc = greatCircleArc(from, to);
|
||||
const mid = arc[Math.floor(arc.length / 2)]; // t = 0.5 exactly (index SEGMENTS/2)
|
||||
const chordMid: [number, number] = [(from.lon + to.lon) / 2, (from.lat + to.lat) / 2];
|
||||
expect(haversineKm(mid[1], mid[0], chordMid[1], chordMid[0])).toBeGreaterThan(5); // km off the straight line
|
||||
});
|
||||
|
||||
it('short routes still fine: exact endpoints and a nearly-straight arc', () => {
|
||||
const from = AIRPORTS.get('EDDF')!;
|
||||
const to = AIRPORTS.get('EDDV')!; // ~280 km — sagitta ≈ 1.5 km, visually near-straight
|
||||
const arc = greatCircleArc(from, to);
|
||||
expect(arc.length).toBe(ROUTE_ARC_SEGMENTS + 1);
|
||||
expect(arc[0]).toEqual([from.lon, from.lat]);
|
||||
expect(arc[arc.length - 1]).toEqual([to.lon, to.lat]);
|
||||
const mid = arc[Math.floor(arc.length / 2)];
|
||||
const chordMid: [number, number] = [(from.lon + to.lon) / 2, (from.lat + to.lat) / 2];
|
||||
expect(haversineKm(mid[1], mid[0], chordMid[1], chordMid[0])).toBeLessThan(5); // stays close to the chord
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user