33 lines
1.1 KiB
JavaScript
33 lines
1.1 KiB
JavaScript
import assert from "node:assert/strict";
|
|
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);
|
|
});
|