Files

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([]);
});