import * as THREE from 'three'; import { equaln, equalv3 } from '../../src/Geometry/GeUtils'; import { Orbit } from '../../src/Geometry/Orbit'; test("", () => { //构造一个控制类. let orb = new Orbit(); let dir = new THREE.Vector3(0, 1, 0); orb.SetFromDirection(dir); expect(equaln(orb.RoX, 0)).toBe(true); expect(equaln(orb.theta, Math.PI * 0.5)).toBe(true); //试着还原 orb.UpdateDirection(dir); expect(equalv3(dir, new THREE.Vector3(0, 1, 0))).toBe(true); //试试新的 dir.set(1, 0, 0); orb.SetFromDirection(dir); expect(equaln(orb.RoX, 0)).toBe(true); expect(equaln(orb.theta, 0)).toBe(true); //试着还原 orb.UpdateDirection(dir); expect(equalv3(dir, new THREE.Vector3(1, 0, 0))).toBe(true); //试试新的 dir.set(0.5, 0.5, 0).normalize(); let dirc = dir.clone(); orb.SetFromDirection(dir); //试着还原 orb.UpdateDirection(dir); expect(equalv3(dir, dirc)).toBe(true); //试试新的 dir.set(0.5, 0.5, 1).normalize(); dirc = dir.clone(); orb.SetFromDirection(dir); //试着还原 orb.UpdateDirection(dir); expect(equalv3(dir, dirc)).toBe(true); dir.set(0, 0, -1); dirc = dir.clone(); orb.SetFromDirection(dir); expect(equaln(orb.theta, Math.PI * 0.5)).toBe(true); expect(equaln(orb.RoX, Math.PI * -0.5)).toBe(true); //试着还原 orb.UpdateDirection(dir); expect(equalv3(dir, dirc)).toBe(true); let newDir = orb.UpdateDirection(); let up = Orbit.ComputUpDirection(new THREE.Vector3(0, 0, 1)); expect(equalv3(up, new THREE.Vector3(0, 1, 0))).toBe(true); Orbit.ComputUpDirection(new THREE.Vector3(0, 0, -1), up); Orbit.ComputUpDirection(new THREE.Vector3(0, 0, 1), up); Orbit.ComputUpDirection(new THREE.Vector3(1, 0, 0), up); let newD = orb.UpdateDirection(); expect(equalv3(newD, new THREE.Vector3(0, 0, -1))).toBe(true); }); test("测试求向量", () => { let dir = new THREE.Vector3(0, 0, 1); let up = Orbit.ComputUpDirection(dir); expect(up).toMatchSnapshot(); Orbit.ComputUpDirection(dir, up); expect(up).toMatchSnapshot(); dir.z = -1; Orbit.ComputUpDirection(dir, up); expect(up).toMatchSnapshot(); dir.x = 1; Orbit.ComputUpDirection(dir, up); expect(up).toMatchSnapshot(); });