Files
rayd1o 5bfc790dec
ci / backend (push) Has been cancelled
ci / frontend (push) Has been cancelled
release / images (push) Has been cancelled
ci / delivery (push) Has been cancelled
release: bump version to 0.75.0
2026-09-23 21:20:12 +08:00

30 lines
1.4 KiB
JavaScript

import { expect, test } from "bun:test";
import * as THREE from "three";
import { intersectVisibleCables } from "./cable-picking.js";
test("a center-behind cable remains pickable where its geometry is visible", () => {
const earth = new THREE.Group();
const camera = new THREE.PerspectiveCamera();
camera.position.z = 30;
const cable = new THREE.Line();
cable.geometry.boundingSphere = new THREE.Sphere(new THREE.Vector3(0, 0, -2), 14);
cable.updateMatrixWorld();
let candidates;
const front = { object: cable, point: new THREE.Vector3(0, 0, 10) };
const back = { object: cable, point: new THREE.Vector3(0, 0, -10) };
const raycaster = { intersectObjects(objects) { candidates = objects; return [front, back]; } };
expect(intersectVisibleCables(raycaster, [cable], earth, camera, 10)).toEqual([front]);
expect(candidates).toContain(cable);
});
test("entirely rear geometry is excluded before expensive raycasting", () => {
const earth = new THREE.Group();
const camera = new THREE.PerspectiveCamera();
camera.position.z = 30;
const cable = new THREE.Line();
cable.geometry.boundingSphere = new THREE.Sphere(new THREE.Vector3(0, 0, -9), 1);
cable.updateMatrixWorld();
const raycaster = { intersectObjects(objects) { expect(objects).toEqual([]); return []; } };
expect(intersectVisibleCables(raycaster, [cable], earth, camera, 10)).toEqual([]);
});