mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-20 10:12:18 +00:00
Aircraft icons are one size; helicopters turn a three-frame rotor while airborne or moving; ADS-B ground vehicles share one amber sprite and stations/obstacles one mast; vessels get hull sprites by type and one buoy. Going live keeps contacts until the first live answer and replaces them by id; fast playback holds before the loaded positions end and prefetches ahead. Cesium models move their parts from the optional model part state.
58 lines
1.5 KiB
JavaScript
58 lines
1.5 KiB
JavaScript
// src/data/aircraftIcons.test.mjs
|
|
import { test } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import sharp from 'sharp';
|
|
|
|
import { aircraftIcon, ROTOR_FRAMES } from './aircraftIcons.js';
|
|
|
|
const KINDS = [
|
|
'airliner',
|
|
'widebody',
|
|
'quadjet',
|
|
'turboprop',
|
|
'light',
|
|
'glider',
|
|
'fastjet',
|
|
'bizjet',
|
|
'uav',
|
|
'helicopter',
|
|
'vehicle',
|
|
'station',
|
|
'tr3b',
|
|
'tr3bHot',
|
|
];
|
|
const PX = 480;
|
|
|
|
/** Farthest painted pixel from the centre, in the 96-unit glyph space. */
|
|
async function halfExtent(uri) {
|
|
const svg = Buffer.from(uri.split(',')[1], 'base64');
|
|
const { data, info } = await sharp(svg)
|
|
.ensureAlpha()
|
|
.raw()
|
|
.toBuffer({ resolveWithObject: true });
|
|
let half = 0;
|
|
const c = info.width / 2;
|
|
for (let y = 0; y < info.height; y++) {
|
|
for (let x = 0; x < info.width; x++) {
|
|
if (data[(y * info.width + x) * 4 + 3] <= 8) continue;
|
|
half = Math.max(half, c - x, x + 1 - c, c - y, y + 1 - c);
|
|
}
|
|
}
|
|
return (half * 96) / info.width;
|
|
}
|
|
|
|
test('every sprite fills the same extent, whatever its class', async () => {
|
|
const extents = {};
|
|
for (const kind of KINDS) {
|
|
extents[kind] = await halfExtent(aircraftIcon(kind, PX));
|
|
}
|
|
for (let frame = 0; frame < ROTOR_FRAMES; frame++) {
|
|
extents[`helicopter#${frame}`] = await halfExtent(
|
|
aircraftIcon('helicopter', PX, frame),
|
|
);
|
|
}
|
|
for (const [kind, half] of Object.entries(extents)) {
|
|
assert.ok(Math.abs(half - 44) <= 0.6, `${kind}: ${half.toFixed(2)}`);
|
|
}
|
|
});
|