The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { expect, it } from "vite-plus/test"; |
| 2 | import { Quaternion, Vector3 } from "three"; |
| 3 | import { duoViewSnaps, nearestDuoView } from "./duoSnap.ts"; |
| 4 | |
| 5 | const frames = [ |
| 6 | { |
| 7 | face: "inside" as const, |
| 8 | normal: new Vector3(0, 0, 1), |
| 9 | up: new Vector3(0, 1, 0), |
| 10 | center: new Vector3(), |
| 11 | }, |
| 12 | ]; |
| 13 | const rotation = (x: number, y: number, z = 0) => |
| 14 | new Quaternion().setFromAxisAngle(new Vector3(x, y, z).normalize(), Math.hypot(x, y, z)); |
| 15 | |
| 16 | it("chooses a leaf-focused seated view when it is closer than the middle of the fold", () => { |
| 17 | const leaf = { |
| 18 | face: "right" as const, |
| 19 | normal: new Vector3(0.6, 0, 0.8), |
| 20 | up: new Vector3(0, 1, 0), |
| 21 | center: new Vector3(1, 0, 0), |
| 22 | }; |
| 23 | const candidates = duoViewSnaps([...frames, leaf], 3); |
| 24 | const seat = candidates.find( |
| 25 | (candidate) => candidate.face === "right" && candidate.orientation === "portrait", |
| 26 | )!; |
| 27 | const released = seat.rotation.clone().premultiply(rotation(0.04, 0.05)); |
| 28 | const chosen = nearestDuoView(released, candidates)!; |
| 29 | expect(chosen.face).toBe("right"); |
| 30 | expect(chosen.orientation).toBe("portrait"); |
| 31 | expect(chosen.center.x).toBe(1); |
| 32 | }); |