71 lines
3.4 KiB
JavaScript
71 lines
3.4 KiB
JavaScript
import { expect, test } from "bun:test";
|
|
import * as THREE from "three";
|
|
import { CABLE_CONFIG, CONFIG } from "./constants.js";
|
|
import { cableSurfacePoint, calculateGreatCirclePoints } from "./cable-surface.js";
|
|
import { createLandingPointBatch } from "./cable-batches.js";
|
|
|
|
test("landing anchors and cable endpoints share the exact surface in every view", () => {
|
|
expect(CABLE_CONFIG.line.altitudeOffset).toBe(CABLE_CONFIG.landingPoint.altitudeOffset);
|
|
expect(CABLE_CONFIG.line.renderOrder).toBe(CABLE_CONFIG.landingPoint.renderOrder);
|
|
for (const [lat1, lon1, lat2, lon2] of [[43, 145, 35, 140], [35, 179.9, 36, -179.9], [51, 2, 51.0001, 2.0001]]) {
|
|
const points = calculateGreatCirclePoints(lat1, lon1, lat2, lon2, CONFIG.earthRadius + CABLE_CONFIG.line.altitudeOffset);
|
|
for (const [point, lat, lon] of [[points[0], lat1, lon1], [points.at(-1), lat2, lon2]]) {
|
|
const anchor = cableSurfacePoint(lat, lon);
|
|
expect(point.distanceTo(anchor)).toBeLessThan(1e-6);
|
|
const transform = new THREE.Matrix4().makeRotationY(1.4);
|
|
expect(point.clone().applyMatrix4(transform).distanceTo(anchor.clone().applyMatrix4(transform))).toBeLessThan(1e-6);
|
|
}
|
|
}
|
|
});
|
|
|
|
test("only related landing points get a glow and clearing selection removes it", () => {
|
|
const texture = new THREE.Texture();
|
|
const markers = ["normal", "related", "dimmed"].map(state => {
|
|
const marker = new THREE.Sprite(new THREE.SpriteMaterial({ color: 0xf59e0b }));
|
|
marker.userData.landing_visual_state = state;
|
|
return marker;
|
|
});
|
|
const batch = createLandingPointBatch(markers, texture);
|
|
batch.object.onBeforeRender();
|
|
const emphasis = batch.object.geometry.attributes.emphasis;
|
|
expect(emphasis.getX(0)).toBe(0);
|
|
expect(emphasis.getX(1)).toBeGreaterThan(0.5);
|
|
expect(emphasis.getX(2)).toBe(0);
|
|
markers[1].userData.landing_visual_state = "normal";
|
|
batch.object.onBeforeRender();
|
|
expect(Array.from(emphasis.array)).toEqual([0, 0, 0]);
|
|
markers[1].userData.landing_visual_state = "related";
|
|
markers[1].visible = false;
|
|
batch.object.onBeforeRender();
|
|
expect(emphasis.getX(1)).toBe(0);
|
|
batch.dispose();texture.dispose();markers.forEach(marker=>marker.material.dispose());
|
|
});
|
|
|
|
test("selecting a cable adds halo without whitening or resizing its landing cores", async () => {
|
|
const previousWindow = globalThis.window;
|
|
globalThis.window = { addEventListener() {}, removeEventListener() {} };
|
|
const { landingPoints, applyLandingPointVisualState, resetLandingPointVisualState } = await import("./cables.js");
|
|
const original = landingPoints.slice();
|
|
const marker = new THREE.Sprite(new THREE.SpriteMaterial());
|
|
marker.userData = { cableNames: ["selected-cable"] };
|
|
landingPoints.push(marker);
|
|
try {
|
|
resetLandingPointVisualState();
|
|
const color = marker.material.color.getHex();
|
|
const opacity = marker.material.opacity;
|
|
const size = marker.scale.clone();
|
|
applyLandingPointVisualState("selected-cable");
|
|
expect(marker.userData.landing_visual_state).toBe("related");
|
|
expect(marker.material.color.getHex()).toBe(color);
|
|
expect(marker.material.opacity).toBe(opacity);
|
|
expect(marker.scale.equals(size)).toBe(true);
|
|
resetLandingPointVisualState();
|
|
expect(marker.userData.landing_visual_state).toBe("normal");
|
|
expect(marker.material.color.getHex()).toBe(color);
|
|
} finally {
|
|
globalThis.window = previousWindow;
|
|
landingPoints.splice(0, landingPoints.length, ...original);
|
|
marker.material.dispose();
|
|
}
|
|
});
|