Files

45 lines
1.5 KiB
JavaScript

import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";
import test from "node:test";
import {
advanceGhostPins,
destinationPoint,
geodesicDistanceMeters,
} from "../dist/ghostPins.js";
test("destinationPoint advances a pin over the globe", () => {
const origin = { longitude: 37.618423, latitude: 55.751244 };
const destination = destinationPoint(origin, 90, 1_000);
assert.ok(destination.longitude > origin.longitude);
assert.ok(Math.abs(destination.latitude - origin.latitude) < 0.001);
assert.ok(Math.abs(geodesicDistanceMeters(origin, destination) - 1_000) < 0.01);
});
test("advanceGhostPins turns an escaping pin back toward its anchor", () => {
const anchor = { longitude: 37.618423, latitude: 55.751244 };
const edge = destinationPoint(anchor, 90, 990);
const [advanced] = advanceGhostPins([
{
id: "ghost-1",
label: "123456",
...edge,
heading_degrees: 90,
speed_meters_per_second: 20,
},
], anchor, 1_000, 1);
assert.ok(geodesicDistanceMeters(anchor, advanced) < 990);
assert.ok(advanced.heading_degrees > 260 && advanced.heading_degrees < 280);
});
test("ghost pin stems stay terrain-relative after asynchronous tile loading", async () => {
const source = await readFile(
new URL("../src/CesiumMapRenderer.tsx", import.meta.url),
"utf8",
);
assert.match(source, /new runtime\.Cesium\.CallbackPositionProperty/);
assert.match(source, /new runtime\.Cesium\.CallbackProperty/);
assert.match(source, /depthFailMaterial: fillColor/);
});